In class Programming Exercises: Functions and Files

  1. Write a program that has a subroutine that takes a list of numbers and returns their sum. The subroutine should be capable of dealing with any length of list.
  2. Using the subroutine from the previous problem, write a program to add all the numbers between 10 and 5000.
  3. Write a program that prompts the user for the name of a peptide. If the peptide is one of the files in /home/bios546 (they all end in .pep), then open the file and print the contents. If there is no file by that name, print an error message. To clarify this a bit: the user is just supposed to enter something like "at1g31470", and your program is supposed to concatenate "/home/bios546/" on one end and ".pep" on the other hand. Then try to open the peptide file, and if it can't be opened, the program should die with an appropriate error message. This program needs a line something like "open INFILE, "$filename" or die "no such file exists\n";
  4. Write a program that splits a DNA sequence into 3 base segments (codons) and translates them with the translation subroutine you wrote in a previous exercise. The subroutine should translate a single codon into an amino acid: your main program should invoke the subroutine once for each codon. Use substr in a while loop to split the sequence into codons. Also, have an option to change the reading frame (options 0, 1, or 2), by changing the initial start position of substr.
    The file /home/bios546/at1g02010.cds consists of 2 lines: the first is a comment line, containing identifying information. Just skip past it. The second line contains the entire sequence: it is very long and word-wrapped, but it contains nothing other than ACGT except the last character, which is \n.