Greetings fellow monks. I have picked up perl for my bioinformatics class and im struggling with an assignment. So the gist is I need to write a program that reads a pdb flat file (https://files.rcsb.org/view/6U9D.pdb) and I want to essentially turn it into a FASTA file as well as calculate the geometric center of the atoms using the xyz coordinates the file provides. Now the first part, I have no trouble with. This is the code I have tried so far:

$k=0; open (IN, '6U9D.pdb.txt'); %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'); while (<IN>) { if ($_=~m/HEADER\s+(.*)/){ print ">$1\n"; } if ($_=~m/^SEQRES\s+\d+\s+\w+\s+\d+\s+(.*)/){ $seq.=$1; $seq=~s/ //g;} } #THIS IS THE PART I CANT SEEM TO FIGURE OUT for ($i=0;$i<=length $seq; $i+=3) { print "$amino_acid_conversion{substr($seq,$i,3)}"; #All seems well wit +h the sequence I get the desired output $k++;} print "\n"; if ($_=~m/^ATOM\s+\d+\s+\w+\s+\w+\s+\w+\d+\s+(\S+)\s+(\S+)\s+(\S+)/){ + #the parentheses are the xyz coordinates respectively $x+=$1; $y+=$2; $z+=$3; } $xgk=($x/$k); $ygk=($y/$k); $zgk=($z/$k); print "$xgk $ygk $zgk \n";

The total outpud I get is the sequence and three zeroes. It seems like its not even reading the coordinates? Not sure there... If any of you can share your wisdom I'd appreciate it! Oh and since this is an assignment please use the commands I have here, since this is what I have been taught so far.


In reply to Issues regarding for loops and recursion by Nickmofoe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.