Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Storage of proteins from diferent ORF

by frozenwithjoy (Priest)
on Mar 31, 2014 at 16:35 UTC ( [id://1080426]=note: print w/replies, xml ) Need Help??


in reply to Storage of proteins from diferent ORF

Edit: Looks like kennethk also rewrote your code in almost the same way as I was adding my last part, so it must be the right way to do it! :P

Edit2: kennethk pointed out to me that my code is incrementing by three positions when there is an unknown codon, but yours only increments by one position. Is this by design? It seems to me like you would want to move on to the next codon regardless of there being a match or mismatch.

First, your code would be much more simple if you had your codon table in a hash and just looked up the codon in the hash to get the amino acid. Before you entered the loop, you would define the table:

my %codon_table = ( 'TTT' => 'F', 'TTC' => 'F', 'TTA' => 'L', 'TTG' => 'L', 'CTT' => 'L', 'CTC' => 'L', 'CTA' => 'L', 'CTG' => 'L', # AND SO ON );

Second, I'm not really familiar with this usage:

@marcos=<,$protein>;

I think what you want instead of this line is:

push @marcos, $protein;

Then if you move your last little loop outside of the main loop, I think it should behave the way you expect. Here is a simplified version of that last loop:

print "La secuencia $c es: $_\n\n" for @marcos;

Third, I suspect that you aren't using use strict; use warnings;... Use these!

I've combined all of these suggestions and made a few more changes to rewrite your code as:

my %codon_table = ( 'TTT' => 'F', 'TTC' => 'F', 'TTA' => 'L', 'TTG' => 'L', 'CTT' => 'L', 'CTC' => 'L', 'CTA' => 'L', 'CTG' => 'L', # AND SO ON ); my @marcos; for my $reading_frame ( 0 .. 2 ) { my $position = $reading_frame; while ( $position < length($DNA) - 2 ) { my $codon = substr( $DNA, $position, 3 ); my $amino_acid = $codon_table{$codon}; if ( defined $amino_acid ) { $protein = $protein . $amino_acid; } else { $protein .= "x"; } $position += 3; } push @marcos, $protein; } print "La secuencia $reading_frame es: $_\n\n" for @marcos;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 07:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found