Difference between revisions of "KSH HW2 Translation of DNA sequences into Amino acids"

From Biolecture.org
imported>Seung-hoon Kim
(Created page with "<p>I tried to make a code to translate DNA sequences into amino acids using Perl program.</p> <h3>Foreach loop<sup>1)</sup></h3> <p>First, I learned about Perl foreac...")
 
imported>Seung-hoon Kim
 
Line 7: Line 7:
 
<p>Perl foreach loop iterates over a list value and sets the control variable to be each element of the list in turn</p>
 
<p>Perl foreach loop iterates over a list value and sets the control variable to be each element of the list in turn</p>
  
<p><font color="#000000">The basic form is like this</font></p>
+
<p>The basic form is like this</p>
  
<p><font color="#000000">foreach</font>&nbsp;var (list) {</p>
+
<p>foreach&nbsp;var (list) {</p>
  
 
<p>&nbsp;</p>
 
<p>&nbsp;</p>
Line 39: Line 39:
 
<h3>Perl Script to convert DNA to Protein</h3>
 
<h3>Perl Script to convert DNA to Protein</h3>
  
<p><br />
+
<p>To make a new object and save to a file, write down</p>
 +
 
 +
<p>1. use Bio::Seq;</p>
 +
 
 +
<p>&nbsp;&nbsp; use Bio::SeqIO;</p>
 +
 
 +
<p>When&nbsp;we make a new object,&nbsp;we always&nbsp;have to use this method (method is a function)</p>
 +
 
 +
<p>2. new()</p>
 +
 
 +
<p>3. -&gt; : Method call sign</p>
 +
 
 +
<p>We have to use these arguments to read codon and&nbsp;save it (Argument is a variable to use function or command)</p>
 +
 
 +
<p>4. -seq, -alphabet, -file, -format</p>
 +
 
 +
<p>5. =&gt; : To assign argument value<br />
 
&nbsp;</p>
 
&nbsp;</p>
  
<h3><font color="#000000">Reference</font></h3>
+
<p>6. -alphabet argument has one value among dna, rna, and protein.</p>
 +
 
 +
<p>&nbsp;&nbsp;&nbsp;-format argument has &#39;fasta&#39; or &#39;genbank&#39; value</p>
 +
 
 +
<p>7. Translation method:</p>
 +
 
 +
<p>&nbsp;&nbsp;&nbsp;$argument name = $object name-&gt;translate;</p>
 +
 
 +
<p>8. Print method:</p>
 +
 
 +
<p>&nbsp;&nbsp; Print $argument name -&gt;seq, &quot;\n&quot;;</p>
 +
 
 +
<p>Example<sup>2)</sup></p>
 +
 
 +
<p>use Bio::Seq;</p>
 +
 
 +
<p>use Bio::SeqIO;</p>
 +
 
 +
<p>@bases = (&quot;a&quot;,&quot;t&quot;,&quot;g&quot;,&quot;c&quot;);</p>
 +
 
 +
<p>&nbsp;&nbsp; foreach $first(@bases){</p>
 +
 
 +
<p>&nbsp;&nbsp;&nbsp;&nbsp; foreach $second(@bases){</p>
 +
 
 +
<p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach $third(@bases){</p>
 +
 
 +
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $codon = $first.$second.$third;</p>
 +
 
 +
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $seq_codon = Bio::Seq -&gt; new(-seq =&gt; $codon, -alphabet =&gt; &#39;dna&#39;);</p>
 +
 
 +
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $aa_letter = $seq_codon -&gt; translate;</p>
 +
 
 +
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;$codon \t&quot;, $aa_letter-&gt;seq, &quot;\t&quot;;</p>
 +
 
 +
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
 +
 
 +
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;\n&quot;;</p>
 +
 
 +
<p>&nbsp;&nbsp; }</p>
 +
 
 +
<p>}</p>
 +
 
 +
<p>$seqio_aa = Bio::SeqIO-&gt;new(-file =&gt; &#39;aa.fas&#39;, -format =&gt; &#39;fasta&#39;);</p>
 +
 
 +
<p>$seqio_aa = write_seq($aa_letter);</p>
 +
 
 +
<p>exit;</p>
 +
 
 +
<h3>Reference</h3>
 +
 
 +
<p>1) <a href="http://www.tutorialspoint.com/perl/perl_foreach_loop.htm">http://www.tutorialspoint.com/perl/perl_foreach_loop.htm</a></p>
  
<p><font color="#000000">1) </font><a href="http://www.tutorialspoint.com/perl/perl_foreach_loop.htm">http://www.tutorialspoint.com/perl/perl_foreach_loop.htm</a></p>
+
<p>2) This code&nbsp;was originally written by Myeong Seo Yoon and I made a little modification</p>
  
 
<p>&nbsp;</p>
 
<p>&nbsp;</p>

Latest revision as of 12:13, 18 June 2016

I tried to make a code to translate DNA sequences into amino acids using Perl program.

Foreach loop1)

First, I learned about Perl foreach loop.

Perl foreach loop iterates over a list value and sets the control variable to be each element of the list in turn

The basic form is like this

foreach var (list) {

 

}

Example

<span style="color:rgb(136,0,0)">#!/usr/local/bin/perl</span>
 
<span style="color:rgb(0,102,102)">@list</span> <span style="color:rgb(102,102,0)">=</span> <span style="color:rgb(102,102,0)">(</span><span style="color:rgb(0,102,102)">2</span><span style="color:rgb(102,102,0)">,</span> <span style="color:rgb(0,102,102)">20</span><span style="color:rgb(102,102,0)">,</span> <span style="color:rgb(0,102,102)">30</span><span style="color:rgb(102,102,0)">,</span> <span style="color:rgb(0,102,102)">40</span><span style="color:rgb(102,102,0)">,</span> <span style="color:rgb(0,102,102)">50</span><span style="color:rgb(102,102,0)">);</span>

<span style="color:rgb(136,0,0)"># foreach loop execution</span>
<span style="color:rgb(0,0,136)">foreach</span> $a <span style="color:rgb(102,102,0)">(</span><span style="color:rgb(0,102,102)">@list</span><span style="color:rgb(102,102,0)">){</span>
    <span style="color:rgb(0,0,136)">print</span> <span style="color:rgb(0,136,0)">"value of a: $a\n"</span><span style="color:rgb(102,102,0)">;</span>
<span style="color:rgb(102,102,0)">}</span>

The result is

value of a: 2
value of a: 20
value of a: 30
value of a: 40
value of a: 50

Perl Script to convert DNA to Protein

To make a new object and save to a file, write down

1. use Bio::Seq;

   use Bio::SeqIO;

When we make a new object, we always have to use this method (method is a function)

2. new()

3. -> : Method call sign

We have to use these arguments to read codon and save it (Argument is a variable to use function or command)

4. -seq, -alphabet, -file, -format

5. => : To assign argument value
 

6. -alphabet argument has one value among dna, rna, and protein.

   -format argument has 'fasta' or 'genbank' value

7. Translation method:

   $argument name = $object name->translate;

8. Print method:

   Print $argument name ->seq, "\n";

Example2)

use Bio::Seq;

use Bio::SeqIO;

@bases = ("a","t","g","c");

   foreach $first(@bases){

     foreach $second(@bases){

          foreach $third(@bases){

               $codon = $first.$second.$third;

               $seq_codon = Bio::Seq -> new(-seq => $codon, -alphabet => 'dna');

               $aa_letter = $seq_codon -> translate;

               print "$codon \t", $aa_letter->seq, "\t";

         }

       print "\n";

   }

}

$seqio_aa = Bio::SeqIO->new(-file => 'aa.fas', -format => 'fasta');

$seqio_aa = write_seq($aa_letter);

exit;

Reference

1) http://www.tutorialspoint.com/perl/perl_foreach_loop.htm

2) This code was originally written by Myeong Seo Yoon and I made a little modification