Difference between revisions of "2. Make a Perl program translating 'all' combinations of triple bases into amino acids -YJ code:309ir"

From Biolecture.org
imported>Yeong Jae Kim
(Created page with "<p>aim . translating triple base codes convert into amino acids</p> <p>strategy.</p> <p>code.</p> <p> </p>")
 
imported>Yeong Jae Kim
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<p>aim . translating triple base codes convert into amino acids</p>
 
<p>aim . translating triple base codes convert into amino acids</p>
  
<p>strategy.</p>
+
<p>&nbsp;</p>
  
<p>code.</p>
+
<p>&nbsp;</p>
  
 
<p>&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>

Latest revision as of 02:02, 27 May 2016

aim . translating triple base codes convert into amino acids

 

 

 

-------------------------------------------------------------------------------------------------------------------------------------

#!/usr/bin/perl
use strict;
use warnings;

  1. this function is translating 'all' combinations of triple bases into amino acids

my %basetoaa= (
   "UUU" => "F", "UUC" => "F",
   "UUA" => "L", "UUG" => "L",
   "CUU" => "L", "CUC" => "L",
   "CUA" => "L", "CUG" => "L",
   "AUU" => "I", "AUC" => "I",
   "AUA" => "I", "AUG" => "M",
   "GUU" => "V", "GUC" => "V",
   "GUA" => "V", "GUG" => "V",
   
   "UCU" => "S", "UCC" => "S",
   "UCA" => "S", "UCG" => "S",
   "CCU" => "P", "CCC" => "P",
   "CCA" => "P", "CCG" => "P",
   "ACU" => "T", "ACC" => "T",
   "ACA" => "T", "ACG" => "T",
   "GCU" => "A", "GCC" => "A",
   "GCA" => "A", "GCG" => "A",
   
   "UAU" => "Y", "UAC" => "Y",
   "UAA" => "*", "UAG" => "*",
   "CAU" => "H", "CAC" => "H",
   "CAA" => "Q", "CAG" => "Q",
   "AAU" => "N", "AAC" => "N",
   "AAA" => "K", "AAG" => "K",
   "GAU" => "D", "GAC" => "D",
   "GAA" => "E", "GAG" => "E",
   
   "UGU" => "C", "UGC" => "C",
   "UGA" => "*", "UGG" => "W",
   "CGU" => "R", "CGC" => "R",
   "CGA" => "R", "CGG" => "R",
   "AGU" => "S", "AGC" => "S",
   "AGA" => "R", "AGG" => "R",
   "GGU" => "G", "GGC" => "G",
   "GGA" => "G", "GGG" => "G",
   
   "TTT" => "F", "TTC" => "F",
   "TTA" => "L", "TTG" => "L",
   "CTT" => "L", "CTC" => "L",
   "CTA" => "L", "CTG" => "L",
   "ATT" => "I", "ATC" => "I",
   "ATA" => "I", "ATG" => "M",
   "GTT" => "V", "GTC" => "V",
   "GTA" => "V", "GTG" => "V",
   
   "TCT" => "S", "TCC" => "S",
   "TCA" => "S", "TCG" => "S",
   "CCT" => "P", "CCC" => "P",
   "CCA" => "P", "CCG" => "P",
   "ACT" => "T", "ACC" => "T",
   "ACA" => "T", "ACG" => "T",
   "GCT" => "A", "GCC" => "A",
   "GCA" => "A", "GCG" => "A",
   
   "TAT" => "Y", "TAC" => "Y",
   "TAA" => "*", "TAG" => "*",
   "CAT" => "H", "CAC" => "H",
   "CAA" => "Q", "CAG" => "Q",
   "AAT" => "N", "AAC" => "N",
   "AAA" => "K", "AAG" => "K",
   "GAT" => "D", "GAC" => "D",
   "GAA" => "E", "GAG" => "E",
   
   "TGT" => "C", "TGC" => "C",
   "TGA" => "*", "TGG" => "W",
   "CGT" => "R", "CGC" => "R",
   "CGA" => "R", "CGG" => "R",
   "AGT" => "S", "AGC" => "S",
   "AGA" => "R", "AGG" => "R",
   "GGT" => "G", "GGC" => "G",
   "GGA" => "G", "GGG" => "G",
   "KYJ" => "error"
);
print "Guru : ";
print $basetoaa{"AAA"}; # K
print $basetoaa{"AUU"}; # I
print $basetoaa{"AUG"},"\n"; # M

## 변수입력
my $codon_data;
my $codon_data_length;
my @codon_data_split;
my @three_codon_data;
my @amino_acid_data;
my $amino_acid_length;
my $yorn1, $yorn2, $yorn3, $yorn4, $yorn5;
my $filename;

## Asking the way of how to input user's data(base).
print "This is a converting programm.\n\n";
print "Do you want to input your data using keyboard? [y/n] ";

  1. input your choose in yorn.

$yorn1 = <STDIN>;

  1. delete last enter key command 

chomp $yorn1;

  1. print $yorn," \n";
  2. yes -> using keyboard\ no-> using file\ else-> error\

if($yorn1 eq "y")
{
 print "<You want to input your data by using keyboard>\n";
}
elsif($yorn1 eq "n")
{
 print "<You want to input your data by using file>\n";
}
else
{
 print "<Error!>\n<you must input 'y' or 'n'.>\n";
 exit;
}

#--------------------------------------------------------------------

    1. input by keyboard

if ($yorn1 eq "y")
{
 ## input data 
 print "<please input your data using keyboard>\n"; #input data in $condon_data
 $codon_data = <STDIN>;
 chomp $codon_data;
 #delete (enter) command. chomp funtion delete last command.
 #because STDIN function memory all of command.
 #if do not use chomp, $codon_data is (Yeong Jae Kim 02:02, 27 May 2016 (KST))+(enter key)
 #so you must do it    

## input through file.
elsif($yorn1 eq "n")
{
 print "---------------------------------------\n<Caution!>\n<You must put on your file in same directory>\n";
 print "<Do not write any word without codon data>\n";
 print "<Please input your file name without filename extension>\n";
 print "<If you want to input BRCA1.txt, just type BRCA1>\n---------------------------------\n";
 print "<Your input file name : ";
 $filename = <STDIN>;
 chomp $filename;
 # $filename = "$filename";
 open(TEXT, "$filename.txt");
 $codon_data = <TEXT>;
 close (TEXT);
 ## convert uppercase(대문자)-uc()
 $codon_data = uc($codon_data);
 # print $codon_data,"\n"; 
}

  1. ------------------------------------------------------------------------

## confirm data
print "\nIs it yours?\n-----------------------------------\n$codon_data\n----------------------------------\n";
 

    1. convert uppercase(대문자)-uc()

$codon_data = uc($codon_data);
  

    1. check data length

$codon_data_length = length ($codon_data);
print "Codon length is $codon_data_length.\n";

  1. if codon length is not multiply by 3, i notice warning message
  2. print $codon_data_length%3;

## warning to data_length
if ($codon_data_length%3 ne "0")
{
 print "[warning] your codon length is not multiply by 3."; 
 print "Do you want continue? [y/n] ";
 $yorn2 = <STDIN>;
 chomp $yorn2; 
 if ($yorn2 eq "n")
 {
  exit; # just stop;
 }
}
 
 ## split codon_data
@codon_data_split = split(//, $codon_data);

  1. print @codon_data;
  2. print $codon_data[0];
  3. print $codon_data[1];
  4. print $codon_data[3];
  5. print @codon_data_split,"\n";
  6. my $i =3;
  7. print $codon_data_split[$i];

 
 ## check data
foreach my $i (0..$#codon_data_split)
{
 ## U,T,C,A,G check
 if ($codon_data_split[$i] eq "U" || 
 $codon_data_split[$i] eq "T" || 
 $codon_data_split[$i] eq "C"|| 
 $codon_data_split[$i] eq "A"|| 
 $codon_data_split[$i] eq "G")
 {
  next;
 }
 else
 {
  print "[error]you do not input codon. please check your data\n";
  exit; 
 }
}
 ## divided 3 codons
for(my $i=0; $i < ($codon_data_length); $i=$i+3) 
{
 # print "this ($i/3) step";
 my $j=$i/3;
 $three_codon_data[$j] = $codon_data_split[$i].$codon_data_split[$i+1].$codon_data_split[$i+2];
 # print $three_codon_data[$j],"\n";
 # print length @three_codon_data;
 # you can't get size of array using length function
}
 # you just do to define scalar variable which equal array variable
 $amino_acid_length = @three_codon_data;
 # print "test1 = ",$amino_acid_length;
 # print @three_codon_data;
 # print $amino_acid_length;

 ## convert codon bases into amino acids
for (my $i=0; $i < ($amino_acid_length); $i++)
{
 # print $three_codon_data[$i];
 $amino_acid_data[$i] = $basetoaa{"$three_codon_data[$i]"};
 # print $amino_acid_data[$i],"\n";

#-------------------------------------------------
 ## result
print "result : ",@amino_acid_data,"\n";

 ## alignment
print "<Do you want alignment?> [y/n] ";
$yorn3 = <STDIN>;
chomp $yorn3;
print "<Do you want see the number?> [y/n] ";
$yorn4 = <STDIN>;
chomp $yorn4;
if ($yorn3 eq "y")
{
 my $line = int($amino_acid_length/10);
 for (my $i=0; $i <= $line; $i++)
 {
    ## print number
   if ($yorn4 eq "y")
   {
    my $j =10*$i+1;
    print $j;   
    print "\n     ";
   } 
    ## print codon data
   for (my $j=0; $j < 10; $j++)
   {
    print $three_codon_data[10*$i+$j]," ";
   }  
   print "\n     ";
    ## print amino acid data
   for (my $j=0; $j < 10; $j++)
   {
    my $k = 10*$i+$j+1;
    if ($k == $amino_acid_length && $yorn2 eq "y")
    {
     print " ?", "\n";
    }
    else
    {
     print " ", $amino_acid_data[10*$i+$j], "  ";
    }  
   }
    print "\n";
  }
}

  1. ----------------------------------------------------

 ## make result file
 print "<Do you want make file?> [y/n] ";
$yorn5 = <STDIN>;
chomp $yorn5;
 if ($yorn5 eq "y")
 {
  print "<What is the file name?>\n";
  print "<if you want to input BRCA1.txt, just type BRCA1>\n---------------------------------\n";
  print "<Your output file name : ";
  $output_filename = <STDIN>;
  chomp $output_filename;
  while ($filename eq $output_filename)
  {
   print "<This name is same to codon data file name.>\n";
   print "<Please input another name!!!> \n";
   print "<Your output file name : ";
   $output_filename = <STDIN>;
   chomp $output_filename;
  }
  # $output_filename = "$output_filename.txt";
  open (TEXT, ">$output_filename.txt"); 
  my $outputdata = join ("", @amino_acid_data);
  # print @amino_acid_data,"\n";
  # print $outputdata;
  print TEXT $outputdata;
  close (TEXT);
  print "Success! check your file";
  exit;
 }
 else 
 {
  exit;
 }