Hello, this is my first time on Perl Monks. I'm a grad student practicing Bioinformatics for my dissertation. I found out about Rosalind beta bioinformatics problems (http://rosalind.info, no affiliation posted for interested people only) and decided to give them a shot. My problem is I am trying to parse a given string $s1, and find substrings designated by specific beginning and ending sequences. My code compiles, runs, returns strings which appear to be correct, but is "wrong" according to the website. If anyone can help, my question is if anyone can see any bugs in the code, and especially if anyone can suggest ways to optimize my code, I would greatly appreciate it. Thanks!
#!/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;
}
}
-
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.