在过去的几天里,我一直在努力编写一个用于计算蛋白质(ATOM
)和配体(HETATM
)原子之间距离的脚本。我正在尝试修改脚本,以便在处理文件时实际覆盖输入文件而不是在终端中打印结果。我也试图更改它,以便在结果(last column
)中有一个小于5
的数字,将此文件移动到另一个文件夹中。但它似乎有一些错误。
这是我的带有txt扩展名的输入文件的样子:
ATOM 1587 HB2 LEU D 46 9.557 -9.974 3.186 1.00 0.00 H
ATOM 1588 HB3 LEU D 46 9.379 -9.901 4.974 1.00 0.00 H
ATOM 1589 HG LEU D 46 11.509 -11.235 5.187 1.00 0.00 H
ATOM 1590 HD11 LEU D 46 12.947 -11.556 3.278 1.00 0.00 H
ATOM 1591 HD12 LEU D 46 11.424 -12.448 3.045 1.00 0.00 H
ATOM 1592 HD13 LEU D 46 11.698 -10.914 2.183 1.00 0.00 H
ATOM 1593 HD21 LEU D 46 11.528 -8.800 5.301 1.00 0.00 H
ATOM 1594 HD22 LEU D 46 12.997 -9.452 4.535 1.00 0.00 H
ATOM 1595 HD23 LEU D 46 11.722 -8.718 3.534 1.00 0.00 H
HETATM 1597 N1 308 A 1 0.339 6.314 -9.091 1.00 0.00 N
HETATM 1598 C10 308 A 1 -0.195 5.226 -8.241 1.00 0.00 C
HETATM 1599 C7 308 A 1 -0.991 4.254 -9.133 1.00 0.00 C
HETATM 1600 C1 308 A 1 -1.468 3.053 -8.292 1.00 0.00 C
这是我一直在使用的脚本:
#!/usr/local/bin/perl
use strict;
use warnings;
use File::Glob;
mkdir "mp";
my $txt;
for my $txt ( glob '*.txt' )
{
open my $fh, '<', $txt;
my $out_fh;
my (@refer, @points);
my $part = 0;
my $dist;
while (my $line = <$fh>)
{
chomp($line);
if ($line =~ /^HETATM/)
{
$part++;
}
my @array = (substr($line, 30, 8),substr($line,38,8),substr($line,46,8));
# print "@array\n";
if ($part == 0)
{
push @refer, [ @array ];
} elsif ($part)
{
push @points, [ @array ];
}
my $atom;
foreach my $ref(@refer)
{
my ($x1, $y1, $z1) = @{$ref};
foreach my $atom(@points) {
my ($x, $y, $z) = @{$atom};
my $dist = sqrt( ($x-$x1)**2 + ($y-$y1)**2 + ($z-$z1)**2 );
print "Distance for calculation between $ref and $atom is $dist\n";
}
#if ($dist <= 5){
# system ("mv $fh mp");
# }
}
}
}
终端中脚本的输出如下所示:
Distance for calculation between ARRAY(0x1c92208) and ARRAY(0x1d100f8) is 5.90498865367242
Distance for calculation between ARRAY(0x1c92280) and ARRAY(0x1d100f8) is 6.82836832632804
Distance for calculation between ARRAY(0x1c922f8) and ARRAY(0x1d100f8) is 6.77725903297196
Distance for calculation between ARRAY(0x1c92370) and ARRAY(0x1d100f8) is 5.12546485696663
Distance for calculation between ARRAY(0x1c923e8) and ARRAY(0x1d100f8) is 4.53856199693251
所以,总的来说,我试图找到一种方法来匹配那些因为数字<5而将这些文件移动到另一个文件夹中的文件。有人可以帮帮我吗?