disulfidebond has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w # use Data::Dumper; $s1 = 'AGCCATGTAGCTAACTCAGGTTACATGGGGATGACCCCGCGACTTGGATTAGAGTCTCTTTTG +GAATAAGCCTGAATGATCCGAGTAGCATCTCAG'; print "$s1\n"; # copy string $s1 to array @arr_ @arr_ = split ('', $s1); # must test for initial methionine # assign @arr_ array to string $arr_met to test $arr_met = join('', @arr_); $sub_met = substr($arr_met, 0, 3); if ($sub_met =~ m/ATG/) { # if match is TRUE, call &proteintrans to translate # else do nothing my $peptide = proteintrans($arr_met); print "\n$peptide\n"; } else { print "\nno initial match, moving along...\n"; } # for each iteration of loop # shift $j element off front of array to alter reading frame # assign array @arr_ to string $dna_string for processing # call &testformethionine subroutine print "@arr_\n"; $len = @arr_; for ($j = 0; $j < $len; $j++) { shift @arr_; $dna_string = join('', @arr_); # debugging step # print "\n$dna_string\n"; testformethionine($dna_string); } sub testformethionine { my ($dnastr) = @_; # create substring from first 3 amino acids my $sub1 = substr($dnastr, 0, 3); # print "$sub1\n"; # if matches ATG (Met) proceed through translation &proteintrans # else do nothing if ($sub1 =~ m/ATG/) { my $peptide = proteintrans($dnastr); print "$peptide\n"; } else { # debugging line of code # print "move along, polymerase\n"; } } sub proteintrans { my ($dna) = @_; my $protein = ''; # split amino acids into 3 with for loop and concatenate for(my $i = 0; $i < (length($dna) - 2) ; $i +=3) { $protein .= codons(substr($dna, $i, 3)); } # return $protein; # $len_ = length($protein); if ($protein =~ m/_/) { # if string $protein matches stop codon '_' # find match with index() # form a substring before stop codon with substr() # return new substring protein_ $index = index($protein, '_'); $protein_ = substr($protein, 0, $index); return $protein_; } else { # else return protein unmodified return $protein; } } sub codons { # use hash table to assign codons my($codon) = @_; $codon = uc $codon; my (%genetic_code) = ( 'TCA' => 'S', # Serine 'TCC' => 'S', # Serine 'TCG' => 'S', # Serine 'TCT' => 'S', # Serine 'TTC' => 'F', # Phenylalanine 'TTT' => 'F', # Phenylalanine 'TTA' => 'L', # Leucine 'TTG' => 'L', # Leucine 'TAC' => 'Y', # Tyrosine 'TAT' => 'Y', # Tyrosine 'TAA' => '_', # exit 'TAG' => '_', # exit 'TGC' => 'C', # Cysteine 'TGT' => 'C', # Cysteine 'TGA' => '_', # exit 'TGG' => 'W', # Tryptophan 'CTA' => 'L', # Leucine 'CTC' => 'L', # Leucine 'CTG' => 'L', # Leucine 'CTT' => 'L', # Leucine 'GTT' => 'V', # Valine 'GTC' => 'V', # Valine 'GTA' => 'V', # Valine 'GTG' => 'V', # Valine 'GCT' => 'A', # Alanine 'GCC' => 'A', # Alanine 'GCA' => 'A', # Alanine 'GCG' => 'A', # Alanine 'GAT' => 'D', # Aspartic Acid 'GAC' => 'D', # Aspartic Acid 'GAA' => 'E', # Glutamate 'GAG' => 'E', # Glutamate 'GGT' => 'G', # Glycine 'GGC' => 'G', # Glycine 'GGA' => 'G', # Glycine 'GGG' => 'G', # Glycine 'CCA' => 'P', # Phenylalanine 'CCC' => 'P', # Phenylalanine 'CCG' => 'P', # Phenylalanine 'CCT' => 'P', # Phenylalanine 'CAC' => 'H', # Histidine 'CAT' => 'H', # Histidine 'CAA' => 'Q', # Glutamine 'CAG' => 'Q', # Glutamine 'CGA' => 'R', # Arginine 'CGC' => 'R', # Arginine 'CGG' => 'R', # Arginine 'CGT' => 'R', # Arginine 'ATA' => 'I', # Isoleucine 'ATC' => 'I', # Isoleucine 'ATT' => 'I', # Isoleucine 'ATG' => 'M', # Methionine 'ACA' => 'T', # Threonine 'ACC' => 'T', # Threonine 'ACG' => 'T', # Threonine 'ACT' => 'T', # Threonine 'AAC' => 'N', # Asparagine 'AAT' => 'N', # Asparagine 'AAA' => 'K', # Lysine 'AAG' => 'K', # Lysine 'AGC' => 'S', # Serine 'AGT' => 'S', # Serine 'AGA' => 'R', # Arginine 'AGG' => 'R', # Arginine # hash table and subroutine from "Beginning Perl for Bioinformatics" # by James Tisdall. c2001 O'Reilly Press. ); if(exists $genetic_code{$codon}) { return $genetic_code{$codon}; } else { print STDERR "$codon not found\n"; exit; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need help with code
by grondilu (Friar) on Oct 19, 2012 at 05:03 UTC | |
|
A critique (was Re: Need help with code)
by roboticus (Chancellor) on Oct 19, 2012 at 14:11 UTC | |
by disulfidebond (Novice) on Oct 21, 2012 at 00:31 UTC | |
by roboticus (Chancellor) on Oct 21, 2012 at 06:05 UTC | |
|
Re: Need help with code
by McA (Priest) on Oct 19, 2012 at 08:32 UTC |