KSH HW2 Translation of DNA sequences into Amino acids

From Biolecture.org
Revision as of 19:31, 14 June 2016 by 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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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


 

Reference

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