# loading library and example data
library(h5vc)
tallyFile <- system.file( "extdata", "example.tally.hfs5", package = "h5vcData" )
sampleData <- getSampleData( tallyFile, "/ExampleStudy/16" )
# check the available samples and sampleData
print(sampleData)
data <- h5dapply( #extracting coverage using h5dapply
filename = tallyFile,
group = "/ExampleStudy/16",
blocksize = 1000,
FUN = function(x) rowSums(x$Coverages),
names = c( "Coverages" ),
range = c(29000000,29010000),
verbose = TRUE
)
coverages <- do.call( rbind, data )
colnames(coverages) <- sampleData$Sample[order(sampleData$Column)]
coverages
#Subsetting by Sample
sampleData <- sampleData[sampleData$Patient == "Patient5",]
data <- h5dapply( #extracting coverage using h5dapply
filename = tallyFile,
group = "/ExampleStudy/16",
blocksize = 1000,
FUN = function(x) rowSums(x$Coverages),
names = c( "Coverages" ),
range = c(29000000,29010000),
samples = sampleData$Sample,
verbose = TRUE
)
coverages <- do.call( rbind, data )
colnames(coverages) <- sampleData$Sample[order(sampleData$Column)]
coverages
#Using GRanges and IRanges
library(GenomicRanges)
library(IRanges)
granges <- GRanges(
c(rep("16", 10), rep("22", 10)),
ranges = IRanges(
start = c(seq(29000000,29009000, 1000), seq(39000000,39009000, 1000)),
width = 1000
))
data <- h5dapply( #extracting coverage using h5dapply
filename = tallyFile,
group = "/ExampleStudy",
blocksize = 1000,
FUN = function(x) rowSums(x$Coverages),
names = c( "Coverages" ),
range = granges,
verbose = TRUE
)
lapply( data, function(x) do.call(rbind, x) )
Run the code above in your browser using DataLab