Homework #2
Due Thursday, January 22, 2009, at the beginning of class. Assignments turned in more than 5 minutes after the beginning of class will be penalized 10 points, with an additional 10 points every 24 hours thereafter.
The first four questions pertain to the following DP matrix:
(10 points) Write down all maximal scoring alignments for the dynamic programming matrix shown above.
(3 points) Was this DP matrix generated by the Smith-Waterman or Needleman-Wunsch algorithm? How do you know?
(3 points) For this DP matrix, is the gap penalty linear or affine? Give the value(s).
(10 points) Draw an empty amino acid substitution matrix, and fill in as many values as you can, based on the above DP matrix.
(15 points) Use the BLOSUM62 matrix (found at ftp://ftp.ncbi.nih.gov/blast/matrices/BLOSUM62) and a gap penalty of -4 to find the optimal local alignment of
VKR
andLQCTAS
. Show your work.(10 points) Write a program
copy-file.py
that copies a given file. For example, if you have a file calledhello.txt
that contains one line ("Hello, world!"), then you could create a copy of this file calledworld.txt
as follows:> python copy-file.py hello.txt world.txt > cat world.txt Hello, world!(10 points) Write a program
reverse-lines.py
that reads in the contents of a file, and prints out the lines in reverse order. For example, say that your file is calledthree-lines.txt
and consists of these three lines:This is the first line. This is the second line. This is the third line.Your program should do this:
> python reverse-lines.py three-lines.txt This is the third line. This is the second line. This is the first line.(12 points) Write a program
split-number.py
that reads a real number from the command line and prints its integer part on one line, followed by its decimal part (i.e., the digits after the decimal point) on a second line. For the decimal part, print no more than 6 digits after the decimal, but do not print trailing zeroes.> python split-number.py 1.234567 1 0.234567 > python split-number.py 1.23456711 1 0.234567 > python split-number.py 1.23 1 0.23(12 points) Write a program
format-number.py
that takes as input two arguments: a number and a format, where the format is eitherinteger
,real
orscientific
. Print the given number in the requested format, and print an error if an invalid format string is provided.> python format-number.py 3.14159 integer 3 > python format-number.py 3.14159 real 3.14159 > python format-number.py 3.14159 scientific 3.141590e+00 > python format-number.py 3.14159 foo Invalid format: foo(15 points) Write a program called
day-of-year.py
that takes as input a month and a day and returns an integer less than or equal to 365 indicating how many days of the year have passed on that date.> python day-of-year.py January 1 1 > python day-of-year.py December 31 365 > python day-of-year.py February 2 33 > python day-of-year.py August 17 229 > python day-of-year.py Agust 17 Error: Agust is not a valid month.You can ignore leap years.