Concept
How can programs analyze DNA n-gram frequencies and subsequence occurrences?
ComputerScienceOne / Exercises
"Exercise 9.11. A DNA sequence is a sequence of some combination of the characters A (adenine), C (cytosine), G (guanine), and T (thymine) which correspond to the four nucleobases that make up DNA. Given a long DNA sequence, its often useful to compute the frequency of n-grams . An n -gram is a DNA subsequence of length n . Since there are four bases, there are 4 n possible n -grams. Write a program that processes a DNA sequence from a plaintext file and, given n , computes the relative frequency of each n -gram as it appears in the sequence. As an example, consider the sequence in Figure 9.5. GGAAGTAGCAGGCCGCATGCTTGGAGGTAAAGTTCATGGTTCCCTGGCCC Figure 9.5.: A DNA Sequence To compute the frequency of all n = 2 n -grams, we would consider all 16 combinations of length-two DNA sequences. We would then go through the sequence and count up the number of times each 2-gram appears. We then compute the relative frequency (note: if a sequence is length L , then the total number of n -grams in it is L − ( n − 1)). The relative frequency of each such 2-gram is calculated below. AA 6.1224% AC 0.0000% AG 10.2041% AT 4.0816% CA 6.1224% CC 10.2041% CG 2.0408% CT 4.0816% GA 4.0816% GC 10.2041% GG 12.2449% GT 8.1633% TA 4.0816% TC 4.0816% TG 8.1633% TT 6.1224%\n\nExercise 9.12. Given a long DNA sequence, it is often useful to compute the number of instances of a certain subsequence . As an example, if we were to search for the subsequence GT A in the DNA sequence in Figure 9.5, it appears twice. As another example, in the sequence CCCC , the subsequence CC appears three times. Write a program that processes a text file containing a DNA sequence and, given a subequence s , searches the DNA sequence and counts the number of times s appears.\n\nExercise 9.13. Protein sequencing in an organism consists of a two step process. First the DNA is translated into RNA by replacing each thymine (T) nucleotide with uracil (U). Then, the RNA sequence is translated into a protein according to the following rules. The RNA sequence is processed 3 bases at a time. Each trigram is translated into a single amino acid according to known encoding rul"
Related Ideas
- How can you compute a substring of a string?ComputerScienceOne · Arrays of Strings
- How can you read a text file one line at a time?ComputerScienceOne · Binary Files
- How can a Scanner read input from a file?ComputerScienceOne · File Input
- How can file input/output programs process text, binary data, and word searches?ComputerScienceOne · Exercises
- How do fprintf() and fscanf() read from and write to plaintext files?ComputerScienceOne · Plaintext Files
- How are files read, written, and properly managed?ComputerScienceOne · Paths
- What is 22?ComputerScienceOne · Opening Files
- How do file names, extensions, and working directories affect file paths?ComputerScienceOne · Paths