Analyzing Sequence Data using the GENESIS Package

Stephanie M. Gogarten

2019-02-20

Overview

This vignette provides a description of how to use the GENESIS package to analyze sequence data. We demonstrate the use of mixed models for genetic association testing, as PC-AiR PCs can be used as fixed effect covariates to adjust for population stratification, and a kinship matrix (or genetic relationship matrix) estimated from PC-Relate can be used to account for phenotype correlation due to genetic similarity among samples. To illustrate the methods, we use a small subset of data from 1000 Genomes Phase 3.

Convert VCF to GDS

The first step is to convert a VCF file into the GDS file format used by GENESIS. We use the SeqArray package, which defines the extended GDS format used to capture all data in a VCF file. If the VCF files are split by chromosome, they can be combined into a single GDS file.

library(SeqArray)
vcffile <- system.file("extdata", "1KG", paste0("1KG_phase3_subset_chr", 1:22, ".vcf.gz"), package="GENESIS")
gdsfile <- tempfile()
seqVCF2GDS(vcffile, gdsfile, verbose=FALSE)
gds <- seqOpen(gdsfile)
gds
## Object of class "SeqVarGDSClass"
## File: /tmp/Rtmpk7HVEP/fileb3652c58532 (419.8K)
## +    [  ] *
## |--+ description   [  ] *
## |--+ sample.id   { Str8 100 LZMA_ra(37.8%), 309B } *
## |--+ variant.id   { Int32 24639 LZMA_ra(7.99%), 7.7K } *
## |--+ position   { Int32 24639 LZMA_ra(71.8%), 69.1K } *
## |--+ chromosome   { Str8 24639 LZMA_ra(0.36%), 237B } *
## |--+ allele   { Str8 24639 LZMA_ra(19.2%), 20.0K } *
## |--+ genotype   [  ] *
## |  |--+ data   { Bit2 2x100x24657 LZMA_ra(18.7%), 224.9K } *
## |  |--+ extra.index   { Int32 3x0 LZMA_ra, 18B } *
## |  \--+ extra   { Int16 0 LZMA_ra, 18B }
## |--+ phase   [  ]
## |  |--+ data   { Bit1 100x24639 LZMA_ra(0.06%), 201B } *
## |  |--+ extra.index   { Int32 3x0 LZMA_ra, 18B } *
## |  \--+ extra   { Bit1 0 LZMA_ra, 18B }
## |--+ annotation   [  ]
## |  |--+ id   { Str8 24639 LZMA_ra(37.3%), 87.8K } *
## |  |--+ qual   { Float32 24639 LZMA_ra(0.17%), 173B } *
## |  |--+ filter   { Int32,factor 24639 LZMA_ra(0.17%), 173B } *
## |  |--+ info   [  ]
## |  \--+ format   [  ]
## \--+ sample.annotation   [  ]

Create a SeqVarData object

Next, we combine the GDS file with information about the samples, which we store in an AnnotatedDataFrame (defined in the Biobase package). An AnnotatedDataFrame combines a data.frame with metadata describing each column. A SeqVarData object (defined in the SeqVarTools package), contains both an open GDS file and an AnnotatedDataFrame describing the samples. The sample.id column in the AnnotatedDataFrame must match the sample.id node in the GDS file.

## [1] TRUE

Population structure and relatedness

PC-AiR and PC-Relate are described in detail in a separate vignette. Here, we demonstrate their use to provide adjustment for population structure and relatedness in a mixed model.

KING

Step 1 is to get initial estimates of kinship using KING, which is robust to population structure but not admixture. The KING algorithm is available in SNPRelate. We select a subset of variants for this calculation with LD pruning.

PC-AiR

The next step is PC-AiR, in which we select a set of unrelated samples that is maximally informative about all ancestries in the sample, use this unrelated set for Principal Component Analysis (PCA), then project the relatives onto the PCs. We use a kinship threshold of degree 3 (unrelated is less than first cousins). In this example, we use the KING estimates for both kinship (kinobj) and ancestry divergence (divobj). KING kinship estimates are negative for samples with different ancestry.

## Principal Component Analysis (PCA) on genotypes:
## Calculating allele counts/frequencies ...
## 
[..................................................]  0%, ETC: ---    
[==================================================] 100%, completed in 0s
## Excluding 330 SNVs (monomorphic: TRUE, MAF: NaN, missing rate: NaN)
## Working space: 88 samples, 10,468 SNVs
##     using 1 (CPU) core
## CPU capabilities: Double-Precision SSE2
## Wed Feb 20 20:07:16 2019    (internal increment: 36816)
## 
[..................................................]  0%, ETC: ---        
[==================================================] 100%, completed in 0s
## Wed Feb 20 20:07:16 2019    Begin (eigenvalues and eigenvectors)
## Wed Feb 20 20:07:16 2019    Done.
## SNP loading:
## Working space: 88 samples, 10468 SNPs
##     using 1 (CPU) core
##     using the top 32 eigenvectors
## Wed Feb 20 20:07:16 2019    (internal increment: 65536)
## 
[..................................................]  0%, ETC: ---        
[==================================================] 100%, completed in 0s
## Wed Feb 20 20:07:16 2019    Done.
## Sample loading:
## Working space: 12 samples, 10468 SNPs
##     using 1 (CPU) core
##     using the top 32 eigenvectors
## Wed Feb 20 20:07:16 2019    (internal increment: 65536)
## 
[..................................................]  0%, ETC: ---        
[==================================================] 100%, completed in 0s
## Wed Feb 20 20:07:16 2019    Done.

We need to determine which PCs are ancestry informative. To do this we need population information for the 1000 Genomes samples. We make a parallel coordinates plot, color-coding by 1000 Genomes population.

PC-Relate

The first 2 PCs separate populations, so we use them to compute kinship estimates adjusting for ancestry. The pcrelate method requires creating a SeqVarBlockIterator object, which should iterate over the pruned SNPs only.

## # of selected variants: 10,798

To improve our estimates for PCs and kinship, we could run another iteration of PC-AiR and PC-Relate, this time using the PC-Relate kinship estimates as the kinobj argument to pcair. The KING matrix is still used for ancestry divergence. We could then use those new PCs to calculate revised kinship estimates.

Association tests

Null model

The first step for association testing is to fit the model under the null hypothesis that each SNP has no effect. This null model contains all of the covariates, including ancestry representative PCs, as well as any random effects, such as a polygenic effect due to genetic relatedness, but it does not include any SNP genotype terms as fixed effects.

The type of model fit depends on the arguments to fitNullModel. Including a cov.mat argument will result in a mixed model, while omitting this argument will run a standard linear model. A logistic model is specified with family="binomial". In the case of a logistic model and a covariance matrix, fitNullModel will use the GMMAT algorithm. Including a group.var argument will allow heteroscedastic variance (for linear models or linear mixed models only).

Single variant tests

To run a test using the null model, we first create an iterator object specifying how we want variants to be selected. (See the documentation for the SeqVarIterator class in SeqVarTools for more details.) For single-variant tests (GWAS), it is common to use a block iterator that reads variants in blocks (default is 10,000 variants per block).

For example purposes, we restrict our analysis to chromosome 1. The seqSetFilter function can be used to restrict the set of variants tested in other ways (e.g., variants that pass a quality filter).

## # of selected variants: 1,120
##   variant.id chr     pos allele.index n.obs  freq      Score  Score.SE
## 1          1   1  828740            1   100 0.035  1.3034215 2.6179616
## 2          2   1  913272            1   100 0.010  0.4913351 1.2830821
## 3          3   1 1171878            1   100 0.005  1.1534379 0.9278191
## 4          4   1 1242288            1   100 0.025 -1.4188486 1.9895353
## 5          5   1 1378837            1   100 0.670  2.1279286 5.5336244
## 6          6   1 1403820            1   100 0.015 -2.1785851 1.5559273
##   Score.Stat Score.pval
## 1  0.4978765  0.6185711
## 2  0.3829335  0.7017691
## 3  1.2431712  0.2138048
## 4 -0.7131558  0.4757494
## 5  0.3845452  0.7005744
## 6 -1.4001844  0.1614581

The default test is a Score test, but the Wald test is also available for continuous outcomes.

If there are multiallelic variants, each alternate allele is tested separately. The allele.index column in the output differentiates between different alternate alleles for the same variant.

We make a QQ plot to examine the results.

Aggregate tests

We can aggregate rare variants for association testing to decrease multiple testing burden and increase statistical power. We can create functionally agnostic units using a SeqVarWindowIterator. This iterator type generates a sliding window over the genome, with user-specified width and step size. We can also create units with specific start and end points or containing specific variants, using a SeqVarRangeIterator or a SeqVarListIterator.

In this example, we illustrate defining ranges based on known genes. We run a burden test, setting a maximum alternate allele frequency to exclude common variants.

## # of selected variants: 1,120

The output of an aggregate test is a list with two elements: 1) a data.frame with the test results for each aggregate unit, and 2) a list of data.frames containing the variants in each aggregate unit.

##   n.site n.alt n.sample.alt       Score  Score.SE  Score.Stat Score.pval
## 1      1     3            3 -2.17858513 1.5559273 -1.40018439  0.1614581
## 2      1     5            5  2.23972473 2.0534695  1.09070270  0.2754037
## 3      1     1            1  0.08001278 0.9603839  0.08331333  0.9336024
## 4      1     9            9 -1.41021876 2.3409891 -0.60240297  0.5469059
## 5      0     0            0          NA        NA          NA         NA
## 6      1     1            1  0.67872777 0.9375709  0.72392153  0.4691139
## [[1]]
##   variant.id chr     pos allele.index n.obs  freq weight
## 1          6   1 1403820            1   100 0.015      1
## 
## [[2]]
##   variant.id chr     pos allele.index n.obs  freq weight
## 1          7   1 1421285            1   100 0.025      1
## 
## [[3]]
##   variant.id chr     pos allele.index n.obs  freq weight
## 1         12   1 2023475            1   100 0.005      1
## 
## [[4]]
##   variant.id chr     pos allele.index n.obs  freq weight
## 1         21   1 3254100            1   100 0.045      1
## 
## [[5]]
## [1] variant.id   chr          pos          allele.index n.obs       
## [6] freq         weight      
## <0 rows> (or 0-length row.names)
## 
## [[6]]
##   variant.id chr     pos allele.index n.obs  freq weight
## 1         24   1 3818550            1   100 0.005      1

References