
iyanu
New User
Mar 22, 2010, 2:31 PM
Post #1 of 2
(2945 views)
|
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";
|