diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-11-21 21:14:01 +0000 |
|---|---|---|
| committer | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-11-21 21:14:01 +0000 |
| commit | 098bc6fcc8da84a3598e301c6527d2907df5252e (patch) | |
| tree | fb09fdb5e3bc1fe6df26e229ea7e987c9cfcd8bf /scripts | |
| parent | fd5807024b0b5553cbe6e7d6d2bf717d50ef8b05 (diff) | |
| download | genenetwork4-098bc6fcc8da84a3598e301c6527d2907df5252e.tar.gz | |
scripts: project a panel whose markers are each biallelic onto their own pair
HET3-ITP.12's codes are not one alphabet: 486 markers carry exactly {5,6},
395 carry {7,8}, one carries {2,3}. Each marker is biallelic with its own
code pair, which is why a single global table is constant on that panel
(measured: 881 of 893 markers with zero variance) and why `--pairwise` exists:
per marker, its two present codes become 0 and 1, and a marker with one or
more than two classes is left missing rather than folded.
`--pairwise` produces a real pair -- 2,603,603 of 5,761,710 calls, dosages
0 and 1 at 50/50 -- and pangemma ran HET3-ITP trait 10000 on it: HTTP 200 in
2678 s (44.6 min; 6447 mice, so the LOCO eigen decomposition per chromosome
dominates). The *result* is not usable yet, and the numbers say why: only 36
of 893 markers came back with association rows, and `af` reads 0.25, i.e.
GEMMA divided a mean-of-0.5 by two -- the coding is on the wrong scale for its
mean-genotype convention (0, 0.5, 1), and most markers then fall out.
So: the panel's structure is now understood and the tool can express it; what
remains is the dosage scale (0/0.5/1 rather than 0/1) and finding why 857
markers produce no rows. Data restored to the shipped stub meanwhile -- a
45-minute run that returns 36 markers should not be what the deployment serves.
R/qtl stays the engine for this panel (it models the 4-way genotypes
directly); the point of the exercise is that GEMMA's refusal was diagnosable,
not mysterious.
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/geno-to-bimbam.py | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/scripts/geno-to-bimbam.py b/scripts/geno-to-bimbam.py index 089da45..b31829d 100755 --- a/scripts/geno-to-bimbam.py +++ b/scripts/geno-to-bimbam.py @@ -34,8 +34,16 @@ is not in the `.geno` header, this repository, or the panel's `rdata/*.RData` decision for whoever owns the panel -- pick the founders, then pass the table here. R/qtl remains the engine for 4-way panels (docs/genotypes.md). - scripts/geno-to-bimbam.py --geno HET3-ITP.12.geno --out DIR + scripts/geno-to-bimbam.py --geno HET3-ITP.12.geno --out DIR --pairwise writes DIR/HET3-ITP.12_geno.txt and DIR/HET3-ITP.12_snps.txt. + +NOT every panel needs a fixed table. A panel whose markers are each biallelic +but whose *code pair* varies from marker to marker (HET3-ITP.12: 486 markers +carry codes {5,6}, 395 carry {7,8}, a handful more) needs `--pairwise`: for +each marker its two present codes become 0 and 1 (lower code -> 0), anything +else missing. That is the biallelic projection the panel actually supports -- +a single global table cannot express it, and forcing one there was measured to +be constant (881 of 893 markers with zero variance). """ import argparse @@ -71,16 +79,27 @@ def main(): help="basename for the outputs (default: the .geno's name)", ) parser.add_argument( + "--pairwise", + action="store_true", + help="per-marker biallelic coding: each marker's two present codes " + "become 0 and 1. Use this for a panel whose code pair varies by " + "marker (see the docstring); it conflicts with --codes.", + ) + parser.add_argument( "--codes", - required=True, + required=False, help="projection table: '<dosage>=<code,code,...>' separated by ';', " "e.g. '0=1,2;1=3,4;0.5=5,6,7,8' (required: a guessed table produces a " "silently empty projection, see the docstring)", ) args = parser.parse_args() + if bool(args.pairwise) == bool(args.codes): + sys.exit("give exactly one of --pairwise or --codes") table = {} - for part in args.codes.split(";"): + for part in (args.codes or "").split(";"): + if not part: + continue dosage, codes = part.split("=") for code in codes.split(","): table[code.strip()] = dosage.strip() @@ -93,12 +112,27 @@ def main(): seen = {"markers": 0, "calls": 0, "missing": 0} per_dosage = {} + pairwise_seen = {} with open(geno_out, "w") as geno, open(snps_out, "w") as snps: for chrom, locus, _cm, mb, calls in read_geno(args.geno): + marker_table = table + if args.pairwise: + present = sorted({c.strip() for c in calls if c.strip() not in ("NA", "", ".")}) + # Exactly two classes is what a biallelic marker looks like. + # One class (monomorphic) or more than two (a genuinely + # multi-allelic marker, which BIMBAM cannot carry) is left + # missing rather than silently folded. + if len(present) == 2: + marker_table = {present[0]: "0", present[1]: "1"} + pairwise_seen[(present[0], present[1])] = ( + pairwise_seen.get((present[0], present[1]), 0) + 1 + ) + else: + marker_table = {} projected = [] for call in calls: call = call.strip() - dosage = table.get(call) + dosage = marker_table.get(call) if dosage is None: projected.append("NA") seen["missing"] += 1 @@ -133,6 +167,13 @@ def main(): f"calls projected ({100 * (1 - seen['missing'] / seen['calls']):.1f}% present), " f"dosages {dict(sorted(per_dosage.items()))}" ) + if args.pairwise: + print( + "per-marker code pairs: " + + ", ".join( + f"{a}/{b}: {n}" for (a, b), n in sorted(pairwise_seen.items(), key=lambda kv: -kv[1]) + ) + ) print(f"{snps_out}") |
