document.write('<link rel="stylesheet" href="http://gist.github.com/stylesheets/gist/embed.css"/>')





document.write('<div id=\"gist-113587\" class=\"gist\">\n  \n  \n    \n            \n\n      <div class=\"gist-file\">\n        <div class=\"gist-data gist-syntax\">\n          \n          \n          \n            <div class=\"gist-highlight\"><pre><div class=\"line\" id=\"LC1\">sub translate {<\/div><div class=\"line\" id=\"LC2\">&nbsp;<\/div><div class=\"line\" id=\"LC3\">&nbsp;&nbsp;&nbsp;&nbsp;# Translate the input file from dna to protein, replacing the<\/div><div class=\"line\" id=\"LC4\">&nbsp;&nbsp;&nbsp;&nbsp;# original file. Sequences that are already protein remain<\/div><div class=\"line\" id=\"LC5\">&nbsp;&nbsp;&nbsp;&nbsp;# untouched.<\/div><div class=\"line\" id=\"LC6\">&nbsp;<\/div><div class=\"line\" id=\"LC7\">&nbsp;&nbsp;&nbsp;&nbsp;my ( $filename, $fullpath ) = @_;<\/div><div class=\"line\" id=\"LC8\">&nbsp;<\/div><div class=\"line\" id=\"LC9\">&nbsp;&nbsp;&nbsp;&nbsp;# Input sequence stream.<\/div><div class=\"line\" id=\"LC10\">&nbsp;&nbsp;&nbsp;&nbsp;my $seqI = Bio::SeqIO-&gt;new( -file =&gt; $fullpath );<\/div><div class=\"line\" id=\"LC11\">&nbsp;<\/div><div class=\"line\" id=\"LC12\">&nbsp;&nbsp;&nbsp;&nbsp;# Output sequence stream.<\/div><div class=\"line\" id=\"LC13\">&nbsp;&nbsp;&nbsp;&nbsp;my $tempfile = File::Temp-&gt;new( SUFFIX =&gt; \'.fasta\' )-&gt;filename;<\/div><div class=\"line\" id=\"LC14\">&nbsp;&nbsp;&nbsp;&nbsp;my $seqO     = Bio::SeqIO-&gt;new(<\/div><div class=\"line\" id=\"LC15\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-file   =&gt; &quot;&gt;$tempfile&quot;,<\/div><div class=\"line\" id=\"LC16\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-format =&gt; \'fasta\'<\/div><div class=\"line\" id=\"LC17\">&nbsp;&nbsp;&nbsp;&nbsp;);<\/div><div class=\"line\" id=\"LC18\">&nbsp;<\/div><div class=\"line\" id=\"LC19\">&nbsp;&nbsp;&nbsp;&nbsp;# Translate dna sequences and write to temp file.<\/div><div class=\"line\" id=\"LC20\">&nbsp;&nbsp;&nbsp;&nbsp;while ( my $seq = $seqI-&gt;next_seq ) {<\/div><div class=\"line\" id=\"LC21\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( $seq-&gt;alphabet eq \'dna\' ) {<\/div><div class=\"line\" id=\"LC22\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$seq = $seq-&gt;translate;<\/div><div class=\"line\" id=\"LC23\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<\/div><div class=\"line\" id=\"LC24\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$seqO-&gt;write_seq($seq);<\/div><div class=\"line\" id=\"LC25\">&nbsp;&nbsp;&nbsp;&nbsp;}<\/div><div class=\"line\" id=\"LC26\">&nbsp;<\/div><div class=\"line\" id=\"LC27\">&nbsp;&nbsp;&nbsp;&nbsp;$_-&gt;close for ( $seqI, $seqO );<\/div><div class=\"line\" id=\"LC28\">&nbsp;<\/div><div class=\"line\" id=\"LC29\">&nbsp;&nbsp;&nbsp;&nbsp;# Replace the original file with the temporary one with the<\/div><div class=\"line\" id=\"LC30\">&nbsp;&nbsp;&nbsp;&nbsp;# translated sequences.<\/div><div class=\"line\" id=\"LC31\">&nbsp;&nbsp;&nbsp;&nbsp;move( $tempfile, $fullpath );<\/div><div class=\"line\" id=\"LC32\">&nbsp;<\/div><div class=\"line\" id=\"LC33\">}<\/div><\/pre><\/div>\n        \n        <\/div>\n\n        <div class=\"gist-meta\">\n          <a href=\"http://gist.github.com/raw/113587/8fe1943c53972124d331100da0d10ff1ae778210/translate-2.pl\" style=\"float:right;\">view raw<\/a>\n          <a href=\"http://gist.github.com/113587#file_translate_2.pl\" style=\"float:right;margin-right:10px;color:#666\">translate-2.pl<\/a>\n          <a href=\"http://gist.github.com/113587\">This Gist<\/a> brought to you by <a href=\"http://github.com\">GitHub<\/a>.\n        <\/div>\n      <\/div>\n    \n  \n<\/div>\n')
