Last active
August 29, 2015 14:18
-
-
Save grimbough/ca9e668a5772dc00cafb to your computer and use it in GitHub Desktop.
Examining memory usage in ShortReadQ class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ShortRead) | |
## create a single string with the number of characters defined by 'length' | |
## and the letter sampled from 'alphabet' | |
generateString <- function(length = 50, alphabet = c("A","C","G","T") ) { | |
paste0(sample(alphabet, size = length, replace = TRUE), collapse = "") | |
} | |
## create a ShortReadQ object containing 'nreads' reads, each of which has length 'length' | |
createFastq <- function(nreads, length) { | |
sread <- DNAStringSet( sapply(rep(length, nreads), generateString, alphabet = c("A","C","G","T") )) | |
qual <- FastqQuality( sapply(rep(length, nreads), generateString, alphabet = alphabet( FastqQuality() ))) | |
id <- BStringSet(paste0("Read_", 1:nreads)) | |
fq <- ShortReadQ(sread = sread, qual = qual, id = id) | |
return(fq) | |
} | |
## create 3 ShortReadQ objects - 500 reads, 50,000 reads and extract the | |
## first 500 reads from the larger object | |
fq1 <- createFastq(nreads = 500, length = 200) | |
fq2 <- createFastq(nreads = 50000, length = 200) | |
fq3 <- fq2[1:500,] | |
## print memory usage | |
print(object.size(fq1), units = "auto") ## 229.3 Kb | |
print(object.size(fq2), units = "auto") ## 21.3 Mb | |
print(object.size(fq3), units = "auto") ## 19.6 Mb | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment