Learn R Programming

GWASTools (version 1.12.2)

GdsGenotypeReader: Class GdsGenotypeReader

Description

The GdsGenotypeReader class is an extension of the GdsReader class specific to reading genotype data stored in GDS files. GDS files with both snp x scan and scan x snp dimensions are supported.

Arguments

Extends

GdsReader

Constructor

GdsGenotypeReader(filename, genotypeDim): filename must be the path to a GDS file or a gds object. The GDS file must contain the following variables:
  • 'snp.id': a unique integer vector of snp ids
  • 'snp.chromosome': integer chromosome codes
  • 'snp.position': integer position values
  • 'sample.id': a unique integer vector of scan ids
  • 'genotype': a matrix of bytes with dimensions ('snp','sample'). The byte values must be the number of A alleles : 2=AA, 1=AB, 0=BB.
The optional variable "snp.allele" stores the A and B alleles in a character vector with format "A/B". Default values for chromosome codes are 1-22=autosome, 23=X, 24=XY, 25=Y, 26=M. The defaults may be changed with the arguments autosomeCode, XchromCode, XYchromCode, YchromCode, and MchromCode. The constructor automatically detects whether the GDS file is in snp x scan or scan x snp order using the dimensions of snp.id and sample.id. In the case of GDS files with equal SNP and scan dimensions, genotypeDim is a required input to the function and can take values "snp,scan" or "scan,snp". The GdsGenotypeReader constructor creates and returns a GdsGenotypeReader instance pointing to this file.

Accessors

In the code snippets below, object is a GdsGenotypeReader object. snp and scan indicate which elements to return along the snp and scan dimensions. They must be integer vectors of the form (start, count), where start is the index of the first data element to read and count is the number of elements to read. A value of '-1' for count indicates that the entire dimension should be read. If snp and/or is scan omitted, the entire variable is read. See GdsReader for additional methods.
nsnp(object): The number of SNPs in the GDS file.
nscan(object): The number of scans in the GDS file.
getSnpID(object, index): A unique integer vector of snp IDs. The optional index is a logical or integer vector specifying elements to extract.
getChromosome(object, index, char=FALSE): A vector of chromosomes. The optional index is a logical or integer vector specifying elements to extract. If char=FALSE (default), returns an integer vector. If char=TRUE, returns a character vector with elements in (1:22,X,XY,Y,M,U). "U" stands for "Unknown" and is the value given to any chromosome code not falling in the other categories.
getPosition(object, index): An integer vector of base pair positions. The optional index is a logical or integer vector specifying elements to extract.
getAlleleA(object, index): A character vector of A alleles. The optional index is a logical or integer vector specifying elements to extract.
getAlleleB(object, index): A character vector of B alleles. The optional index is a logical or integer vector specifying elements to extract.
getScanID(object, index): A unique integer vector of scan IDs. The optional index is a logical or integer vector specifying elements to extract.
getGenotype(object, snp, scan, transpose=FALSE): Extracts genotype values (number of A alleles). The result is a vector or matrix, depending on the number of dimensions in the returned values. Missing values are represented as NA. Genotypes are returned in SNP x scan order if transpose=FALSE, otherwise they are returned in scan x SNP order.
getVariable(object, varname, snp, scan): Extracts the contents of the variable varname. The result is a vector or matrix, depending on the number of dimensions in the returned values. Missing values are represented as NA. If the variable is not found in the GDS file, returns NULL.
XchromCode(object): Returns the integer code for the X chromosome.
XYchromCode(object): Returns the integer code for the pseudoautosomal region.
YchromCode(object): Returns the integer code for the Y chromosome.
MchromCode(object): Returns the integer code for mitochondrial SNPs.

See Also

GdsReader, GenotypeData

Examples

Run this code
file <- system.file("extdata", "illumina_geno.gds", package="GWASdata")
gds <- GdsGenotypeReader(file)

# dimensions
nsnp(gds)
nscan(gds)

# get snpID and chromosome
snpID <- getSnpID(gds)
chrom <- getChromosome(gds)

# get positions only for chromosome 22
pos22 <- getPosition(gds, index=(chrom == 22))

# get all snps for first scan
geno <- getGenotype(gds, snp=c(1,-1), scan=c(1,1))

# starting at snp 100, get 10 snps for the first 5 scans
geno <- getGenotype(gds, snp=c(100,10), scan=c(1,5))

close(gds)

Run the code above in your browser using DataLab