Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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).

#!/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 amin +o 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 =~ / GCAGCU /i ) { return A;} # Alanine; if ( $_ 0 =~ / UGC|UGU /i ) { return C;} # Cysteine if ( $_ 0 =~ / GAC|GAU /i ) { return D;} # Aspartic Acid; if ( $_ 0 =~ / GAA|GAG /i ) { return Q;} # Glutamine; if ( $_ 0 =~ / UUC|UUU /i ) { return F;} # Phenylalanine; if ( $_ 0 =~ / GGAGCU /i ) { return G;} # Glycine; if ( $_ 0 =~ / CAC|CAU /i ) { return His;} # Histine (start codon); + if ( $_ 0 =~ / AUAUC /i ) { return I;} # Isoleucine; if ( $_ 0 =~ / AAA|AAG /i ) { return K;} # Lysine; if ( $_ 0 =~ / UUA|UUG|CUAGCU /i ) { return Leu;} # Leucine; if ( $_ 0 =~ / AUG /i ) { return M;} # Methionine; if ( $_ 0 =~ / AAC|AAU /i ) { return N;} # Asparagine; if ( $_ 0 =~ / CCAGCU /i ) { return P;} # Proline; if ( $_ 0 =~ / CAA|CAG /i ) { return G;} # Glutamine; if ( $_ 0 =~ / AGA|AGG|CGAGCU /i ) { return R;} # Arginine; if ( $_ 0 =~ / AGC|AGU|UCAGCU /i ) { return S;} # Serine; if ( $_ 0 =~ / ACAGCU /i ) { return T;} # Threonine; if ( $_ 0 =~ / GUAGCU /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;

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.


In reply to Re: Urgent help required. Need a code to translate a given nucleotide sequence into proteins using codon table. by dasgar
in thread Urgent help required. Need a code to translate a given nucleotide sequence into proteins using codon table. by suchetana

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



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-24 04:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found