A review of the ranking's arithmetic found four things wrong, all of which made the score look better informed than it was. Measurements below are from this repo, not estimates. **Components now abstain instead of inventing a number.** A run without a VEP cache returns no allele frequencies, and rarity_score(None) read that as "absent from gnomAD, therefore maximally rare" and awarded every variant a free 0.25. jobs.has_frequencies / has_effect_scores record what the run actually produced, absent components are dropped from the weighted mean, and the remaining weights are renormalised so the score keeps its meaning. The UI shows "not looked up" rather than a bar, and the funnel stops calling a step "rare" when nothing was filtered. **Allele frequency is no longer a model feature.** It dominated: the same missense variant scored 0.887 at AF 0 and 0.0003 at AF 0.01. That double- counted, because the ranking already scores frequency explicitly, putting ~45% of every rank on one measurement; and it was circular, because ACMG assigns ClinVar's benign labels using frequency (BA1/BS1). Retraining without it moves missense AUROC from 0.872 to 0.500 — exactly random. The old figure was allele frequency, not variant-effect knowledge. The model therefore abstains unless CADD or AlphaMissense is present, since otherwise it only restates the consequence class. **Phenotype matching is weighted by information content** and HPO annotations are propagated up the ontology. Counting terms alike let "global developmental delay" (IC 0.93) count as much as "dilated left subclavian artery" (IC 7.88). **A real bug in the propagation, found by checking it.** The ancestor walk read a pre-order DFS backwards, which on a DAG lets a term resolve before one of its parents and inherit that parent alone instead of its lineage. It dropped 399 terms out of the phenotype branch, Camptodactyly and Chiari malformation among them. Now a true post-order, tested against a reference transitive closure. The ontology arithmetic moved to rarelens_ml.hpo so it is covered by tests, and rarelens_ml.benchmark measures the whole thing: across 10,178 published cases the causal gene ranks first 45.9-81.0% of the time against 5,269 genes, versus 0.02% for chance. docs/data.md reports that with its contamination (HPO's annotations come from these same case reports), and includes the measurement showing information-content weighting earns its place while propagation does not - kept anyway, for a reason the docs argue rather than assume.
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
import math
|
|
|
|
import pandas as pd
|
|
|
|
from rarelens_ml.features import RAW_COLUMNS, build
|
|
|
|
|
|
def raw(**overrides: list) -> pd.DataFrame:
|
|
base = {
|
|
"impact": ["HIGH", "LOW", None],
|
|
"consequence": ["stop_gained", "synonymous_variant", None],
|
|
"cadd_phred": ["35", "2.1", "-"],
|
|
"am_pathogenicity": ["0.98", None, "-"],
|
|
}
|
|
base.update(overrides)
|
|
return pd.DataFrame(base, index=[10, 11, 12])
|
|
|
|
|
|
def test_raw_columns_are_the_serving_contract() -> None:
|
|
assert RAW_COLUMNS == ["impact", "consequence", "cadd_phred", "am_pathogenicity"]
|
|
|
|
|
|
def test_allele_frequency_is_not_a_feature() -> None:
|
|
"""It dominated the model and the ranking already scores it, auditably and only once.
|
|
|
|
Keeping it here also meant learning ACMG's own frequency-based benign rule from labels that
|
|
rule produced, which is most of why the headline AUROC looked so good.
|
|
"""
|
|
assert "gnomad_af" not in RAW_COLUMNS
|
|
assert "gnomad_af" not in build(raw(gnomad_af=[0.0, 0.5, None])).columns
|
|
|
|
|
|
def test_build_ranks_impact_and_coerces_numbers() -> None:
|
|
out = build(raw())
|
|
assert out["impact_rank"].tolist() == [3, 1, 0]
|
|
assert out["cadd_phred"].iloc[0] == 35.0
|
|
assert math.isnan(out["cadd_phred"].iloc[2]) # VEP writes "-" for missing
|
|
assert math.isnan(out["am_pathogenicity"].iloc[1])
|
|
|
|
|
|
def test_build_keeps_the_input_index() -> None:
|
|
assert build(raw()).index.tolist() == [10, 11, 12]
|
|
|
|
|
|
def test_build_makes_consequence_categorical() -> None:
|
|
assert isinstance(build(raw())["consequence"].dtype, pd.CategoricalDtype)
|