GWAS & Polygenic Scores
Genome-wide association statistics and polygenic score computation from simulation output.
GWAS and Polygenic Score (PGS) computation from simulation output.
Provides: - GWAS: per-variant association statistics (beta, SE, t, p) for each phenotype - PGS: polygenic score calculation from external weights
- class xftsim.gwas.GWASResult(beta, se, t_stat, p_value, af, n)[source]
Bases:
objectPer-variant association statistics for a single phenotype.
- beta
(m,) regression coefficients (phenotype on genotype dosage).
- Type:
np.ndarray
- se
(m,) standard errors of beta.
- Type:
np.ndarray
- t_stat
(m,) t-statistics (beta / se).
- Type:
np.ndarray
- p_value
(m,) two-sided p-values.
- Type:
np.ndarray
- af
(m,) allele frequencies.
- Type:
np.ndarray
- class xftsim.gwas.GWAS(haplotypes, phenotypes, sample_indices=None)[source]
Bases:
objectGenome-wide association study: per-variant regression of phenotype on genotype dosage.
Computes OLS regression statistics for every variant simultaneously using efficient matrix operations (no per-variant loops).
- Parameters:
haplotypes (
HaplotypeOperator) – Genotype data (DenseHaplotypeArray or GraphHaplotypeOperator).phenotypes (
PhenotypeArray) – Phenotype data (dict-like, keyed by phenotype name).sample_indices (
np.ndarray, optional) – Indices of samples to include (e.g. from an UnrelatedView). If None, all samples are used.
- Parameters:
haplotypes (HaplotypeOperator)
phenotypes (PhenotypeArray)
sample_indices (np.ndarray | None)
Examples
>>> gwas = GWAS(haplotypes, phenotypes) >>> results = gwas.run() # all phenotype keys >>> results = gwas.run(['Y']) # specific keys >>> r = results['Y'] >>> r.beta, r.se, r.p_value
- Parameters:
haplotypes (
HaplotypeOperator)phenotypes (
PhenotypeArray)
- class xftsim.gwas.PGS(haplotypes, weights, standardized=False)[source]
Bases:
objectPolygenic score calculator.
Computes PGS = haplotypes @ weights using the HaplotypeOperator’s matvec (raw or standardized).
- Parameters:
haplotypes (
HaplotypeOperator) – Genotype data.weights (
np.ndarrayordict) – Effect weights. If dict, maps variant IDs to weights (looked up against haplotypes.variants.vid). If np.ndarray, must be (m,).standardized (
bool) – If True, use standardized genotypes (centered by 2*AF). Default is False (raw dosage).
- Parameters:
haplotypes (HaplotypeOperator)
standardized (bool)
Examples
>>> pgs = PGS(haplotypes, weights=beta_hat) >>> scores = pgs.score()