Learn R Programming

GWASTools (version 1.12.2)

gwasExactHW: Hardy-Weinberg Equilibrium testing

Description

This function performs exact Hardy-Weinberg Equilibrium testing (using Fisher's Test) over a selection of SNPs. It also performs genotype counts, calculates allele frequencies, and calculates inbreeding coefficients.

Usage

gwasExactHW(genoData, scan.chromosome.filter = NULL, scan.exclude = NULL, geno.counts = TRUE, chromosome.set = NULL, block.size = 5000, verbose = TRUE, outfile = NULL)

Arguments

genoData
GenotypeData object, should contain sex and phenotypes in scan annotation. Chromosomes are expected to be in contiguous blocks.
scan.chromosome.filter
a logical matrix that can be used to exclude some chromosomes, some scans, or some specific scan-chromosome pairs. Entries should be TRUE if that scan-chromosome pair should be included in the analysis, FALSE if not. The number of rows must be equal to the number of scans in genoData, and the number of columns must be equal to the largest integer chromosome value in genoData. The column number must match the chromosome number. e.g. A scan.chromosome.filter matrix used for an analyis when genoData has SNPs with chromosome=(1-24, 26, 27) (i.e. no Y (25) chromosome SNPs) must have 27 columns (all FALSE in the 25th column). But a scan.chromosome.filter matrix used for an analysis genoData has SNPs chromosome=(1-26) (i.e no Unmapped (27) chromosome SNPs) must have only 26 columns.
scan.exclude
an integer vector containing the IDs of entire scans to be excluded.
geno.counts
if TRUE (default), genotype counts are returned in the output data.frame.
chromosome.set
integer vector with chromosome(s) to be analyzed. Use 23, 24, 25, 26, 27 for X, XY, Y, M, Unmapped respectively.
block.size
Number of SNPs to be read from genoData at once.
verbose
if TRUE (default), will print status updates while the function runs. e.g. it will print "chr 1 block 1 of 10" etc. in the R console after each block of SNPs is done being analyzed.
outfile
a character string to append in front of ".chr.i_k.RData" for naming the output data-frame; where i is the first chromosome, and k is the last chromosome used in that call to the function. "chr.i_k." will be omitted if chromosome.set=NULL.

Value

If outfile=NULL (default), all results are returned as a single data.frame. If outfile is specified, no data is returned but the function saves a data-frame with the naming convention as described by the argument outfile.The first three columns of the data-frame are:
snpID
snpID (from the snp annotation) of the SNP
chromosome
chromosome (from the snp annotation) of the SNP. The integers 23, 24, 25, 26, 27 are used for X, XY, Y, M, Unmapped respectively.
position
position (from the snp annotation) of the SNP
If geno.counts = TRUE:
nAA
number of AA genotypes in samples
nAB
number of AB genotypes in samples
nBB
number of BB genotypes in samples
MAF
minor allele frequency.
minor.allele
the minor allele. Takes values "A" or "B".
f
the inbreeding coefficient.
p.value
exact Hardy-Weinberg Equilibrium (using Fisher's Test) p-value. p.value will be NA for monomorphic SNPs (MAF == 0).
Warnings:If outfile is not NULL, another file will be saved with the name "outfile.chr.i_k.warnings.RData" that contains any warnings generated by the function.

Details

HWE calculations are performed with the HWExact function in the GWASExactHW package. For the X chromosome, only female samples will be used in all calculations (since males are excluded from HWE testing on this chromosome). Hence if chromosome.set includes 23, the scan annotation of genoData should provide the sex of the sample ("M" or "F") i.e. there should be a column named "sex" with "F" for females and "M" for males.

Y, M, and U (25, 26, and 27) chromsome SNPs are not used in HWE analysis, so all returned values for these SNPs will be NA.

See Also

HWExact

Examples

Run this code
# The following example would perform exact Hardy-Weinberg equilibrium testing on all chromosomes in this data set.  It would also return genotype counts, minor allele frequencies, and inbreeding coefficients.

library(GWASdata)
data(illuminaScanADF)

# run only on YRI subjects
scan.exclude <- illuminaScanADF$scanID[illuminaScanADF$race != "YRI"]

# create data object
gdsfile <- system.file("extdata", "illumina_geno.gds", package="GWASdata")
gds <- GdsGenotypeReader(gdsfile)
genoData <-  GenotypeData(gds, scanAnnot=illuminaScanADF)

hwe <- gwasExactHW(genoData, scan.exclude=scan.exclude)

close(genoData)

Run the code above in your browser using DataLab