Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.99 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. #
  3. # Claudia Gahleitner 0556004
  4. #
  5. # Exercise 5
  6.  
  7. use strict;
  8. use warnings;
  9.  
  10. if ($#ARGV != 1)
  11. {
  12.         die ("USAGE: ex5.pl input.txt output.txt\n");
  13. }
  14.  
  15. my $idx = 0;
  16. my $input = $ARGV[$idx++];
  17. my $output = $ARGV[$idx++];
  18.  
  19. open(INFO,   "<  $input")    || die("kann coding.fa nicht öffnen: $!");
  20. open(OUTFILE, "> $output") or die "Kann output.txt nicht öffnen: $!";
  21.  
  22. my @coding = <INFO>;
  23. my $i;
  24. my $j;
  25. my @newcoding;
  26.  
  27. chomp @coding;
  28. foreach $i (@coding)
  29. {
  30.     if ($i =~ /^[A|G|C|T]+$/i)
  31.     {
  32.         push (@newcoding,$i);
  33.     }
  34.     elsif ($i =~ /^>(.+)/ && @newcoding)
  35.     {
  36.         my $mrna = transcript(@newcoding);
  37.         my @protein = translate($mrna);
  38.         print "$1: @protein\n";
  39.         @newcoding = [];
  40.     }
  41. }
  42.  
  43.  
  44. my $mrna = transcript(@newcoding);
  45. #print "mrna: $mrna\n";
  46.  
  47. my @protein = translate($mrna);
  48.  
  49. sub transcript
  50. {
  51.     my @temp;
  52.  foreach $i (@_)
  53.  {
  54.   $i =~ s/T/U/g;
  55.   push (@temp,$i);
  56.  }
  57.  return reverse(join("", @temp));
  58. }
  59.  
  60.  
  61. sub translate
  62. {
  63.  my $mrna = pop(@_);
  64.  
  65. # print "now: $mrna\n";
  66.  
  67.  my %codonTable =  # associates base-triplets to the amino-acids they encode
  68.  (
  69.     "CUU" => "Leu", "CUC" => "Leu", "CUA" => "Leu", "CUG" => "Leu", "UUA" => "Leu", "UUG" => "Leu",
  70.         "UCU" => "Ser", "UCC" => "Ser", "UCA" => "Ser", "UCG" => "Ser", "AGU" => "Ser", "AGC" => "Ser",
  71.         "CGU" => "Arg", "CGC" => "Arg", "CGA" => "Arg", "CGG" => "Arg", "AGA" => "Arg", "AGG" => "Arg",
  72.         "GGU" => "Gly", "GGC" => "Gly", "GGA" => "Gly", "GGG" => "Gly",
  73.         "GCU" => "Ala", "GCC" => "Ala", "GCA" => "Ala", "GCG" => "Ala",
  74.         "GUU" => "Val", "GUC" => "Val", "GUA" => "Val", "GUG" => "Val",
  75.         "ACU" => "Thr", "ACC" => "Thr", "ACA" => "Thr", "ACG" => "Thr",
  76.         "CCU" => "Pro", "CCC" => "Pro", "CCA" => "Pro", "CCG" => "Pro",
  77.         "AUU" => "Ile", "AUC" => "Ile", "AUA" => "Ile",
  78.         "UAU" => "Tyr", "UAC" => "Tyr",
  79.         "UUU" => "Phe", "UUC" => "Phe",
  80.         "UGU" => "Cys", "UGC" => "Cys",
  81.         "AAU" => "Asn", "AAC" => "Asn",
  82.         "GAU" => "Asp", "GAC" => "Asp",
  83.         "CAA" => "Gln", "CAG" => "Gln",
  84.         "GAA" => "Glu", "GAG" => "Glu",
  85.         "CAU" => "His", "CAC" => "His",
  86.         "AAA" => "Lys", "AAG" => "Lys",
  87.         "AUG" => "Met",
  88.         "UGG" => "Trp",
  89.         "UAA" => "___", "UAG" => "___", "UGA" => "___",
  90.         );
  91.  
  92.  #  every protein starts with Methinin (AUG)
  93.  my $start = index($mrna, "AUG");
  94.  if ($start == -1)
  95.  {
  96.      print "$mrna\n";
  97.   die("ERROR: no start-codon found. Bailing out!");
  98.  }
  99.  
  100.  my @protein;
  101.  while (length($mrna) > 3)
  102.  {
  103.   my $codon = substr($mrna, $start, 3);
  104.   $mrna = substr($mrna, 3);
  105.  
  106.   if (!exists($codonTable{$codon}))
  107.   {
  108.    die ("ERROR: $codon does not encode a valid amino acid. Bailing out!");
  109.   }
  110.  
  111.   my $amino = $codonTable{$codon};
  112.   if (length($codon) < 3 || !$amino)
  113.    {
  114.    die("ERROR: no stop-codon found.");
  115.    }
  116.   elsif ($amino eq "___") # we hit a stop-codon
  117.    {
  118.    last;
  119.    }
  120.   {
  121.   push(@protein, $amino);
  122.   }
  123.  }
  124.  return @protein;
  125. }
  126.  
  127. close(INFO);
  128. close(OUTFILE);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement