#!/usr/bin/perl -w
use strict;
my ($file,$line,$sequence,$i,$codon,$CODON,$protein);
my %genetic_code = qw(
TTT F
TCT S
TAT Y
TGT C
TTC F
TCC S
TAC Y
TGC C
TTA L
TCA S
TAA _
TGA _
TTG L
TCG S
TAG _
TGG W
CTT L
CCT P
CAT H
CGT R
CTC L
CCC P
CAC H
CGC R
CTA L
CCA P
CAA Q
CGA R
CTG L
CCG P
CAG Q
CGG R
ATT I
ACT T
AAT N
AGT S
ATC I
ACC T
AAC N
AGC S
ATA I
ACA T
AAA K
AGA R
ATG M
ACG T
AAG K
AGG R
GTT V
GCT A
GAT D
GGT G
GTC V
GCC A
GAC D
GGC G
GTA V
GCA A
GAA E
GGA G
GTG V
GCG A
GAG E
GGG G
);
print "Enter the filename: ";
$file = <STDIN>;
chomp $file;
open (FILE, $file) or die "Cannot open file : $file \n\n";
# if there are 10 lines in the file then while loop iterates 10 times
# next command resets the while loop to the next line
while ($line = <FILE>)
{
# Discard blank lines
if ($line =~ /^\s*#/ )
{ next; }
# Discard comment line
elsif ($line=~/^#/)
{ next; }
# Discard fasta header line
elsif($line =~ /^>/ )
{ next; }
# Keep concatenating to $sequence string
else
{ $sequence .= $line; }
}
$sequence =~ s/\s//g ;
close FILE;
for ($i=0; $i < (length ($sequence) - 2) ; $i += 3)
{
# From the string '$sequence' at position '$i' extract 3 characters & store it in '$codon'
$codon = (substr($sequence,$i,3));
# Converting any lower case characters to upper case
$CODON = uc $codon;
# Checking for the existence of CODON in the hash %genetic_code
if(exists $genetic_code{$CODON})
# The corresponding amino acid in the hash is stored in $protein
{ $protein .= $genetic_code{$CODON}; }
else
{ die "Bad codon !! \n\n";}
}
print "The translated protein sequence is : $protein \n\n";
use strict;
my ($file,$line,$sequence,$i,$codon,$CODON,$protein);
my %genetic_code = qw(
TTT F
TCT S
TAT Y
TGT C
TTC F
TCC S
TAC Y
TGC C
TTA L
TCA S
TAA _
TGA _
TTG L
TCG S
TAG _
TGG W
CTT L
CCT P
CAT H
CGT R
CTC L
CCC P
CAC H
CGC R
CTA L
CCA P
CAA Q
CGA R
CTG L
CCG P
CAG Q
CGG R
ATT I
ACT T
AAT N
AGT S
ATC I
ACC T
AAC N
AGC S
ATA I
ACA T
AAA K
AGA R
ATG M
ACG T
AAG K
AGG R
GTT V
GCT A
GAT D
GGT G
GTC V
GCC A
GAC D
GGC G
GTA V
GCA A
GAA E
GGA G
GTG V
GCG A
GAG E
GGG G
);
print "Enter the filename: ";
$file = <STDIN>;
chomp $file;
open (FILE, $file) or die "Cannot open file : $file \n\n";
# if there are 10 lines in the file then while loop iterates 10 times
# next command resets the while loop to the next line
while ($line = <FILE>)
{
# Discard blank lines
if ($line =~ /^\s*#/ )
{ next; }
# Discard comment line
elsif ($line=~/^#/)
{ next; }
# Discard fasta header line
elsif($line =~ /^>/ )
{ next; }
# Keep concatenating to $sequence string
else
{ $sequence .= $line; }
}
$sequence =~ s/\s//g ;
close FILE;
for ($i=0; $i < (length ($sequence) - 2) ; $i += 3)
{
# From the string '$sequence' at position '$i' extract 3 characters & store it in '$codon'
$codon = (substr($sequence,$i,3));
# Converting any lower case characters to upper case
$CODON = uc $codon;
# Checking for the existence of CODON in the hash %genetic_code
if(exists $genetic_code{$CODON})
# The corresponding amino acid in the hash is stored in $protein
{ $protein .= $genetic_code{$CODON}; }
else
{ die "Bad codon !! \n\n";}
}
print "The translated protein sequence is : $protein \n\n";