test2f09

test2f09 - CompSci 6 PROBLEM 1 : Test 2 (Blasting out DNA...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CompSci 6 Test 2 Fall 2009 PROBLEM 1 : ( Blasting out DNA (24 points) ) In this problem, we use a single strand of DNA to generate fragments of DNA. A DNA strand is made up of the nucleotides A, C, G and T. For example, a DNA strand might be ”CGTA”. Each symbol has a complement. A and T are complements of each other, and C and G are complements of each other. The complement of ”CGTA” is the complement of each symbol, resulting in ”GCAT”. We want to generate DNA fragments from a DNA strand and a reactant (one of the four nucleotides). A DNA fragment is generated by generating a string of complements, stopping randomly at the chosen reactant. For example, suppose the DNA strand is ”CGATACTCTGT” and the reactant is ”A”. Shown below are four copies of this DNA strand on the first line with the four possible fragments below it. Each symbol in the fragment is the complement of the corresponding symbol directly above it and each fragment has to end in the reactant A. CGATACTCTGT CGATACTCTGT CGATACTCTGT CGATACTCTGT GCTA GCTATGA GCTATGAGA GCTATGAGACA In this problem, given a DNA strand and a reactant we will randomly generate an array of possible fragments. We will write this in three parts. First we give you the method complement which given a string of one letter (C,G,T or A) gives you the complement letter. You may want to use this method. public String complement(String str) { if (str.equals("A")) return "T"; if (str.equals("T")) return "A"; if (str.equals("C")) return "G"; return "C"; } PART A. (8) Complete the method findPositionOfAllOccurences which has two String parameters: dna is a string of nucleotides and nuc is one nucleotide. This method returns an ArrayList of the positions of nuc in dna. For example, if dna is AGCATA and nuc is A, then return the ArrayList of integers 0, 3, 5, which are the positions of the A in the dna strand. public ArrayList<Integer> findPositionOfAllOccurences(String dna, String nuc) { 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
PART B. (8) Complete the method createOneFragment that is given a dna String and a position in the String and returns one fragment that ends at that position. The fragment is created by generating a new String in which each character is the complement of the character in the dna String. The fragment may be shorter then the dna String as it must stop at the lastposition parameter. For example, suppose the dna string is ”CGTAG” and the last position is 2, then the fragment returned is ”GCA”, since GCA is the complement of CGT and the fragment ends at position 2. public String createOneFragment (String dna, int lastPosition)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

test2f09 - CompSci 6 PROBLEM 1 : Test 2 (Blasting out DNA...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online