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]
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.