posted Monday 2 May 2016
due Monday 9 May 2016 at midnight
Submission policy: Report all plots and your code in this iPython notebook. Print your notebook as a PDF and attach it to the rest of your assignment. Turn in your assignment on the 2nd floor of Packard in the EE372 bin next to the kitchen area.
Question I: Lander-Waterman and repeat statistics
In Question III of the last problem set, you aligned reads from an E. coli sequencing experiment to the E. coli genome using Bowtie, obtaining 617036 aligned reads (out of 644022 total reads). Download the set of aligned reads here (the alignments are saved as a *.bam file). You can view the first 15 lines of the file using the command
samtools view E.coli.alignments.EE372.bam | head -15. Samtools is installed on Stanford’s Corn server.
- Refer to the documentation for the *.sam file format here. Convert the *.bam file to a *.sam file using the
samtools viewcommand. What position does the first read align to?
- The length of the E. coli genome is 4639675. Write a function to compute the proportion of the genome by covered by the reads in a given *.sam file. What proportion of the genome is covered by the reads in E.coli.alignments.EE372.bam?
- Subsample the *.sam file using the
samtools view -scommand. You should generate a new *.sam file for each subsampling. Using the function you wrote above, plot the proportion of the genome covered as a function of , the proportion of reads kept. Interpret what you see (1-2 sentences).
- Compute the triple repeat and interleaved statistics of the E. coli genome (available here). Report the number of triple and interleaved repeats of length more than 200. Consider only the forward strand of the reference. Hint: Use the software MUMmer, which is also installed on Corn. The
repeat-matchcommand might be helpful.
You may also use pysam for this problem.
Question II: de Bruijn graph assembly
Give the 5-mer spectrum of TAAAAACCCCAAAAAG. How many different assemblies are consistent with the 5-mer spectrum?
The support of a -mer spectrum is the -mer spectrum with the value of all non-zero -mers set to 1. Give the assembly of TAAAAACCCCAAAAAG from the support of its 5-mer spectrum. How many different assemblies are consistent with the support of this 5-mer spectrum?
Study the implementation of the de Bruijn graph assembler by Ben Langmead here. You should copy and paste the code from the top cell into your notebook as you will use a tweak of this class to perform assembly. (You will need to make sure that the assembly is done using the k-mers of non-zero support. That is, even if a k-mer is seen twice one would add only an edge between the k-1 mers.) Note that you will need to pass a list of reads (strings) as the
strIterargument when initializing an instance of the class (see
__iter___). You can use the
eulerianWalkOrCyclemethod to obtain a list of -mers corresponding to an Eulerian walk through the graph. Write a function that obtains the assembly from this list of -mers (i.e. if the list is [‘ABCD’,’BCDE’] with , then your function should return ‘ABCDE’).
Write a function to generate random reads. The input should be the number of reads generated and the length of each read generated. The output should be random length- sequences of nucleotides. Generate a random length-100 genome.
Write a function to sample reads from a genome. The input should be the genome, the number of reads generated , and the length of each read generated. Assuming that , how many reads do you need to achieve a coverage depth of 30? Generate this number of reads and give the assembly using your code from part 3.
Write a modified version of the previous function for sampling reads from a genome with error. Generate random length-10 reads with 5% error rate and a coverage of 30. Give the assembly using your code for part 3. What do you observe? You may want to rerun your code for 4-6 to make sure your observations are consistent.
Question III: Alignment of random strings
Write a function that computes the edit distance between two strings using dynamic programming. You can use standard libraries such as editdistance to check the correctness of your function. The input should be two strings each of at least length 2. The output should be a float representing the edit distance between the two input strings.
How can you use the above function to perform alignment between two reads? If you have total reads each of length , what is the runtime of this approach in terms of and ?
For , generate two reads of length and compute their edit distance. Average your result over 100 runs to obtain an estimate of the average edit distance of two randomly generated reads of length . Repeat for . Plot as a function of with error bars. Do you observed any trends? What can you say about how well random strings align? (2-3 sentences).