## create a toy example
A <- matrix(rbinom(50, 2, prob=0.2), 5, 10)
sA <- as(A, "dgCMatrix")
pos <- sort(sample(1:10000, ncol(A)))
seqname <- "chr1"
## variant with 'GRanges' object
gr <- GRanges(seqnames=seqname, ranges=IRanges(start=pos, width=1))
gtm <- genotypeMatrix(A, gr)
gtm
as.matrix(gtm)
variantInfo(gtm)
MAF(gtm)
## variant with 'pos' and 'seqnames' object
genotypeMatrix(sA, pos, seqname)
## variant with 'seqname:pos' strings passed through 'pos' argument
spos <- paste(seqname, pos, sep=":")
spos
genotypeMatrix(sA, spos)
## read data from VCF file using 'readVcf()' from the 'VariantAnnotation'
## package
if (require(VariantAnnotation))
{
vcfFile <- system.file("examples/example1.vcf.gz", package="podkat")
sp <- ScanVcfParam(info=NA, genome="GT", fixed=c("ALT", "FILTER"))
vcf <- readVcf(vcfFile, genome="hgA", param=sp)
rowRanges(vcf)
## call constructor for 'VCF' object
gtm <- genotypeMatrix(vcf)
gtm
variantInfo(gtm)
## alternatively, extract information from 'VCF' object and use
## variant with character matrix and 'GRanges' positions
## note that, in 'VCF' objects, rows correspond to variants and
## columns correspond to samples, therefore, we have to transpose the
## genotype
gt <- t(geno(vcf)$GT)
gt[1:5, 1:5]
gr <- rowRanges(vcf)
gtm <- genotypeMatrix(gt, gr)
as.matrix(gtm[1:20, 1:5, recomputeMAF=TRUE])
}
Run the code above in your browser using DataLab