1 / 10

BIO503: Tutorial 2 Solutions E.coli Genome

BIO503: Tutorial 2 Solutions E.coli Genome. Harvard School of Public Health Wintersession 2009. 1A. Getting the Data into R. For strange file extensions, it's a great idea to take a look at the file first (e.g. open in Notepad). The sequence data is in a non-rectangular format.

armani
Télécharger la présentation

BIO503: Tutorial 2 Solutions E.coli Genome

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. BIO503: Tutorial 2 SolutionsE.coli Genome Harvard School of Public Health Wintersession 2009

  2. 1A. Getting the Data into R For strange file extensions, it's a great idea to take a look at the file first (e.g. open in Notepad). The sequence data is in a non-rectangular format. This suggests we should use the function scan (read.table will not work). Make sure you're in the same working directory as where the .fna file located. Alternatively you can specify the full path of where this file lives. > genome <- scan("U00096.fna", what="txt") Take a look at what genome is: > genome[1:10]

  3. 1A. Fixing up the Data Ideally we only want to work with the sequence data, so we can strip the data of unnecessary information. > genome <- genome[-(1:9)] We could also have read the data in and skipped the first line: > genome <- scan("U00096.fna", skip=1, what="txt")

  4. 1A. Counting the number of bases To count the number of bases, there are at least 2 ways to do it: Method #1: Using the nchar function We count the number of bases in each line of the file separately using nchar > line.count <- nchar(genome) Now we have a vector of 66282 counts corresponding to the 66282 lines of the file. To get the total number of bases in the entire genome: > total.base <- sum(line.count)

  5. 1A. Counting the number of bases Method #2: Using the strsplit function For each line of the file, we can split the contiguous string into individual bases. The big picture for this code will be to have each base stored as a value in a vector. Then we can find the length of the vector to get the total number of bases in the genome. > g.split <- strsplit(genome, "") > class(g.split) > length(g.split) g.split is a list object with 66282 components, each corresponding to the 66282 lines of the file.

  6. 1A. Counting the number of bases Method #2[continued]: Each individual component is a vector with bases stored as individual elements. To get the total number of bases in the entire genome, first make g.split into a vector object: > g.vec <- unlist(g.split) > total.base <- length(g.vec)

  7. 1B. How many Cs are in the Genome? We can take the output from g.vec: > c.logical <- g.vec == "C" > c.count <- sum(c.logical)

  8. 1C. Write a Function Imagine an input string DNA <- "ACTGA" For C: > g.split <- strsplit(DNA, "") > g.vec <- unlist(g.split) > c.logical <- g.vec == "C" To generalize this for other bases, say base > base <- "C" > base.logical <- g.vec == base

  9. 1C. Write a Function To formalize this as a function: countBase <- function(DNAstring, base="C"){ g.split <- strsplit(DNAstring, "") g.vec <- unlist(g.split) base.logical <- g.vec == base count.base <- sum(base.logical) return(count.base) } To use: > countBase(genome[1], "G") By default, countBase will count the number of Cs in the input string. > countBase(genome[1], "C")

  10. 1D. Calculate the GC content We currently have genome as a vector which stores the whole sequence broken up by lines. Let's collapse this down into one long string. Then use our function countBase to calculate the GC content. > genome.one <- paste(genome, collapse="", sep="") > total.base <- nchar(genome.one) > c.count <- countBase(genome.one) > g.count <- countBase(genome.one, "G") > gc <- (c.count + g.count)/total.base Answer: 0.507897

More Related