-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTranslate.pm
executable file
·47 lines (43 loc) · 1.04 KB
/
Translate.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
##############################################################################
# PACKAGE NAME: Translate.pm
# DESCRIPTION: AA translation from nucleotide sequence
#
# DATE WRITTEN: 2007-01-12
# WRITTEN BY: Martin J. Maiers
##############################################################################
package Translate;
use strict; # always
use warnings; # or else
my $init=0;
my %tran;
sub initialize {
$init=1;
my $translate_dir = ".";
my $prot="$translate_dir/protein.db";
open(PROTEIN, $prot) or die "can't open $prot for reading";
while(<PROTEIN>) {
chomp;
next if /^#/; #comments
my ($aa,$aa_3,$aa_name,$na_list) = split /:/;
my(@na) = split (/,/, $na_list);
foreach my $n (@na) {
$tran{$n}=$aa;
}
}
}
sub translate {
my ($seq) = shift;
my $ret = "";
initialize() unless $init;
my $length = length $seq;
for(my $i=0; $i<$length; $i+=3) {
my $codon = substr($seq,$i, 3);
if (defined $tran{$codon}) {
$ret.=$tran{$codon};
} else {
$ret.="*";
}
}
return $ret;
}
1;