bigsnpr R Package

repository·master·Indexed 42 days ago

https://github.com/privefl/bigsnpr

An R package for the analysis of massive SNP arrays in human genetics. It extends bigstatsr to provide tools for genotype data analysis, including quality control, imputation via snp_fastImpute(), and polygenic score calculation using methods such as LDpred2, lassosum2, and Clumping and Thresholding.

Tokens
601
Snippets
2
Records
5
Agent score
3%

What's inside bigsnpr

  1. Understand the bigSNP data object

    master

    The core data structure in bigsnpr is the bigSNP class, which represents SNP data as a list containing:

    • $genotypes: An FBM.code256 object where rows are samples and columns are variants. This stores genotype calls or dosages (rounded to 2 decimal places).
    • $fam: A data.frame containing individual/sample information.
    • $map: A data.frame containing variant information.

    Important Note on Missing Values: Most algorithms in this package do not handle missing values. You should either impute missing values of genotyped variants using snp_fastImpute() or snp_fastImputeSimple(), or use the bed_*() functions which are designed to work directly on .bed files with a few missing values.

  2. Calculate Polygenic Scores (PGS)

    master

    The package provides three primary methods for polygenic score calculation:

    1. Penalized regressions: Uses individual-level data.
    2. Clumping and Thresholding (C+T) and Stacked C+T (SCT): Uses a combination of summary statistics and individual-level data.
    3. LDpred2 and lassosum2: Uses summary statistics (LDpred2 is a major focus of the package).
  3. Install bigsnpr

    master

    You can install bigsnpr from CRAN or directly from GitHub using the remotes package.

    From CRAN:

    install.packages("bigsnpr")

    From GitHub:

    # install.packages("remotes")
    remotes::install_github("privefl/bigsnpr")
    # install.packages("remotes")
    remotes::install_github("privefl/bigsnpr")
  4. Read SNP data from PLINK or BGEN formats

    master

    Use the following functions to load genotype data into the bigSNP format:

    • PLINK files (bed/bim/fam): Use snp_readBed() or snp_readBed2().
    • UK Biobank BGEN files: Use snp_readBGEN().

    Before reading into the bigSNP format, you can perform quality control and conversion using PLINK via the R functions snp_plinkQC() and snp_plinkKINGQC().

    # Example usage (conceptual):
    # bfile <- snp_readBed(bedfile = "path/to/file")
    # bgen <- snp_readBGEN(bgenfile = "path/to/file")
  5. Impute missing genotypes

    master

    Since most bigsnpr algorithms require complete data, you can use these functions to handle missing values in genotyped variants:

    • snp_fastImpute(): A more thorough imputation method (can take several hours for large datasets, e.g., 15K x 300K).
    • snp_fastImputeSimple(): A faster, simpler imputation method (takes only a few minutes).