Difference between revisions of "PERL"

From Biolecture.org
imported>Byeongeun Lee
(Created page with "<p><span style="font-size:20px">Basic of Perl</span></p> <hr /> <p><span style="font-size:14px">1) <strong>Variable</strong></span></p> <p>Variable is a place to store a value,...")
 
imported>Byeongeun Lee
Line 45: Line 45:
  
 
<hr />
 
<hr />
 +
<p><strong>Translate combinations of triple bases into amino acids</strong></p>
 +
 
<p>&nbsp;</p>
 
<p>&nbsp;</p>
 +
 +
<pre>
 +
<strong>$text = &quot;aaatgaccgatcagctacgatcagctataaaaaccccggagctacgatcatcg&quot;;</strong>
 +
 +
%convertor = (
 +
    &#39;TCA&#39; =&gt; &#39;S&#39;,    # Serine
 +
    &#39;TCC&#39; =&gt; &#39;S&#39;,    # Serine
 +
    &#39;TCG&#39; =&gt; &#39;S&#39;,    # Serine
 +
    &#39;TCT&#39; =&gt; &#39;S&#39;,    # Serine
 +
    &#39;TTC&#39; =&gt; &#39;F&#39;,    # Phenylalanine
 +
    &#39;TTT&#39; =&gt; &#39;F&#39;,    # Phenylalanine
 +
    &#39;TTA&#39; =&gt; &#39;L&#39;,    # Leucine
 +
    &#39;TTG&#39; =&gt; &#39;L&#39;,    # Leucine
 +
    &#39;TAC&#39; =&gt; &#39;Y&#39;,    # Tyrosine
 +
    &#39;TAT&#39; =&gt; &#39;Y&#39;,    # Tyrosine
 +
    &#39;TAA&#39; =&gt; &#39;_&#39;,    # Stop
 +
    &#39;TAG&#39; =&gt; &#39;_&#39;,    # Stop
 +
    &#39;TGC&#39; =&gt; &#39;C&#39;,    # Cysteine
 +
    &#39;TGT&#39; =&gt; &#39;C&#39;,    # Cysteine
 +
    &#39;TGA&#39; =&gt; &#39;_&#39;,    # Stop
 +
    &#39;TGG&#39; =&gt; &#39;W&#39;,    # Tryptophan
 +
    &#39;CTA&#39; =&gt; &#39;L&#39;,    # Leucine
 +
    &#39;CTC&#39; =&gt; &#39;L&#39;,    # Leucine
 +
    &#39;CTG&#39; =&gt; &#39;L&#39;,    # Leucine
 +
    &#39;CTT&#39; =&gt; &#39;L&#39;,    # Leucine
 +
    &#39;CCA&#39; =&gt; &#39;P&#39;,    # Proline
 +
    &#39;CCC&#39; =&gt; &#39;P&#39;,    # Proline
 +
    &#39;CCG&#39; =&gt; &#39;P&#39;,    # Proline
 +
    &#39;CCT&#39; =&gt; &#39;P&#39;,    # Proline
 +
    &#39;CAC&#39; =&gt; &#39;H&#39;,    # Histidine
 +
    &#39;CAT&#39; =&gt; &#39;H&#39;,    # Histidine
 +
    &#39;CAA&#39; =&gt; &#39;Q&#39;,    # Glutamine
 +
    &#39;CAG&#39; =&gt; &#39;Q&#39;,    # Glutamine
 +
    &#39;CGA&#39; =&gt; &#39;R&#39;,    # Arginine
 +
    &#39;CGC&#39; =&gt; &#39;R&#39;,    # Arginine
 +
    &#39;CGG&#39; =&gt; &#39;R&#39;,    # Arginine
 +
    &#39;CGT&#39; =&gt; &#39;R&#39;,    # Arginine
 +
    &#39;ATA&#39; =&gt; &#39;I&#39;,    # Isoleucine
 +
    &#39;ATC&#39; =&gt; &#39;I&#39;,    # Isoleucine
 +
    &#39;ATT&#39; =&gt; &#39;I&#39;,    # Isoleucine
 +
    &#39;ATG&#39; =&gt; &#39;M&#39;,    # Methionine
 +
    &#39;ACA&#39; =&gt; &#39;T&#39;,    # Threonine
 +
    &#39;ACC&#39; =&gt; &#39;T&#39;,    # Threonine
 +
    &#39;ACG&#39; =&gt; &#39;T&#39;,    # Threonine
 +
    &#39;ACT&#39; =&gt; &#39;T&#39;,    # Threonine
 +
    &#39;AAC&#39; =&gt; &#39;N&#39;,    # Asparagine
 +
    &#39;AAT&#39; =&gt; &#39;N&#39;,    # Asparagine
 +
    &#39;AAA&#39; =&gt; &#39;K&#39;,    # Lysine
 +
    &#39;AAG&#39; =&gt; &#39;K&#39;,    # Lysine
 +
    &#39;AGC&#39; =&gt; &#39;S&#39;,    # Serine
 +
    &#39;AGT&#39; =&gt; &#39;S&#39;,    # Serine
 +
    &#39;AGA&#39; =&gt; &#39;R&#39;,    # Arginine
 +
    &#39;AGG&#39; =&gt; &#39;R&#39;,    # Arginine
 +
    &#39;GTA&#39; =&gt; &#39;V&#39;,    # Valine
 +
    &#39;GTC&#39; =&gt; &#39;V&#39;,    # Valine
 +
    &#39;GTG&#39; =&gt; &#39;V&#39;,    # Valine
 +
    &#39;GTT&#39; =&gt; &#39;V&#39;,    # Valine
 +
    &#39;GCA&#39; =&gt; &#39;A&#39;,    # Alanine
 +
    &#39;GCC&#39; =&gt; &#39;A&#39;,    # Alanine
 +
    &#39;GCG&#39; =&gt; &#39;A&#39;,    # Alanine
 +
    &#39;GCT&#39; =&gt; &#39;A&#39;,    # Alanine
 +
    &#39;GAC&#39; =&gt; &#39;D&#39;,    # Aspartic Acid
 +
    &#39;GAT&#39; =&gt; &#39;D&#39;,    # Aspartic Acid
 +
    &#39;GAA&#39; =&gt; &#39;E&#39;,    # Glutamic Acid
 +
    &#39;GAG&#39; =&gt; &#39;E&#39;,    # Glutamic Acid
 +
    &#39;GGA&#39; =&gt; &#39;G&#39;,    # Glycine
 +
    &#39;GGC&#39; =&gt; &#39;G&#39;,    # Glycine
 +
    &#39;GGG&#39; =&gt; &#39;G&#39;,    # Glycine
 +
    &#39;GGT&#39; =&gt; &#39;G&#39;,    # Glycine
 +
    );
 +
 +
 +
for ($s=0; $s&lt;3; $s++) {
 +
        $scrap = substr($text,0,$s);
 +
        $main = substr($text,$s);
 +
        $main =~ s/(...)/&quot;$convertor{uc $1}&quot; || &quot;?&quot;/eg;
 +
        print &quot;$scrap$main\n&quot;;
 +
        }
 +
 +
</pre>
 +
 +
<p>&nbsp;</p>
 +
 +
<pre>
 +
%convertor = ( ~~~ );
 +
 +
= used for giving information for translation (codon into amino acids)
 +
 +
for ($s=0; $s&lt;3; $s++)</pre>
 +
 +
<p>=&nbsp;</p>

Revision as of 18:07, 17 June 2016

Basic of Perl


1) Variable

Variable is a place to store a value, so we can refer to it or manipulate it throughout program. Perl has three types of variables; scalars, arrays and hases.

Scalar ($) 

Scalar variable stores a single (scalar) value. Perl scalar names are prefixed with a dollar sign ($), so for example, $x, $y, $z, $username, and $url are all examples of scalar variable names. A scalar can hold data of any type, be it a string, a number, or whatnot.

ex) 

$name = "Byeongeun Lee";

Array (@)

An array stores a list of values. While a scalar variable can only store one value, an array can store many. Perl array names are prefixed with an at-sign (@). In Perl, array indices start with 0, so to refer to the first element of the array @colors, you use $colors[0]. Note that when you're referring to a single element of an array, you prefix the name with a $ instead of the @. The $-sign again indicates that it's a single (scalar) value; the @-sign means you're talking about the entire array.

ex)

@Grades = ("A","B","C");

 

Hash (%)

A hash is a special kind of array - an associative array, or paired group of elements. Perl hash names are prefixed with a percent sign (%), and consist of pairs of elements - a key and a data value.

ex)

my %courses = (
    "Cell bio" => "prof.P",
    "Micro" => "prof.M",
);

 

Assignment study


Translate combinations of triple bases into amino acids

 

<strong>$text = "aaatgaccgatcagctacgatcagctataaaaaccccggagctacgatcatcg";</strong>

%convertor = (
    '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' => '_',    # Stop
    'TAG' => '_',    # Stop
    'TGC' => 'C',    # Cysteine
    'TGT' => 'C',    # Cysteine
    'TGA' => '_',    # Stop
    'TGG' => 'W',    # Tryptophan
    'CTA' => 'L',    # Leucine
    'CTC' => 'L',    # Leucine
    'CTG' => 'L',    # Leucine
    'CTT' => 'L',    # Leucine
    'CCA' => 'P',    # Proline
    'CCC' => 'P',    # Proline
    'CCG' => 'P',    # Proline
    'CCT' => 'P',    # Proline
    '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
    'GTA' => 'V',    # Valine
    'GTC' => 'V',    # Valine
    'GTG' => 'V',    # Valine
    'GTT' => 'V',    # Valine
    'GCA' => 'A',    # Alanine
    'GCC' => 'A',    # Alanine
    'GCG' => 'A',    # Alanine
    'GCT' => 'A',    # Alanine
    'GAC' => 'D',    # Aspartic Acid
    'GAT' => 'D',    # Aspartic Acid
    'GAA' => 'E',    # Glutamic Acid
    'GAG' => 'E',    # Glutamic Acid
    'GGA' => 'G',    # Glycine
    'GGC' => 'G',    # Glycine
    'GGG' => 'G',    # Glycine
    'GGT' => 'G',    # Glycine
    );


for ($s=0; $s<3; $s++) {
        $scrap = substr($text,0,$s);
        $main = substr($text,$s);
        $main =~ s/(...)/"$convertor{uc $1}" || "?"/eg;
        print "$scrap$main\n";
        }

 

%convertor = ( ~~~ );

= used for giving information for translation (codon into amino acids)

for ($s=0; $s<3; $s++)