snpgdsGetGeno {SNPRelate} | R Documentation |
To get a genotype matrix from a specified GDS file
snpgdsGetGeno(gdsobj, sample.id=NULL, snp.id=NULL, snpfirstdim=NA, .snpread=NA, with.id=FALSE, verbose=TRUE)
gdsobj |
an object of class |
sample.id |
a vector of sample id specifying selected samples; if NULL, all samples are used |
snp.id |
a vector of snp id specifying selected SNPs; if NULL, all SNPs are used |
snpfirstdim |
if |
.snpread |
internal use |
with.id |
if |
verbose |
if TRUE, show information |
The function returns an integer matrix with values 0, 1, 2 or NA
representing the number of reference allele when with.id=FALSE
;
or list(genotype, sample.id, snp.id)
when with.id=TRUE
. The
orders of sample and SNP IDs in the genotype matrix are actually consistent
with sample.id
and snp.id
in the GDS file, which may not be
as the same as the arguments sampel.id
and snp.id
specified
by users.
Xiuwen Zheng
# open an example dataset (HapMap) genofile <- snpgdsOpen(snpgdsExampleFileName()) set.seed(1000) snpset <- sample(read.gdsn(index.gdsn(genofile, "snp.id")), 1000) mat1 <- snpgdsGetGeno(genofile, snp.id=snpset, snpfirstdim=TRUE) dim(mat1) # 1000 279 table(c(mat1), exclude=NULL) mat2 <- snpgdsGetGeno(genofile, snp.id=snpset, snpfirstdim=FALSE) dim(mat2) # 279 1000 table(c(mat2), exclude=NULL) identical(t(mat1), mat2) # TRUE # close the file snpgdsClose(genofile)