Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Urgent help required. Need a code to translate a given nucleotide sequence into proteins using codon table.

by suchetana
on Feb 13, 2013 at 18:28 UTC ( #1018596=perlquestion: print w/ replies, xml ) Need Help??
suchetana has asked for the wisdom of the Perl Monks concerning the following question:

Here's the code that I tried. Please let me know if it is fine or not. Basically I need to find the ORFs in the thread in three reading frames. and then translate. I tried this code:
#!/usr/bin/perl -w $sequence1='file1.txt'; open(SEQUENCE,$sequence1); $seq=<SEQUENCE>; print $seq, "\n"; $RNA=$seq; $RNA=~s/T/U/g; print "\n here is mRNA $RNA \n"; close SEQUENCE; $rna1=$RNA; print "\n Here is the 1st frame $rna1 \n" ; $rna2=substr($RNA,1) ; print " Here is the 2nd frame $rna2 \n"; $rna3=substr($RNA,2) ; print "Here is the 3rd frame $rna3 \n"; $length1= length$rna1; $length2= length$rna2; $length3= length$rna3; print "1st line ORFs\n"; for ($i = 0; $i <= ($length1 - 3); $i = $i + 3) { $codon1 = substr($rna1, $i, 3); print $codon1," "; } print "2nd line ORFs\n"; for ($i = 0; $i <= ($length2 - 3); $i = $i + 3) { $codon2 = substr($rna2, $i, 3); print $codon2," "; } print "\n 3rd line ORFs\n"; for ($i = 0; $i <= ($length3 - 3); $i = $i + 3) { $codon3 = substr($rna3, $i, 3); print $codon3," "; } local $_ = $RNA ; while ( / AUG /g ) { my $start = pos () - 2 ; if ( / UGA|UAA|UAG /g ) { my $stop = pos ; $gene = substr ( $_ , $start - 1 , $stop - $start + 1 ), $/ ; print "$gene" ; } # The next set of commands translates the ORF found above for an amino + acid seq. print "\nThe largest reading Frame is:\t\t\t" . $protein { "gene" } . +"\n" ; sub translate { my ( $gene , $reading_frame ) = @_ ; my %protein = (); for ( $i = $reading_frame ; $i < length ( $gene ); $i += 3 ) { $codon = substr ( $gene , $i , 3 ); $amino_acid = translate_codon( $codon ); $protein { $amino_acid }++; $protein { "gene" } .= $amino_acid ; } return %protein ; } sub translate_codon { if ( $_ [ 0 ] =~ / GC[AGCU] /i ) { return A;} # Alanine; if ( $_ [ 0 ] =~ / UGC|UGU /i ) { return C;} # Cysteine if ( $_ [ 0 ] =~ / GAC|GAU /i ) { return D;} # Aspartic A +cid; if ( $_ [ 0 ] =~ / GAA|GAG /i ) { return Q;} # Glutamine; if ( $_ [ 0 ] =~ / UUC|UUU /i ) { return F;} # Phenylalan +ine; if ( $_ [ 0 ] =~ / GG[AGCU] /i ) { return G;} # Glycine; if ( $_ [ 0 ] =~ / CAC|CAU /i ) { return His;} # Histine +(start codon); if ( $_ [ 0 ] =~ / AU[AUC] /i ) { return I;} # Isoleucine +; if ( $_ [ 0 ] =~ / AAA|AAG /i ) { return K;} # Lysine; if ( $_ [ 0 ] =~ / UUA|UUG|CU[AGCU] /i ) { return Leu;} # Leucine; if ( $_ [ 0 ] =~ / AUG /i ) { return M;} # Methionine +; if ( $_ [ 0 ] =~ / AAC|AAU /i ) { return N;} # Asparagine +; if ( $_ [ 0 ] =~ / CC[AGCU] /i ) { return P;} # Proline; if ( $_ [ 0 ] =~ / CAA|CAG /i ) { return G;} # Glutamine; if ( $_ [ 0 ] =~ / AGA|AGG|CG[AGCU] /i ) { return R;} # Arginine; if ( $_ [ 0 ] =~ / AGC|AGU|UC[AGCU] /i ) { return S;} # Serine; if ( $_ [ 0 ] =~ / AC[AGCU] /i ) { return T;} # Threonine; if ( $_ [ 0 ] =~ / GU[AGCU] /i ) { return V;} # Valine; if ( $_ [ 0 ] =~ / UGG /i ) { return W;} # Tryptophan +; if ( $_ [ 0 ] =~ / UAC|UAU /i ) { return Y;} # Tyrosine; if ( $_ [ 0 ] =~ / UAA|UGA|UAG /i ) { return "***" ;} # Stop +Codons; } } exit;
Please give me a detailed answer. I need the total program URGENTLY. Please Help!!!

Comment on Urgent help required. Need a code to translate a given nucleotide sequence into proteins using codon table.
Download Code
Re: Urgent help required. Need a code to translate a given nucleotide sequence into proteins using codon table.
by roboticus (Canon) on Feb 13, 2013 at 18:59 UTC

    suchetana:

    If it does what you want, then it's fine!

    Since you really didn't tell what's wrong or right, I'll leave it to you to decide how fine it is.

    I suggest urgently fixing your code tags, then urgently describing the symptoms to your urgent problem. Otherwise, many monks will urgently ignore it.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      See what I have is suppose TATGCATGGCATATATATACGTACGTATGCATATATATGCTAA. I want to find the substring that has ATG......TAA while reading from the first T Then I want it to start reading from the second alphabet and find the substring having ATG...TAA and again then the same thing from T to get ATG....TAA. Also, I then need to store these three substrings in three different scalars/arrays. Then I need to translate them, like if the first three are ATG it should return say M, then it reads the next 3 characters of that substring and say it is CAT. Then it will return X say. Likewise. How do I go about? Please please help
Re: Urgent help required. Need a code to translate a given nucleotide sequence into proteins using codon table.
by kennethk (Monsignor) on Feb 13, 2013 at 19:11 UTC
    So a scan your post suggests you would be well served by using strict in your coding -- see Basic debugging checklist and Use strict warnings and diagnostics or die. If I'm reading it correctly, most of your return statements return barewords rather than strings. For example, I expect return K; should actually be return 'K'; -- you don't actually have a subroutine named K, right?

    Of course, all this is guesses because your posted code is mangled because of lack of <code> tags and you don't provide input or expected output. See How do I post a question effectively?


    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re: Urgent help required. Need a code to translate a given nucleotide sequence into proteins using codon table.
by dasgar (Deacon) on Feb 13, 2013 at 19:35 UTC

    To be nice, here's the OP's code in a more readable format (i.e. added in line breaks and is inside proper code tags).

    In the process of reformatting, I suspect that there are some issues with curly brackets. It looks like the while loop's open curly bracket isn't closed off until after the subroutines. I suspect that might be an issue and definitely agree with kennethk's suggestion about using strict and warnings.

      i do have -w given, so it should read the bugs and warn, right?

        warnings and strict cover different issues. Without strict, you get some very regressive behaviors that you almost assuredly don't intend, e.g. my point about barewords. Did you try addressing that issue yet?


        #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      For future reference, perlmonks linkifies anything between [ and ], so locations in the posted code that display as links should actually be array indices or character classes. For example
      if ( $_ 0 =~ / GGAGCU /i ) { return G;} # Glycine;
      is printed above as

      if ( $_ 0 =~ / GGAGCU /i ) { return G;} # Glycine;

      and should therefore actually probably be translated as

      if ( $_[0] =~ /GG[AGCU]/i ) { return G;} # Glycine;
      barring ambiguities with regard to whitespace counts. Not that I've done this before....

      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re: Urgent help required. Need a code to translate a given nucleotide sequence into proteins using codon table.
by thundergnat (Deacon) on Feb 13, 2013 at 19:44 UTC

    Umm. Is this the same urgent problem from Nov 11, 2011 (11/11/11 :-) ) on stackoverflow?

    If it is, why didn't any of those answers help? If not, why would you copy code that is explicitly stated to be broken?

      didn't work that code
        didn't work that code

        Doesn't work this code either.... Not a surprise. It's the SAME code.

Re: Urgent help required. Need a code to translate a given nucleotide sequence into proteins using codon table.
by necroshine (Acolyte) on Feb 14, 2013 at 15:46 UTC
Re: Urgent help required. Need a code to translate a given nucleotide sequence into proteins using codon table.
by runrig (Abbot) on Mar 11, 2013 at 20:50 UTC
    I need the total program URGENTLY.
    I'll get right on it!!! What's your deadline ?!?!?!?
    Please let me know if it is fine or not.
    That code is NOT fine!!! The problems should be fixed (URGENTLY)!!!!

      I'll get right on it!!! What's your deadline ?!?!?!?

      Last month sometime? Like when OP last visited?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1018596]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2014-12-17 20:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (31 votes), past polls