Changes

From Biolecture.org
no edit summary
<p>aim . translating triple base codes convert into amino acids</p>
<p>strategy.&nbsp;</p>
<p>code.&nbsp;</p>
<p>&nbsp;</p>
 
<p>-------------------------------------------------------------------------------------------------------------------------------------</p>
 
<p>#!/usr/bin/perl<br />
use strict;<br />
use warnings;<br />
#this function is translating &#39;all&#39; combinations of triple bases into amino acids<br />
my %basetoaa= (<br />
&nbsp; &nbsp;&quot;UUU&quot; =&gt; &quot;F&quot;, &quot;UUC&quot; =&gt; &quot;F&quot;,<br />
&nbsp; &nbsp;&quot;UUA&quot; =&gt; &quot;L&quot;, &quot;UUG&quot; =&gt; &quot;L&quot;,<br />
&nbsp; &nbsp;&quot;CUU&quot; =&gt; &quot;L&quot;, &quot;CUC&quot; =&gt; &quot;L&quot;,<br />
&nbsp; &nbsp;&quot;CUA&quot; =&gt; &quot;L&quot;, &quot;CUG&quot; =&gt; &quot;L&quot;,<br />
&nbsp; &nbsp;&quot;AUU&quot; =&gt; &quot;I&quot;, &quot;AUC&quot; =&gt; &quot;I&quot;,<br />
&nbsp; &nbsp;&quot;AUA&quot; =&gt; &quot;I&quot;, &quot;AUG&quot; =&gt; &quot;M&quot;,<br />
&nbsp; &nbsp;&quot;GUU&quot; =&gt; &quot;V&quot;, &quot;GUC&quot; =&gt; &quot;V&quot;,<br />
&nbsp; &nbsp;&quot;GUA&quot; =&gt; &quot;V&quot;, &quot;GUG&quot; =&gt; &quot;V&quot;,<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;&quot;UCU&quot; =&gt; &quot;S&quot;, &quot;UCC&quot; =&gt; &quot;S&quot;,<br />
&nbsp; &nbsp;&quot;UCA&quot; =&gt; &quot;S&quot;, &quot;UCG&quot; =&gt; &quot;S&quot;,<br />
&nbsp; &nbsp;&quot;CCU&quot; =&gt; &quot;P&quot;, &quot;CCC&quot; =&gt; &quot;P&quot;,<br />
&nbsp; &nbsp;&quot;CCA&quot; =&gt; &quot;P&quot;, &quot;CCG&quot; =&gt; &quot;P&quot;,<br />
&nbsp; &nbsp;&quot;ACU&quot; =&gt; &quot;T&quot;, &quot;ACC&quot; =&gt; &quot;T&quot;,<br />
&nbsp; &nbsp;&quot;ACA&quot; =&gt; &quot;T&quot;, &quot;ACG&quot; =&gt; &quot;T&quot;,<br />
&nbsp; &nbsp;&quot;GCU&quot; =&gt; &quot;A&quot;, &quot;GCC&quot; =&gt; &quot;A&quot;,<br />
&nbsp; &nbsp;&quot;GCA&quot; =&gt; &quot;A&quot;, &quot;GCG&quot; =&gt; &quot;A&quot;,<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;&quot;UAU&quot; =&gt; &quot;Y&quot;, &quot;UAC&quot; =&gt; &quot;Y&quot;,<br />
&nbsp; &nbsp;&quot;UAA&quot; =&gt; &quot;*&quot;, &quot;UAG&quot; =&gt; &quot;*&quot;,<br />
&nbsp; &nbsp;&quot;CAU&quot; =&gt; &quot;H&quot;, &quot;CAC&quot; =&gt; &quot;H&quot;,<br />
&nbsp; &nbsp;&quot;CAA&quot; =&gt; &quot;Q&quot;, &quot;CAG&quot; =&gt; &quot;Q&quot;,<br />
&nbsp; &nbsp;&quot;AAU&quot; =&gt; &quot;N&quot;, &quot;AAC&quot; =&gt; &quot;N&quot;,<br />
&nbsp; &nbsp;&quot;AAA&quot; =&gt; &quot;K&quot;, &quot;AAG&quot; =&gt; &quot;K&quot;,<br />
&nbsp; &nbsp;&quot;GAU&quot; =&gt; &quot;D&quot;, &quot;GAC&quot; =&gt; &quot;D&quot;,<br />
&nbsp; &nbsp;&quot;GAA&quot; =&gt; &quot;E&quot;, &quot;GAG&quot; =&gt; &quot;E&quot;,<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;&quot;UGU&quot; =&gt; &quot;C&quot;, &quot;UGC&quot; =&gt; &quot;C&quot;,<br />
&nbsp; &nbsp;&quot;UGA&quot; =&gt; &quot;*&quot;, &quot;UGG&quot; =&gt; &quot;W&quot;,<br />
&nbsp; &nbsp;&quot;CGU&quot; =&gt; &quot;R&quot;, &quot;CGC&quot; =&gt; &quot;R&quot;,<br />
&nbsp; &nbsp;&quot;CGA&quot; =&gt; &quot;R&quot;, &quot;CGG&quot; =&gt; &quot;R&quot;,<br />
&nbsp; &nbsp;&quot;AGU&quot; =&gt; &quot;S&quot;, &quot;AGC&quot; =&gt; &quot;S&quot;,<br />
&nbsp; &nbsp;&quot;AGA&quot; =&gt; &quot;R&quot;, &quot;AGG&quot; =&gt; &quot;R&quot;,<br />
&nbsp; &nbsp;&quot;GGU&quot; =&gt; &quot;G&quot;, &quot;GGC&quot; =&gt; &quot;G&quot;,<br />
&nbsp; &nbsp;&quot;GGA&quot; =&gt; &quot;G&quot;, &quot;GGG&quot; =&gt; &quot;G&quot;,<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;&quot;TTT&quot; =&gt; &quot;F&quot;, &quot;TTC&quot; =&gt; &quot;F&quot;,<br />
&nbsp; &nbsp;&quot;TTA&quot; =&gt; &quot;L&quot;, &quot;TTG&quot; =&gt; &quot;L&quot;,<br />
&nbsp; &nbsp;&quot;CTT&quot; =&gt; &quot;L&quot;, &quot;CTC&quot; =&gt; &quot;L&quot;,<br />
&nbsp; &nbsp;&quot;CTA&quot; =&gt; &quot;L&quot;, &quot;CTG&quot; =&gt; &quot;L&quot;,<br />
&nbsp; &nbsp;&quot;ATT&quot; =&gt; &quot;I&quot;, &quot;ATC&quot; =&gt; &quot;I&quot;,<br />
&nbsp; &nbsp;&quot;ATA&quot; =&gt; &quot;I&quot;, &quot;ATG&quot; =&gt; &quot;M&quot;,<br />
&nbsp; &nbsp;&quot;GTT&quot; =&gt; &quot;V&quot;, &quot;GTC&quot; =&gt; &quot;V&quot;,<br />
&nbsp; &nbsp;&quot;GTA&quot; =&gt; &quot;V&quot;, &quot;GTG&quot; =&gt; &quot;V&quot;,<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;&quot;TCT&quot; =&gt; &quot;S&quot;, &quot;TCC&quot; =&gt; &quot;S&quot;,<br />
&nbsp; &nbsp;&quot;TCA&quot; =&gt; &quot;S&quot;, &quot;TCG&quot; =&gt; &quot;S&quot;,<br />
&nbsp; &nbsp;&quot;CCT&quot; =&gt; &quot;P&quot;, &quot;CCC&quot; =&gt; &quot;P&quot;,<br />
&nbsp; &nbsp;&quot;CCA&quot; =&gt; &quot;P&quot;, &quot;CCG&quot; =&gt; &quot;P&quot;,<br />
&nbsp; &nbsp;&quot;ACT&quot; =&gt; &quot;T&quot;, &quot;ACC&quot; =&gt; &quot;T&quot;,<br />
&nbsp; &nbsp;&quot;ACA&quot; =&gt; &quot;T&quot;, &quot;ACG&quot; =&gt; &quot;T&quot;,<br />
&nbsp; &nbsp;&quot;GCT&quot; =&gt; &quot;A&quot;, &quot;GCC&quot; =&gt; &quot;A&quot;,<br />
&nbsp; &nbsp;&quot;GCA&quot; =&gt; &quot;A&quot;, &quot;GCG&quot; =&gt; &quot;A&quot;,<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;&quot;TAT&quot; =&gt; &quot;Y&quot;, &quot;TAC&quot; =&gt; &quot;Y&quot;,<br />
&nbsp; &nbsp;&quot;TAA&quot; =&gt; &quot;*&quot;, &quot;TAG&quot; =&gt; &quot;*&quot;,<br />
&nbsp; &nbsp;&quot;CAT&quot; =&gt; &quot;H&quot;, &quot;CAC&quot; =&gt; &quot;H&quot;,<br />
&nbsp; &nbsp;&quot;CAA&quot; =&gt; &quot;Q&quot;, &quot;CAG&quot; =&gt; &quot;Q&quot;,<br />
&nbsp; &nbsp;&quot;AAT&quot; =&gt; &quot;N&quot;, &quot;AAC&quot; =&gt; &quot;N&quot;,<br />
&nbsp; &nbsp;&quot;AAA&quot; =&gt; &quot;K&quot;, &quot;AAG&quot; =&gt; &quot;K&quot;,<br />
&nbsp; &nbsp;&quot;GAT&quot; =&gt; &quot;D&quot;, &quot;GAC&quot; =&gt; &quot;D&quot;,<br />
&nbsp; &nbsp;&quot;GAA&quot; =&gt; &quot;E&quot;, &quot;GAG&quot; =&gt; &quot;E&quot;,<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;&quot;TGT&quot; =&gt; &quot;C&quot;, &quot;TGC&quot; =&gt; &quot;C&quot;,<br />
&nbsp; &nbsp;&quot;TGA&quot; =&gt; &quot;*&quot;, &quot;TGG&quot; =&gt; &quot;W&quot;,<br />
&nbsp; &nbsp;&quot;CGT&quot; =&gt; &quot;R&quot;, &quot;CGC&quot; =&gt; &quot;R&quot;,<br />
&nbsp; &nbsp;&quot;CGA&quot; =&gt; &quot;R&quot;, &quot;CGG&quot; =&gt; &quot;R&quot;,<br />
&nbsp; &nbsp;&quot;AGT&quot; =&gt; &quot;S&quot;, &quot;AGC&quot; =&gt; &quot;S&quot;,<br />
&nbsp; &nbsp;&quot;AGA&quot; =&gt; &quot;R&quot;, &quot;AGG&quot; =&gt; &quot;R&quot;,<br />
&nbsp; &nbsp;&quot;GGT&quot; =&gt; &quot;G&quot;, &quot;GGC&quot; =&gt; &quot;G&quot;,<br />
&nbsp; &nbsp;&quot;GGA&quot; =&gt; &quot;G&quot;, &quot;GGG&quot; =&gt; &quot;G&quot;,<br />
&nbsp; &nbsp;&quot;KYJ&quot; =&gt; &quot;error&quot;<br />
);<br />
print &quot;Guru : &quot;;<br />
print $basetoaa{&quot;AAA&quot;}; # K<br />
print $basetoaa{&quot;AUU&quot;}; # I<br />
print $basetoaa{&quot;AUG&quot;},&quot;\n&quot;; # M</p>
 
<p>## 변수입력<br />
my $codon_data;<br />
my $codon_data_length;<br />
my @codon_data_split;<br />
my @three_codon_data;<br />
my @amino_acid_data;<br />
my $amino_acid_length;<br />
my $yorn1, $yorn2, $yorn3, $yorn4, $yorn5;<br />
my $filename;</p>
 
<p>## Asking the way of how to input user&#39;s data(base).<br />
print &quot;This is a converting programm.\n\n&quot;;<br />
print &quot;Do you want to input your data using keyboard? [y/n] &quot;;<br />
# input your choose in yorn.<br />
$yorn1 = &lt;STDIN&gt;;<br />
# delete last enter key command&nbsp;<br />
chomp $yorn1;<br />
# print $yorn,&quot; \n&quot;;<br />
# yes -&gt; using keyboard\ no-&gt; using file\ else-&gt; error\<br />
if($yorn1 eq &quot;y&quot;)<br />
{<br />
&nbsp;print &quot;&lt;You want to input your data by using keyboard&gt;\n&quot;;<br />
}<br />
elsif($yorn1 eq &quot;n&quot;)<br />
{<br />
&nbsp;print &quot;&lt;You want to input your data by using file&gt;\n&quot;;<br />
}<br />
else<br />
{<br />
&nbsp;print &quot;&lt;Error!&gt;\n&lt;you must input &#39;y&#39; or &#39;n&#39;.&gt;\n&quot;;<br />
&nbsp;exit;<br />
}</p>
 
<p>#--------------------------------------------------------------------<br />
## input by keyboard<br />
if ($yorn1 eq &quot;y&quot;)<br />
{<br />
&nbsp;## input data&nbsp;<br />
&nbsp;print &quot;&lt;please input your data using keyboard&gt;\n&quot;; #input data in $condon_data<br />
&nbsp;$codon_data = &lt;STDIN&gt;;<br />
&nbsp;chomp $codon_data;<br />
&nbsp;#delete (enter) command. chomp funtion delete last command.<br />
&nbsp;#because STDIN function memory all of command.<br />
&nbsp;#if do not use chomp, $codon_data is ([[User:Yeong Jae Kim|Yeong Jae Kim]] 02:02, 27 May 2016 (KST))+(enter key)<br />
&nbsp;#so you must do it &nbsp; &nbsp;<br />
}&nbsp;</p>
 
<p>## input through file.<br />
elsif($yorn1 eq &quot;n&quot;)<br />
{<br />
&nbsp;print &quot;---------------------------------------\n&lt;Caution!&gt;\n&lt;You must put on your file in same directory&gt;\n&quot;;<br />
&nbsp;print &quot;&lt;Do not write any word without codon data&gt;\n&quot;;<br />
&nbsp;print &quot;&lt;Please input your file name without filename extension&gt;\n&quot;;<br />
&nbsp;print &quot;&lt;If you want to input BRCA1.txt, just type BRCA1&gt;\n---------------------------------\n&quot;;<br />
&nbsp;print &quot;&lt;Your input file name : &quot;;<br />
&nbsp;$filename = &lt;STDIN&gt;;<br />
&nbsp;chomp $filename;<br />
&nbsp;# $filename = &quot;$filename&quot;;<br />
&nbsp;open(TEXT, &quot;$filename.txt&quot;);<br />
&nbsp;$codon_data = &lt;TEXT&gt;;<br />
&nbsp;close (TEXT);<br />
&nbsp;## convert uppercase(대문자)-uc()<br />
&nbsp;$codon_data = uc($codon_data);<br />
&nbsp;# print $codon_data,&quot;\n&quot;;&nbsp;<br />
}<br />
#------------------------------------------------------------------------</p>
 
<p>## confirm data<br />
print &quot;\nIs it yours?\n-----------------------------------\n$codon_data\n----------------------------------\n&quot;;<br />
&nbsp;<br />
## convert uppercase(대문자)-uc()<br />
$codon_data = uc($codon_data);<br />
&nbsp;&nbsp;<br />
## check data length<br />
$codon_data_length = length ($codon_data);<br />
print &quot;Codon length is $codon_data_length.\n&quot;;<br />
# if codon length is not multiply by 3, i notice warning message<br />
# print $codon_data_length%3;</p>
 
<p>## warning to data_length<br />
if ($codon_data_length%3 ne &quot;0&quot;)<br />
{<br />
&nbsp;print &quot;[warning] your codon length is not multiply by 3.&quot;;&nbsp;<br />
&nbsp;print &quot;Do you want continue? [y/n] &quot;;<br />
&nbsp;$yorn2 = &lt;STDIN&gt;;<br />
&nbsp;chomp $yorn2;&nbsp;<br />
&nbsp;if ($yorn2 eq &quot;n&quot;)<br />
&nbsp;{<br />
&nbsp; exit; # just stop;<br />
&nbsp;}<br />
}<br />
&nbsp;<br />
&nbsp;## split codon_data<br />
@codon_data_split = split(//, $codon_data);<br />
# print @codon_data;<br />
# print $codon_data[0];<br />
# print $codon_data[1];<br />
# print $codon_data[3];<br />
# print @codon_data_split,&quot;\n&quot;;<br />
# my $i =3;<br />
# print $codon_data_split[$i];<br />
&nbsp;<br />
&nbsp;## check data<br />
foreach my $i (0..$#codon_data_split)<br />
{<br />
&nbsp;## U,T,C,A,G check<br />
&nbsp;if ($codon_data_split[$i] eq &quot;U&quot; ||&nbsp;<br />
&nbsp;$codon_data_split[$i] eq &quot;T&quot; ||&nbsp;<br />
&nbsp;$codon_data_split[$i] eq &quot;C&quot;||&nbsp;<br />
&nbsp;$codon_data_split[$i] eq &quot;A&quot;||&nbsp;<br />
&nbsp;$codon_data_split[$i] eq &quot;G&quot;)<br />
&nbsp;{<br />
&nbsp; next;<br />
&nbsp;}<br />
&nbsp;else<br />
&nbsp;{<br />
&nbsp; print &quot;[error]you do not input codon. please check your data\n&quot;;<br />
&nbsp; exit;&nbsp;<br />
&nbsp;}<br />
}<br />
&nbsp;## divided 3 codons<br />
for(my $i=0; $i &lt; ($codon_data_length); $i=$i+3)&nbsp;<br />
{<br />
&nbsp;# print &quot;this ($i/3) step&quot;;<br />
&nbsp;my $j=$i/3;<br />
&nbsp;$three_codon_data[$j] = $codon_data_split[$i].$codon_data_split[$i+1].$codon_data_split[$i+2];<br />
&nbsp;# print $three_codon_data[$j],&quot;\n&quot;;<br />
&nbsp;# print length @three_codon_data;<br />
&nbsp;# you can&#39;t get size of array using length function<br />
}<br />
&nbsp;# you just do to define scalar variable which equal array variable<br />
&nbsp;$amino_acid_length = @three_codon_data;<br />
&nbsp;# print &quot;test1 = &quot;,$amino_acid_length;<br />
&nbsp;# print @three_codon_data;<br />
&nbsp;# print $amino_acid_length;</p>
 
<p>&nbsp;## convert codon bases into amino acids<br />
for (my $i=0; $i &lt; ($amino_acid_length); $i++)<br />
{<br />
&nbsp;# print $three_codon_data[$i];<br />
&nbsp;$amino_acid_data[$i] = $basetoaa{&quot;$three_codon_data[$i]&quot;};<br />
&nbsp;# print $amino_acid_data[$i],&quot;\n&quot;;<br />
}&nbsp;</p>
 
<p>#-------------------------------------------------<br />
&nbsp;## result<br />
print &quot;result : &quot;,@amino_acid_data,&quot;\n&quot;;</p>
 
<p>&nbsp;## alignment<br />
print &quot;&lt;Do you want alignment?&gt; [y/n] &quot;;<br />
$yorn3 = &lt;STDIN&gt;;<br />
chomp $yorn3;<br />
print &quot;&lt;Do you want see the number?&gt; [y/n] &quot;;<br />
$yorn4 = &lt;STDIN&gt;;<br />
chomp $yorn4;<br />
if ($yorn3 eq &quot;y&quot;)<br />
{<br />
&nbsp;my $line = int($amino_acid_length/10);<br />
&nbsp;for (my $i=0; $i &lt;= $line; $i++)<br />
&nbsp;{<br />
&nbsp; &nbsp; ## print number<br />
&nbsp; &nbsp;if ($yorn4 eq &quot;y&quot;)<br />
&nbsp; &nbsp;{<br />
&nbsp; &nbsp; my $j =10*$i+1;<br />
&nbsp; &nbsp; print $j; &nbsp;&nbsp;<br />
&nbsp; &nbsp; print &quot;\n &nbsp; &nbsp; &quot;;<br />
&nbsp; &nbsp;}&nbsp;<br />
&nbsp; &nbsp; ## print codon data<br />
&nbsp; &nbsp;for (my $j=0; $j &lt; 10; $j++)<br />
&nbsp; &nbsp;{<br />
&nbsp; &nbsp; print $three_codon_data[10*$i+$j],&quot; &quot;;<br />
&nbsp; &nbsp;} &nbsp;<br />
&nbsp; &nbsp;print &quot;\n &nbsp; &nbsp; &quot;;<br />
&nbsp; &nbsp; ## print amino acid data<br />
&nbsp; &nbsp;for (my $j=0; $j &lt; 10; $j++)<br />
&nbsp; &nbsp;{<br />
&nbsp; &nbsp; my $k = 10*$i+$j+1;<br />
&nbsp; &nbsp; if ($k == $amino_acid_length &amp;&amp; $yorn2 eq &quot;y&quot;)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp;print &quot; ?&quot;, &quot;\n&quot;;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; else<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp;print &quot; &quot;, $amino_acid_data[10*$i+$j], &quot; &nbsp;&quot;;<br />
&nbsp; &nbsp; } &nbsp;<br />
&nbsp; &nbsp;}<br />
&nbsp; &nbsp; print &quot;\n&quot;;<br />
&nbsp; }<br />
}<br />
#----------------------------------------------------<br />
&nbsp;## make result file<br />
&nbsp;print &quot;&lt;Do you want make file?&gt; [y/n] &quot;;<br />
$yorn5 = &lt;STDIN&gt;;<br />
chomp $yorn5;<br />
&nbsp;if ($yorn5 eq &quot;y&quot;)<br />
&nbsp;{<br />
&nbsp; print &quot;&lt;What is the file name?&gt;\n&quot;;<br />
&nbsp; print &quot;&lt;if you want to input BRCA1.txt, just type BRCA1&gt;\n---------------------------------\n&quot;;<br />
&nbsp; print &quot;&lt;Your output file name : &quot;;<br />
&nbsp; $output_filename = &lt;STDIN&gt;;<br />
&nbsp; chomp $output_filename;<br />
&nbsp; while ($filename eq $output_filename)<br />
&nbsp; {<br />
&nbsp; &nbsp;print &quot;&lt;This name is same to codon data file name.&gt;\n&quot;;<br />
&nbsp; &nbsp;print &quot;&lt;Please input another name!!!&gt; \n&quot;;<br />
&nbsp; &nbsp;print &quot;&lt;Your output file name : &quot;;<br />
&nbsp; &nbsp;$output_filename = &lt;STDIN&gt;;<br />
&nbsp; &nbsp;chomp $output_filename;<br />
&nbsp; }<br />
&nbsp; # $output_filename = &quot;$output_filename.txt&quot;;<br />
&nbsp; open (TEXT, &quot;&gt;$output_filename.txt&quot;);&nbsp;<br />
&nbsp; my $outputdata = join (&quot;&quot;, @amino_acid_data);<br />
&nbsp; # print @amino_acid_data,&quot;\n&quot;;<br />
&nbsp; # print $outputdata;<br />
&nbsp; print TEXT $outputdata;<br />
&nbsp; close (TEXT);<br />
&nbsp; print &quot;Success! check your file&quot;;<br />
&nbsp; exit;<br />
&nbsp;}<br />
&nbsp;else&nbsp;<br />
&nbsp;{<br />
&nbsp; exit;<br />
&nbsp;}</p>

Navigation menu