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: object

Per-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

n

Sample size used.

Type:

int

Parameters:
beta: ndarray
se: ndarray
t_stat: ndarray
p_value: ndarray
af: ndarray
n: int
class xftsim.gwas.GWAS(haplotypes, phenotypes, sample_indices=None)[source]

Bases: object

Genome-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:

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:
run(keys=None)[source]

Run GWAS for specified phenotype keys.

Parameters:

keys (list of str, optional) – Phenotype keys to analyze. If None, uses all keys.

Return type:

dict[str, GWASResult]

Returns:

dict[str, GWASResult] – Mapping from phenotype key to association results.

Parameters:

keys (list[str] | None)

class xftsim.gwas.PGS(haplotypes, weights, standardized=False)[source]

Bases: object

Polygenic score calculator.

Computes PGS = haplotypes @ weights using the HaplotypeOperator’s matvec (raw or standardized).

Parameters:
  • haplotypes (HaplotypeOperator) – Genotype data.

  • weights (np.ndarray or dict) – 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:

Examples

>>> pgs = PGS(haplotypes, weights=beta_hat)
>>> scores = pgs.score()
Parameters:
score()[source]

Compute polygenic scores.

Return type:

ndarray

Returns:

np.ndarray – (n,) array of polygenic scores, one per sample.