regenie

repository·master·Indexed 42 days ago

https://github.com/rgcgithub/regenie

A high-performance C++ tool for whole genome regression modelling in large-scale genome-wide association studies (GWAS). It supports quantitative, binary, and time-to-event traits, featuring Firth logistic and cox regression, gene-based burden tests (SKAT, SKATO, ACATV, ACATO, NNLS), and interaction tests. Compatible with BGEN, PLINK, and PLINK2 genetic data formats.

Tokens
13.5K
Snippets
31
Records
63
Agent score
54%

What's inside regenie

  1. Overview of regenie capabilities

    master

    regenie is a C++ program designed for whole genome regression modelling of large genome-wide association studies (GWAS).

    Key Features:

    • Trait Support: Works on quantitative, binary, and time-to-event traits. It handles unbalanced case-control ratios and low event rates.
    • Statistical Methods:
      • Binary traits: Supports Firth logistic regression and SPA tests.
      • Time-to-event traits: Supports Firth cox regression.
      • Gene/Region-based tests: Includes SKAT, SKATO, ACATV, ACATO, and NNLS (Non-Negative Least Square) tests.
      • Advanced Analysis: Supports interaction tests (GxE and GxG) and conditional analyses.
    • Data Formats: Supports BGEN, PLINK (bed/bim/fam), and PLINK2 (pgen/pvar/psam) genetic data formats.
    • Performance: Designed to be fast and memory efficient, and is ideally suited for implementation in Apache Spark (e.g., via GLOW).
  2. Overview of the qf library

    master

    The qf library provides C code designed to compute the p-value from a linear combination of $\chi^2(1)$ (chi-squared with 1 degree of freedom) distributions. It achieves this by inverting the characteristic function.

    Note: This implementation was modified from Robert Davies' original code to remove dependencies on the setjmp library, ensuring compatibility with C++ environments.

  3. Step 1: Ridge Regression (Level 0) and Cross-validation (Level 1)

    master

    In Step 1, REGENIE reduces the dimensionality of the genetic data to create efficient predictors.

    Level 0: Ridge Regression

    REGENIE reads markers in blocks of size $B$ (controlled by --bsize). For each block, it calculates a set of ridge regression predictors using a range of $J$ shrinkage parameters (controlled by --l0, default is 5). This captures the effects of markers within the block while accounting for Linkage Disequilibrium (LD).

    Level 1: Cross-validation

    To account for the correlation between the Level 0 predictors and the phenotype, REGENIE performs a second level of ridge regression on the full set of predictors.

    • Quantitative Traits: Uses ridge regression and selects the best shrinkage parameter ($\phi$) via K-fold cross-validation to prevent overfitting.
    • Binary Traits: Uses a logistic ridge regression model to combine predictors.
  4. How REGENIE works: The two-step approach

    master

    REGENIE implements a two-step method for genome-wide association testing designed to handle large sample sizes (e.g., UK Biobank) and diverse genetic data (microarray, imputation, exome sequencing).

    1. Step 1: Whole genome model: A subset of genetic markers (typically several hundred thousand common markers) is used to fit a whole genome regression model. This captures a significant portion of the phenotype variance attributable to genetic effects.
    2. Step 2: Association testing: A larger set of markers (e.g., imputed markers) is tested for association with the phenotype. This testing is performed conditional upon the predictions from Step 1 using a Leave One Chromosome Out (LOCO) scheme to avoid proximal contamination (where a marker's effect is accidentally captured by the Step 1 model because it is physically near the marker being tested).
  5. Use LOVO and LODO schemes for mask analysis

    master

    regenie supports Leave-One-Variant-Out (LOVO) and Leave-One-Domain-Out (LODO) schemes to analyze the impact of specific variants or domains on the mask.

    • LOVO (--mask-lovo): Builds masks by leaving out one variant at a time from the full set. The argument is a comma-separated list: [set/gene name],[mask name],[AAF cutoff]. If using 4-column annotations, use [gene name],[domain name],[mask name],[AAF cutoff].
    • LODO (--mask-lodo): Builds a LODO mask for each domain by excluding all variants in that domain. The argument is [gene name],[mask name],[AAF cutoff].

    Note: LOVO/LODO schemes cannot be used with --write-mask (PLINK bed output).

  6. Interpret interaction testing output suffixes

    master

    The interaction model follows the equation $g(\mu) = E\alpha + G\beta + (G\odot E)\gamma$. The TEST column in the output files uses suffixes to indicate which null hypothesis is being tested:

    • ADD: Marginal test where the interacting variable has not been added as a covariate ($H_0: \beta = 0$ given $\alpha=\gamma = 0$). Only printed for GxG by default, or GxE using --no-condtl.
    • ADD-CONDTL: Marginal test where the interacting variable has been added as a covariate ($H_0: \beta = 0$ given $\gamma = 0$). Default for GxE tests.
    • ADD-INT_VAR: Test for the main effect of the interaction variable ($H_0: \alpha = 0$). For categorical variables, separate lines are provided for each level (e.g., ADD-INT_BMI=25-30).
    • ADD-INT_SNP: Test for the main effect of the tested SNP in the interaction model ($H_0: \beta = 0$).
    • ADD-INT_SNPxVAR: Test for the interaction effect ($H_0: \gamma = 0$). For categorical variables, separate lines are provided for each level.
    • ADD-INT_$k$DF: Joint test for main and interaction effect of the tested variant ($k\ge2$ for categorical interacting variables) ($H_0: \beta = \gamma = 0$).
  7. Define a function for unconstrained minimization

    master

    To use the L-BFGS solver, you must define a functor (a class or struct) that represents the multivariate function to be minimized. The functor must implement an operator() with the following signature:

    double operator()(const VectorXd& x, VectorXd& grad)

    • x: The current point (input).
    • grad: The gradient vector, which must be overwritten with the gradient evaluated at x (output).
    • The return value must be the objective function value at x.
    class Rosenbrock
    {
    private:
        int n;
    public:
        Rosenbrock(int n_) : n(n_) {}
        double operator()(const Eigen::VectorXd& x, Eigen::VectorXd& grad)
        {
            double fx = 0.0;
            // ... calculate fx and populate grad ...
            return fx;
        }
    };
  8. Use helper classes for sparse compressed covariance/LD matrices

    master

    The remeta helper classes are designed to store sparse compressed covariance or Linkage Disequilibrium (LD) matrices originating from SKAT for use in meta-analysis.

    Note on Compilation: These classes depend on HTSlib. If HTSlib is not available on your system, these classes will not be compiled unless the WITH_HTSLIB macro is explicitly set during the build process.

  9. Understand A1FREQ calculation in burden masks

    master

    When building masks, the calculation of A1FREQ depends on the rule used:

    • max and comphet rules: The burden masks take values in [0, 2]. A1FREQ is calculated as the mean genotype divided by 2 (mean(G)/2), consistent with single variants.
    • sum rule: A1FREQ is calculated as the average of the effect allele frequencies across all sites included in the mask.
  10. Step 2: Single-variant association testing for Quantitative and Binary traits

    master

    In Step 2, REGENIE tests a larger set of markers for association using block-based processing to manage memory.

    Quantitative Traits

    Uses a linear regression model where:

    • Covariates are regressed out of phenotypes and genetic markers.
    • LOCO predictions from Step 1 are removed from the phenotypes.
    • Linear regression tests the association of the residualized phenotype and the genetic marker.

    Binary Traits

    Uses a logistic regression score test where:

    • The LOCO predictions from Step 1 are included as an offset.
    • Covariates are included in the linear predictor.
    • Handling Imbalance: For imbalanced case-control ratios, REGENIE uses:
      • Firth logistic regression: Applied when the standard p-value is below a threshold (default 0.05). Use --firth for a fast approximate version. Use --firth-se to report a Standard Error (SE) computed from the effect size and the LRT p-value.
      • Saddle point approximation (SPA) test: Provides better tail probability estimation than standard asymptotic theory. Use --minMAC to filter out ultra-rare variants where SPA might not work well.
  11. Understand the REGENIE two-step workflow

    master

    REGENIE operates in two distinct steps:

    Step 1: Genomic Prediction

    Used to estimate genetic effects and generate predictions.

    • Required Flag: --step 1.
    • Output: Generates .loco files (per-chromosome LOCO predictions) and a [prefix]_pred.list file.
    • Low Memory Mode: Use --lowmem to write level 0 predictions to disk instead of RAM. Use --lowmem-prefix to specify the temporary directory.

    Step 2: Association Testing

    Used to test individual variants for association with traits using the predictions from Step 1.

    • Required Flags: --step 2 and --pred [FILE].
    • Input for --pred: The [prefix]_pred.list file generated in Step 1.
    • Output: Generates .regenie files containing association statistics (chromosome, position, ID, alleles, frequency, sample size, test type, effect size, SE, chi-square, and p-value).

    Relationship: Step 2 relies on the predictions produced in Step 1. If you are running Step 2, the covariate file used must be the same as the one used in Step 1.

    # Step 1
    regenie --step 1 --bgen data.bgen --phenoFile pheno.txt --out run1
    
    # Step 2
    regenie --step 2 --bgen data.bgen --phenoFile pheno.txt --pred run1_pred.list --out run2
  12. Selection of traits for large-scale analysis

    master

    When performing large-scale analyses (like UK Biobank), regenie can analyze multiple traits at once for higher computational efficiency.

    Guidelines:

    • Imputation: regenie uses an imputation scheme to handle missing data. This is effective for quantitative traits with up to ~20% missingness and binary traits with up to ~5% missingness.
    • Grouping: Group traits that have similar missingness patterns and keep missingness reasonably low (<15%) to ensure accuracy.