#!/usr/bin/perl
 
###########################
#### The Central Dogma ####
###########################
 
### Genome
$DNA_seq = "CATTACGATGCATTGATTTTTCAAAGGAATGTACTATCGAAATCACAAGTCGTGGACTACGGTTTGCAGTGGAGGAATCGCAGTCTTTGCAGGCTCACGCCTTTCTTGATAAGTCGTTGTTTCAAACGTTTAATTTTCAGGGTGATTCAGATGGGGATACATATATGTTCCAGACGATGATTTCACCT";
 
### Transcription

## Here you want to convert the DNA sequence to the equivalent RNA sequence,
## in a variable called '$RNA_seq'.  Do this by first copying the value of one
## into the other, then using perl's regular expression for substitution.
## For example, if you wanted to copy the value of $DNA_seq into a variable
## named '$a', you'd write the following:
##   $a = $DNA_seq;
## The substitution regular expression looks like:
##   $a =~ s/1/2/g;
## This example would change all occurences of '1' to '2' in $a.

## Print your results to output using the following (uncommented) line:
#print "$RNA_seq\n";
 
### Translation

## Here you need to translate your RNA sequence into a protein sequence
## in three different reading frames.  Use the subroutine provided at the
## bottom ('translate_codon') as follows:
##   print translate_codon($codon);
## You can do this by setting an offset (0, 1, or 2), then using perl's
## 'substr' function to take off three-nucleotide chunks of sequence.
## These 3-mers are the '$codon' that you'll use for the translate_codon
## subroutine.


### Now take the reverse-complement of the sequence

## First you want to change your sequence to the opposite order (hint: check
## out perl's 'reverse' function).  Save your results into a variable called
## '$reversed'.

## Print your results with the following (uncommented) line:
# print $reversed;

## Next change each nucleotide to its complement.  A good way to
## do this uses perl's 'tr' function.

## Print your results with the following (uncommented) line:
# print $reversed;

### Translation

## Once again, translate your RNA sequence into a protein sequence
## in three different reading frames, and print the results to output.  The
## code for this can be an exact copy of your code from earlier.


############################### Subroutines ##############################

sub translate_codon {
      if ($_[0] =~ /GC./i) {return Ala;} 
      if ($_[0] =~ /UGC|UGU/i) {return Cys;} 
      if ($_[0] =~ /GAC|GAU/i) {return Asp;}
      if ($_[0] =~ /GAA|GAG/i) {return Glu;}
      if ($_[0] =~ /UUC|UUU/i) {return Phe;}
      if ($_[0] =~ /GG./i) {return Gly;}
      if ($_[0] =~ /CAC|CAU/i) {return His;}
      if ($_[0] =~ /AUA|AUC|AUU/i) {return Ile;}
      if ($_[0] =~ /AAA|AAG/i) {return Lys;}
      if ($_[0] =~ /UUA|UUG|CU./i) {return Leu;}
      if ($_[0] =~ /AUG/i) {return Met;}
      if ($_[0] =~ /AAC|AAU/i) {return Asn;}
      if ($_[0] =~ /CC./i) {return Pro;}
      if ($_[0] =~ /CAA|CAG/i) {return Gln;}
      if ($_[0] =~ /AGA|AGG|CG./i) {return Arg;}
      if ($_[0] =~ /AGC|AGU|UC./i) {return Ser;}
      if ($_[0] =~ /AC./i) {return Thr;}
      if ($_[0] =~ /GU./i) {return Val;}
      if ($_[0] =~ /UGG/i) {return Trp;}
      if ($_[0] =~ /UAC|UAU/i) {return Tyr;}
      if ($_[0] =~ /UAA|UGA|UAG/i) {return "***";}
}
