计算pdb文件中单个原子与其他原子之间的距离;打印问题

时间:2013-12-06 19:19:26

标签: perl printing

在这里编码新手。 在Frankensteining我从互联网和一些实验室伙伴发现的一些代码之后,我创建了一个脚本来计算单个原子与所有其他与该行中的模式匹配的原子之间的距离。
请记住,这是一个.pdb文件。 有问题的PDB文件:http://rapidshare.com/share/7B1847A6F8A249B12B32D85653B140C4 我运行代码并没有得到任何错误消息,但我没有输出。在我的打印检查工作中。但是,当距离计算块运行时,没有距离数输出。

#!/use/bin/perl
use warnings;
use strict;

#Usage: ./script.pl input > output

#subroutines for calculations

sub distanceAB
{
    my $distance = 0;

    my $Ax = substr($_[0], 30, 8) + 0;
    my $Ay = substr($_[0], 38, 8) + 0;
    my $Az = substr($_[0], 46, 8) + 0;

   my $Bx = substr($_[1], 30, 8) + 0;
   my $By = substr($_[1], 38, 8) + 0;
   my $Bz = substr($_[1], 46, 8) + 0;

    $distance = sqrt(($Ax - $Bx)**2 + ($Ay - $By)**2 + ($Az - $Bz)**2);
    return sprintf("%4.2f", $distance);
}
#open files for calculations and modify distance cutoff for target residues

my $input = $ARGV[0]; 
my $num = 0;
my $ZNline = '';

open my $PDBFILE, '<', $input or die "can't open .pdb '$input':$!";


while (my $pdbline = <$PDBFILE>) {

if ($pdbline =~ m/^ATOM.*(ZN1  LG1)/)
{
    my $ZNline = $pdbline;
    print "$ZNline \n";
}
#find xyz coordinates for other atoms and store in array
if ( $pdbline =~ m/^ATOM.*(OD2 ASP|NE2 HIS)/)
{
    $Atomline = $pdbline;
    $Atomlinearray[$num] = $Atomline;
    $resname = substr($pdbline, 16, 3);
    $resnamearray[$num] = $resname;
    $resnumber = substr($pdbline, 22, 3);
    $resnumberarray[$num] = $resnumber;
    print "$num \n";
    ++$num;
}
}
close $PDBFILE;

    #calculate Zn to each atom distance
    foreach $i (0 .. $#Atomline) {
    my $Zndistance = distanceAB($ZNline, $Atomlinearray[$i]);
    print "$Zndistance \n";
    print "$resnamearray[$i] $resnumberarray[$i] \n";
    }

1 个答案:

答案 0 :(得分:2)

只需删除my:

即可
my $Zndistance=distanceAB($ZNline, $Atomline);
if ($Zndistance < 2.5) {
# __^
    print "$Zndistance\n";

如果你重新宣布它,它就会被取消。

也改变这些行:

my @pdblines = <PDBFILE>;
while (<PDBFILE>) {

为:

while (my $pdblines = <PDBFILE>) {

if (my $pdbline =~ m/....

if ($pdbline =~ m/....

完成修订:

my $input = $ARGV[0];
my $num = 0;
my $ZNline = '';
open my $PDBFILE, '<', $input or die "can't open .file '$input':$!";
while (my $pdbline = <$PDBFILE>) {
    if ($pdbline =~ m/^ATOM.*(ZN1  LG1)/) {
        $ZNline = $pdbline;
    } 
    #find xyz coordinates for other atoms and store in array
    elsif ($pdbline =~ m/^ATOM.*(OD2 ASP|NE2 HIS)/) {
        my $Atomline = $pdbline;
        my $resname = substr($pdbline, 16, 3);
        my $resnumber = substr($pdbline, 22, 3);
        #calculate Zn to each atom distance
        my $Zndistance = distanceAB($ZNline, $Atomline);
        if ($Zndistance < 2.5) {
            print "$Zndistance\n";
            print "$resname $resnumber \n";
            print "Coordinator $num \n";
        }
    }
    ++$num;
}