From 0253fa66f2ef464d56324c27ba51cec1e27e3108 Mon Sep 17 00:00:00 2001 From: Pjotr Date: Tue, 10 Nov 2026 21:39:01 +0000 Subject: uploads: map an uploaded genotype by name, and clean up after it Three follow-ups from putting an upload through the whole loop. * /compute/qtl2's `genotype_file` branch only accepted positional `trait_values`, i.e. it demanded the file's column order -- which a caller with an uploaded population does not have. It now takes `samples` (name and value) or a `basket` and aligns them onto the cross by name, leaving individuals without a value as missing. Positional `trait_values` still work for a file whose order is known. * DELETE /uploads/genotypes/{name} now removes the .geno it wrote on demand: a file nobody can name is a file that confuses the next operator. * scripts/example-genotype-upload.py spreads its markers across chromosomes. One chromosome of markers is a poor example -- a leave-one-chromosome-out kinship has nothing to leave out, so the scan came back with no rows at all, which looked like a broken upload and was really a property of the example. 20 markers over the genome map cleanly (19 rows, the 20th used for the HMM), and the README says to use "kinship": "overall" if a file really has one chromosome. --- scripts/example-genotype-upload.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/example-genotype-upload.py b/scripts/example-genotype-upload.py index 0e36e63..07f683c 100755 --- a/scripts/example-genotype-upload.py +++ b/scripts/example-genotype-upload.py @@ -40,6 +40,26 @@ def read_geno(path: str): return individuals, markers +def spread(markers, wanted): + """Markers spread across chromosomes. + + One chromosome of markers makes a poor example: an LMM's leave-one- + chromosome-out kinship has nothing to leave out, so a scan over it is flat + or empty. Taking a marker per chromosome first gives a file a scan can + actually use. + """ + seen, first = set(), [] + for marker in markers: + if marker[1] not in seen: + seen.add(marker[1]) + first.append(marker) + if len(first) >= wanted: + return first[:wanted] + chosen = {id(marker) for marker in first} + rest = [marker for marker in markers if id(marker) not in chosen] + return (first + rest)[:wanted] + + def main() -> int: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--geno", required=True, help="a GN .geno file to convert") @@ -57,13 +77,14 @@ def main() -> int: header = ["marker", "chr", "pos", *kept, *added] with open(arguments.out, "w") as handle: handle.write("\t".join(header) + "\n") - for name, chr, pos, cells in markers[: arguments.markers]: + for name, chr, pos, cells in spread(markers, arguments.markers): # A new individual inherits the first kept individual's calls: a # valid value of the same kind, which is all the upload checks. row = [name, chr, pos, *cells[: len(kept)], *([cells[0]] * len(added))] handle.write("\t".join(row) + "\n") print(f"{arguments.out}: {len(kept)} kept + {len(added)} new individual(s), " - f"{min(arguments.markers, len(markers))} marker(s)", file=sys.stderr) + f"{len(spread(markers, arguments.markers))} marker(s) across chromosomes", + file=sys.stderr) return 0 -- cgit 1.4.1