mecfs_bio.build_system.task.fast_ct_ldsc.alignment_guards
Fail-fast guards against upstream harmonization bugs in a trait aligned for fast CT-LDSC.
The trait is joined to the HapMap3 regression SNPs by rsID, so a trait whose rsIDs were assigned wrongly upstream (for example from positions in the wrong genome build) would silently yield z-scores for the wrong variants. Three diagnostics expose that, all over the context SNP set:
- coverage = n_matched / n_context: the fraction of context SNPs the trait supplies with alleles that match the index (directly or swapped).
- allele_mismatch_fraction = (n_found - n_matched) / n_found: among context rsIDs the trait carries, the fraction whose alleles do not match the index. Correct rsIDs mismatch well under 1%; rsIDs pointing at the wrong variant mismatch at a large rate.
- position_concordance = n_position_concordant / n_position_compared: among matched SNPs with a trait position, the fraction whose (CHR, POS) equals the index's hg19 position. Only meaningful when the trait declares build 19, so the guard is applied only then.
Classes:
-
AlignmentDiagnostics–Counts from aligning one trait to the context SNP set, plus the trait's declared build.
-
AlignmentGuards–Thresholds for the alignment diagnostics; each lies in [0, 1].
Functions:
-
alignment_diagnostics– -
check_alignment_guards–Assert, in order, the coverage, allele-mismatch and (build 19 only) position guards.
AlignmentDiagnostics
Counts from aligning one trait to the context SNP set, plus the trait's declared build.
Methods:
Attributes:
-
allele_mismatch_fraction(float) – -
coverage(float) – -
declared_build(GenomeBuild | None) – -
n_context(int) – -
n_found(int) – -
n_matched(int) – -
n_position_compared(int | None) – -
n_position_concordant(int | None) – -
position_concordance(float | None) –
from_json_dict
classmethod
Source code in mecfs_bio/build_system/task/fast_ct_ldsc/alignment_guards.py
to_json_dict
Source code in mecfs_bio/build_system/task/fast_ct_ldsc/alignment_guards.py
AlignmentGuards
Thresholds for the alignment diagnostics; each lies in [0, 1].
The defaults leave wide margin around the values observed on the 13 traits of the initial genetic correlation study (experiments/claude/fast_ct_ldsc_vs_gwaslab): coverage 0.954 to 0.999, allele_mismatch_fraction at most 0.0007, and position_concordance at least 0.99999.
Attributes:
alignment_diagnostics
alignment_diagnostics(
aligned: TraitAligned,
declared_build: GenomeBuild | None,
) -> AlignmentDiagnostics
Source code in mecfs_bio/build_system/task/fast_ct_ldsc/alignment_guards.py
check_alignment_guards
check_alignment_guards(
diagnostics: AlignmentDiagnostics,
guards: AlignmentGuards,
alias: str,
) -> None
Assert, in order, the coverage, allele-mismatch and (build 19 only) position guards.