You are missing a
\s+ between a
\w+ and
\d+. Also, the whole part needs to be moved inside the loop.
#! /usr/bin/perl
use warnings;
use strict;
open my $in, '<', '6U9D.pdb' or die $!;
my %amino_acid_conversion = (ALA => 'A', TYR => 'Y', MET => 'M', LEU =
+> 'L',
CYS => 'C', GLY => 'G', ARG => 'R', ASN =
+> 'N',
ASP => 'D', GLN => 'Q', GLU => 'E', HIS =
+> 'H',
TRP => 'W', LYS => 'K', PHE => 'F', PRO =
+> 'P',
SER => 'S', THR => 'T', ILE => 'I', VAL =
+> 'V');
my ($x, $y, $z) = (0, 0, 0);
my $seq;
while (<$in>) {
if (/HEADER\s+(.*)/) {
print ">$1\n";
}
if (/^SEQRES\s+\d+\s+\w+\s+\d+\s+(.*)/) {
$seq .= $1;
}
if (/^ATOM\s+\d+\s+\w+\s+\w+\s+\w+\s+\d+\s+(\S+)\s+(\S+)\s+(\S+)/)
+ {
# ~~~
$x += $1;
$y += $2;
$z += $3;
}
}
$seq =~ s/ //g;
my $k = 0;
for (my $i = 0; $i < length $seq; $i += 3) {
my $triplet = substr $seq, $i, 3;
if (exists $amino_acid_conversion{$triplet}) {
print "$amino_acid_conversion{$triplet}";
} else {
warn "Don't know how to convert '$triplet'.\n";
}
$k++;
}
print "\n";
my $xgk = $x / $k;
my $ygk = $y / $k;
my $zgk = $z / $k;
print "$xgk $ygk $zgk \n";
Note that I also turned strict and warnings on, used the 3-argument version of open without bareword filehandles, and checked its return value.
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]