my %genetic_code = (
'TCA' => 'S', 'TCC' => 'S', 'TCG' => 'S', 'TCT' => 'S',
'TTC' => 'F', 'TTT' => 'F', 'TTA' => 'L', 'TTG' => 'L',
'TAC' => 'Y', 'TAT' => 'Y', 'TAA' => '_', 'TAG' => '_',
'TGC' => 'C', 'TGT' => 'C', 'TGA' => '_', 'TGG' => 'W',
'CTA' => 'L', 'CTC' => 'L', 'CTG' => 'L', 'CTT' => 'L',
'CCA' => 'P', 'CCC' => 'P', 'CCG' => 'P', 'CCT' => 'P',
'CAC' => 'H', 'CAT' => 'H', 'CAA' => 'Q', 'CAG' => 'Q',
'CGA' => 'R', 'CGC' => 'R', 'CGG' => 'R', 'CGT' => 'R',
'ATA' => 'I', 'ATC' => 'I', 'ATT' => 'I', 'ATG' => 'M',
'ACA' => 'T', 'ACC' => 'T', 'ACG' => 'T', 'ACT' => 'T',
'AAC' => 'N', 'AAT' => 'N', 'AAA' => 'K', 'AAG' => 'K',
'AGC' => 'S', 'AGT' => 'S', 'AGA' => 'R', 'AGG' => 'R',
'GTA' => 'V', 'GTC' => 'V', 'GTG' => 'V', 'GTT' => 'V',
'GCA' => 'A', 'GCC' => 'A', 'GCG' => 'A', 'GCT' => 'A',
'GAC' => 'D', 'GAT' => 'D', 'GAA' => 'E', 'GAG' => 'E',
'GGA' => 'G', 'GGC' => 'G', 'GGG' => 'G', 'GGT' => 'G',
);

sub codon2aa {
	my ( $codon ) = @_;

	# check does mapping for codon exists
	if ( exists $genetic_code{ $codon } ) {
		# if it does, return amino acid
		return $genetic_code{ $codon };
	} else {
		# if it doesn't exit with error
		die "bad codon: $codon";
	}
}

sub DNA2protein {
	my ( $DNA, $offset ) = @_;
	my $protein = '';

	# start at $offset and move by three places through DNA
	for ( my $i=$offset; $i<=(length($DNA)-2-$offset); $i+=3 ) {
		# extract single codon starting at position $i
		my $codon = substr( $DNA, $i, 3 );
		# # decode codon to amino acid
		$protein .= codon2aa( $codon );
	}
	# return created protein
	return $protein;
}

sub revcom {
	my ( $DNA ) = @_;
	my $revcom = reverse $DNA;
	$revcom =~ tr/ACGT/TGCA/;
	return $revcom;
}
