SnpAnnotationSQLite {GWASTools} | R Documentation

## Class SnpAnotationSQLite

### Description

The SnpAnnotationSQLite class stores annotation data associated with SNPs, as well as metadata describing each column, in an SQLite database.

### Constructor

  `SnpAnnotationSQLite(dbpath)`:

  `dbpath` is the path to a SQLite database with tables "Annotation" and "Metadata." "Annotation" 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" must contain at least the following columns:

  - "varname": name of variable in annotation

  - "description": description of column in annotation

  If the database does not yet exist, a database is created with tables "Annotation" and "Metadata."

  The `SnpAnnotationSQLite` constructor creates and returns a SnpAnnotationSQLite instance.

### Accessors

In the code snippets below, `object` is a SnpAnnotationSQLite object.

  `open(object)`: Opens a connection to the database.

  `close(object)`: Closes the database connection.

  `nsnp(object)`: The number of SNPs in the database.

  `getSnpID(object, index, condition)`: A unique integer vector of snp IDs. The optional `index` is a logical or integer vector specifying elements to extract. The optional `condition` is a character string with an SQL clause used to select data (e.g., "LIMIT 10", "WHERE chromosome=1").

  `getChromosome(object, index, condition, char=FALSE)`: A vector of chromosomes. The optional `index` is a logical or integer vector specifying elements to extract. The optional `condition` is a character string with an SQL clause used to select data (e.g., "LIMIT 10", "WHERE chromosome=1"). 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, condition)`: An integer vector of base pair positions. The optional `index` is a logical or integer vector specifying elements to extract. The optional `condition` is a character string with an SQL clause used to select data (e.g., "LIMIT 10", "WHERE chromosome=1").

  `getAlleleA(object, index)`: A character vector of A alleles. The optional `condition` is a character string with an SQL clause used to select data (e.g., "LIMIT 10", "WHERE chromosome=1").

  `getAlleleB(object, index)`: A character vector of B alleles. The optional `condition` is a character string with an SQL clause used to select data (e.g., "LIMIT 10", "WHERE chromosome=1").

  `getVariable(object, varname, index, condition)`: A vector of the column `varname`. The optional `index` is a logical or integer vector specifying elements to extract. The optional `condition` is a character string with an SQL clause used to select data (e.g., "LIMIT 10", "WHERE chromosome=1"). 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.

  `getQuery(object, statement)`: Returns result of the SQL query `statement`.

  `writeAnnotation(object, value, append=FALSE, overwrite=TRUE)`: Writes `value` to the SNP annotation table. `value` must be a data.frame containing columns "snpID", "chromosome", and "position".

  `writeMetadata(object, value, append=FALSE, overwrite=TRUE)`: Writes `value` to the metadata table. `value` should be a data.frame containing columns "varname" and "description".

  `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.

### Author(s)

Stephanie Gogarten

### See Also

`ScanAnnotationSQLite`, `SnpAnnotationDataFrame`, `GenotypeData`, `IntensityData`

### Examples

    library(GWASdata)
    dbpath <- tempfile()
    snpAnnot <- SnpAnnotationSQLite(dbpath)

    data(illumina_snp_annot)
    writeAnnotation(snpAnnot, illumina_snp_annot)

    # list columns
    vars <- getVariableNames(snpAnnot)

    # add metadata
    metadf <- data.frame(varname=vars, description=rep(NA, length(vars)),
      row.names=vars, stringsAsFactors=FALSE)
    metadf["snpID", "description"] <- "integer id"
    writeMetadata(snpAnnot, metadf)

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

    # get positions only for chromosome 22
    pos22 <- getPosition(snpAnnot, condition="WHERE chromosome = 22")

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

    # display data
    head(getAnnotation(snpAnnot))
    getMetadata(snpAnnot)

    close(snpAnnot)
    file.remove(dbpath)

[Package GWASTools version 1.30.1 Index]