GWASTools (version 1.18.0)

SnpAnnotationDataFrame: Class SnpAnotationDataFrame

Description

The SnpAnnotationDataFrame class stores annotation data associated with SNPs, as well as metadata describing each column. It extends the AnnotatedDataFrame class.

Arguments

Constructor

SnpAnnotationDataFrame(data, metadata): data must be a data.frame containing the SNP annotation. It must contain at least the following columns:
  • "snpID": integer vector containing unique SNP ids.
  • "chromosome": integer vector containing chromosome codes.
  • "position": integer vector containing position (in base pairs) on the chromosome.
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. metadata is an optional data.frame containing a description for each column in data. It should contain a column "labelDescription", with row.names(metadata) == names(data). The SnpAnnotationDataFrame constructor creates and returns a SnpAnnotationDataFrame instance.

Accessors

In the code snippets below, object is a SnpAnnotationDataFrame object.
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.
getVariable(object, varname, index): A vector of the column varname. The optional index is a logical or integer vector specifying elements to extract. If varname is itself a vector, returns a data.frame. Returns NULL if varname is not found in object.
hasVariable(object, varname): Returns TRUE if varname is a column in object, FALSE if not.
getVariableNames(object): Returns a character vector with the names of all columns in object.
getAnnotation(object): Returns all annotation variables as a data frame.
getMetadata(object): Returns metadata describing the annotation variables as a data frame.
Inherited methods from AnnotatedDataFrame:
varLabels(object): Returns a character vector with the names of all columns in object.
pData(object): Returns all annotation variables as a data frame, or sets the annotation variables with pData(object) <- df.
varMetadata(object): Returns metadata describing the annotation variables as a data frame, or sets the metadata with varMetadata(object) <- df.
The operators [, $, and [[ work just as they do in standard data frames, for both retrieval and assignment.
autosomeCode(object): Returns the integer codes for the autosomes.
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

AnnotatedDataFrame, ScanAnnotationDataFrame, GenotypeData, IntensityData

Examples

Run this code
library(GWASdata)
data(illumina_snp_annot)
snpAnnot <- SnpAnnotationDataFrame(illumina_snp_annot)

# list columns
varLabels(snpAnnot)

# add metadata
meta <- varMetadata(snpAnnot)
meta["snpID", "labelDescription"] <- "unique integer ID"
varMetadata(snpAnnot) <- meta

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

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

# get rsID
if (hasVariable(snpAnnot, "rsID")) rsID <- getVariable(snpAnnot, "rsID")

# display data
head(pData(snpAnnot))

# standard operators
snpID <- snpAnnot$snpID
chrom <- snpAnnot[["chromosome"]]
subset <- snpAnnot[1:10, 1:5]
snpAnnot$newVar <- rep(1, nrow(snpAnnot))

# replace data
df <- pData(snpAnnot)
pData(snpAnnot) <- df

# PLINK chromosome coding
snpID <- 1:10
chrom <- c(rep(1L,5), 23:27)
pos <- 101:110
df <- data.frame(snpID=snpID, chromosome=chrom, position=pos)
snpAnnot <- SnpAnnotationDataFrame(df, YchromCode=24L, XYchromCode=25L)
getChromosome(snpAnnot, char=TRUE)

Run the code above in your browser using DataLab