[2016/12/15]perl程序勘误

来源:互联网 发布:js判断是不是在数组中 编辑:程序博客网 时间:2024/06/08 18:19

今天要用到处理结果了,发现有些aa之间的距离莫名大。。于是检查了一下脚本,错得太离谱了。。难怪昨天用这个数据写程序,代码没错,但跑起来不断提醒segmentation fault。
程序就那么几行代码不是我写的,但是错误的地方都在那里orz
首先!!chain写成chian是什么鬼啊!!完全没看出来。。由于perl语言的特性,不用声明变量所以就没报错,只是把数据当0处理了。其次,字符串比较不应该直接“==”,应该用eq。由于某人写bash写惯了,于是把bash脚本的语言习惯带到这里了。我。。。
下面放正确代码

$bigfile = "1.文件名:4zqk.pdb链.B链;氨基酸序号:75,132,66,78,68,76,136,77,128,126,134链.A链;氨基酸序号:19,26,66,121,122,123,124,125,54,115,1132.文件名:5b8c_ABC.pdb链.C链;氨基酸序号: 63,128,61,131,86,75,78,87,77,85,76,66,68,64链.B链;氨基酸序号:30,33,35,54,59,99,101,102,103,105链.A链; 氨基酸序号:34,53,57,60,96,543.文件名:5ggr_ABY.pdb链.Y链; 氨基酸序号:27,28,29,30,31,60,61,128,129,130,131,132,1334.文件名:5ggt_AHL.pdb链.A链; 氨基酸序号:49,56,69,49,54,115,68,58,54链.H链; 氨基酸序号:105,59,106,32,52,55,108,94,575.文件名:5grj_HLA.pdb链.A 链; 氨基酸序号:66,58,113,56,117,61,60,115,76,61链.H 链;氨基酸序号:31,52,54,55,105,106,57,1016.文件名:5ius_AC.pdb链.A链; 氨基酸序号:68,70,78,134,136,126,128,132,70链.C链; 氨基酸序号:122,125,124,113,123,115,547.文件名:5JXE_BCD.pdb链.B链;氨基酸序号:87,128,76,78,85,648.文件名:mmd(gromacs).pdb 链.B链; 氨基酸序号:135,136,78,126,134链.A链; 氨基酸序号:58,60,113,122,123,125,1159.文件名:aftermpd1mpdl1.pdb链.B链;氨基酸序号:78,75,133,132,131,76,77,126,134链.A链;氨基酸序号:19,26,58,61,66,73,121,124,125,115,58,6110.文件名:aftermutantmd.pdb链.A链; 氨基酸序号:46,48,55,56,58,65,112,115,116,114链.B链;氨基酸序号:121,122,123,125,124,19,120,66,61,113,115,1811.文件名:mPD1hPDL1after.pdb链.B链:氨基酸序号:78,75,133,132,136,68,76,74,128,126,134链.A链; 氨基酸序号:18,26,56,61,66,113,121,123,124,125,54,115";@bigfile_seg = split(/\n/,$bigfile);$temp = 0;open (OUTFILE,">>./outfile");while($temp <= $#bigfile_seg){    if($bigfile_seg[$temp] =~ m/^[0-9]+[.]/){    ##从开头开始,匹配此格式:(一次或多次)数字 + .        #print "$bigfile_seg[$temp]\n";        $temp++;        $file_pos = index($bigfile_seg[$temp],":");        $file = substr($bigfile_seg[$temp], $file_pos+2);        $file =~ s/^\s+//;        $file =~ s/\\s//g;        $file =~ s/[^\040-\176]//g;        #printf "$file\n";        $temp++;        while(index($bigfile_seg[$temp],"链") != -1){            $chain = $bigfile_seg[$temp];            @str = split(/[.]/,$bigfile_seg[$temp]);            $chain = $str[1];            @str = split(/[链]/,$chain);            $chain = $str[0];            @haha = split(/氨基酸序号:/, $bigfile_seg[$temp]);            $haha[1] =~ s/^\s+//;            $haha[1] =~ s/\\s//g;            @string = split ',', $haha[1];            my %hash;#去重            @string = grep { ++$hash{$_} < 2 } @string;            print OUTFILE "chain $chain file $file amount:$#string\n";            for ($i = 0; $i <= $#string; $i++) {                $res1 = $string[$i];                for($j = $i+1; $j <= $#string; $j++)                {                    $res2 = $string[$j];                    open(F,$file);                    while(<F>){                        @at = split(/ +/g,$_); # $at[6,7,8] position; $at[5]: res; $at[4]: chain; $at[2]: CA; $at[3]: residue                         if($at[0] eq "ATOM" && $at[2] eq "CA" && $at[4] eq $chain && $at[5] eq $res1){                            if($file eq "5ggt_AHL.pdb"){                                print "$file $at[4] $at[5]\n";                            }                            $x1 = $at[6];                            $y1 = $at[7];                            $z1 = $at[8];                             $residue1 = $at[3];                            }                        if($at[0] eq "ATOM" && $at[2] eq "CA" && $at[4] eq $chain && $at[5] eq $res2){                            if($file eq "5ggt_AHL.pdb"){                                print "$file $at[4] $at[5]\n";                            }                            $x2=$at[6];                            $y2=$at[7];                            $z2=$at[8];                             $residue2=$at[3];                        }                    }                    close F;                    $z=sqrt( ($x1-$x2)**2 + ($y1-$y2)**2 + ($z1-$z2)**2 );                    print OUTFILE ":$residue1$res1 and $residue2$res2 is $z\n";                    #print ;                }            }            $temp++;        }    }}close(OUTFILE);=chm$file="4zqk.pdb";$chain="B";@string=(78,75,132,66,78,68,76,136,77,128,126,134);print "len : $#string";=cut
0 0
原创粉丝点击