# the file of GDS
gds.fn <- seqExampleFileName("gds")
# or gds.fn <- "C:/YourFolder/Your_GDS_File.gds"
# display
(f <- seqOpen(gds.fn))
# get 'sample.id
(samp.id <- seqGetData(f, "sample.id"))
# "NA06984" "NA06985" "NA06986" ...
# get 'variant.id'
head(variant.id <- seqGetData(f, "variant.id"))
# set sample and variant filters
set.seed(100)
seqSetFilter(f, sample.id=samp.id[seq(2, 16, 2)],
variant.id=sample(variant.id, 10))
# apply a function via a sliding window over variants
seqSlidingWindow(f, c(qual="annotation/id"), win.size=3,
FUN = function(x) {
# x is a list with 'win.size' elements
print(x)
}, as.is="none")
# apply a function via a sliding window over variants
seqSlidingWindow(f, c(qual="annotation/id"), win.size=3,
FUN = function(x) {
cat(unlist(x), sep="\t"); cat("\n")
}, as.is="none")
# apply a function via a sliding window over variants
seqSlidingWindow(f, c(geno="genotype", phase="phase", qual="annotation/id"),
FUN = function(index, x) {
cat("Window ", index, ":\n", sep="")
print(x)
},
win.size=3, as.is="none", var.index="relative")
# apply a function via a sliding window over variants
seqSlidingWindow(f, "genotype", win.size=4,
FUN = function(index, x) {
z <- unlist(lapply(x, function(z) mean(z, na.rm=TRUE)))
cat("Window ", index, ", starting from Variant ", index,
"\n ", format(round(z,3), nsmall=3, width=8), "\n", sep="")
},
as.is="none", var.index="relative")
# close the GDS file
seqClose(f)
Run the code above in your browser using DataLab