2. Make a Perl program translating 'all' combinations of triple bases into amino acids -YJ code:309ir
aim . translating triple base codes convert into amino acids
-------------------------------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
- 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] ";
- input your choose in yorn.
$yorn1 = <STDIN>;
- delete last enter key command
chomp $yorn1;
- print $yorn," \n";
- 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;
}
#--------------------------------------------------------------------
- input by keyboard
- 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";
}
- ------------------------------------------------------------------------
## confirm data
print "\nIs it yours?\n-----------------------------------\n$codon_data\n----------------------------------\n";
- convert uppercase(대문자)-uc()
- convert uppercase(대문자)-uc()
$codon_data = uc($codon_data);
- check data length
- check data length
$codon_data_length = length ($codon_data);
print "Codon length is $codon_data_length.\n";
- if codon length is not multiply by 3, i notice warning message
- 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);
- print @codon_data;
- print $codon_data[0];
- print $codon_data[1];
- print $codon_data[3];
- print @codon_data_split,"\n";
- my $i =3;
- 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";
}
}
- ----------------------------------------------------
## 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;
}