CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
coding.....

 



iyanu
New User

Mar 22, 2010, 2:31 PM

Post #1 of 2 (1823 views)
coding..... Can't Post

three possible ways of writing (sub translate) in this code below:

sub translate {
my ($mrna) = @_;
my $pro = "";
while ($mrna = s/(...)//) {
$pro = $pro . $codonMap{$1};
}
return $pro;
}


The whole code:


my %codonMap; ## declare a hash table
## transcribe translates DNA strings to RNA
sub transcribe {
my ($dna) = @_;
my $rna = scalar reverse $dna;
$rna = tr/ACGT/UGCA/;
return $rna;
}
## translate translates mRNA strings to proteins
sub translate {
my ($mrna) = @_;
my $pro = "";
while ($mrna = s/(...)//) {
$pro = $pro . $codonMap{$1};
}
return $pro;
}
## construct hash that maps codons to amino acids by reading table
## from DATA at the end of the program, which have the following form:
## Residue Codon1 Codon2 ...
while (my $in=<DATA>) { ## assigns next line of DATA to $in; fails if none
chomp($in); ## remove line feed at end of $in
my @codons = split " ",$in;
my $residue
= shift @codons; ## remove first item from @codons and assign
foreach my $nnn (@codons) {
$codonMap{$nnn} = $residue;
}
}
## now read DNA strands from input <STDIN> and print translations in all six
## possible reading frames
while (my $dna=<STDIN>) {
chomp($dna);
print "DNA: ", $dna, "\n";
my $rna = transcribe($dna);
print "RNA: ", $rna, "\n";
my $protein = translate($rna);
print "RF1: ", $protein, "\n";
$rna = s/.//;
$protein = translate($rna);
print "RF2: ", $protein, "\n";
$rna = s/.//;
$protein = translate($rna);
print "RF3: ", $protein, "\n\n";


7stud
Enthusiast

Mar 22, 2010, 10:44 PM

Post #2 of 2 (1812 views)
Re: [iyanu] coding..... [In reply to] Can't Post

Search google for 'code tags'. Read the first ten results, then come back and post what you've learned.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives