如何从pdb文件中取出某些元素

时间:2017-12-09 00:13:55

标签: bash shell perl pdb-files

我试图从pdb文件中取出某些列。我已经在代码中取出了所有以ATOM开头的行。由于某种原因,我的子功能不起作用,我不知道在哪里或如何调用它们。 我的代码是:

open (FILE, $ARGV[0])
    or die "Could not open file\n";

my @newlines;
 while ( my $line = <FILE> ) {
    if ($line =~ m/^ATOM.*/) {
    push @newlines, $line;
    }
}

my $atomcount = @newlines;
#print "@newlines\n";
#print "$atomcount\n";

##############################################################
#This function will take out the element from each line
#The element is from column 77 and contains one or two letters

sub atomfreq {
    foreach my $record1(@newlines) {
      my $element = substr($record1, 76, 2);
      print "$element\n";
      return;
    }
}

################################################################
#This function will take out the residue name from each line
#The element is from column 18 and contains 3 letters

sub resfreq {
    foreach my $record2(@newlines) {
      my $residue = substr($record2, 17, 3);
      print "$residue\n";
      return;
    }
}

2 个答案:

答案 0 :(得分:1)

您可以直接在其他代码下调用它们:

atomfreq();
resfreq();

答案 1 :(得分:1)

正如@Ossip已在this answer中所说,你只需要调用你的函数:

sub atomfreq {
    ...
}

sub resfreq {
    ...
}

atomfreq();
resfreq();

但是我不确定这些功能是否符合您的意图,因为评论意味着他们应该打印每个 $residue和{{1来自$element数组。您已在@newlines循环中放置return语句,该语句将立即从整个函数(及其for循环)返回,因此它将仅打印第一个for }或$residue。因为函数不应该返回任何东西,所以你可以放弃该语句:

$element