From 14622e57629d19451cad03f4a69fdd89e81a433f Mon Sep 17 00:00:00 2001 From: Pjotr Date: Tue, 17 Nov 2026 16:05:11 +0000 Subject: qtl2: the .geno conversion is an R script now, and the Rust writer is gone The conversion wrote qtl2's control file and CSVs by hand in Rust. Its output is an R/qtl2 cross, so the script does it and write_control_file describes it: one implementation of the format, qtl2's. What Rust keeps is the endpoint's own limit -- a .geno panel carries no founder genotypes, so a multiparent crosstype is a 422 with a reason, and the cross type follows @type and the heterozygous policy. prepare_cross now runs Rscript scripts/qtl2-convert-geno.R --geno GROUP.geno --out DIR --het drop|keep --crosstype riself|f2 writes the cross into the same versioned cache directory (now v6: the files it writes are qtl2's own layout), and reads back the report the script leaves beside it -- markers, non-autosomal, individuals, het_dropped, cells -- instead of counting them itself. A failed conversion reports R's own complaint. New configuration key QTL2_CONVERT_SCRIPT (default scripts/qtl2-convert-geno.R). The Rust writer's 250 lines are deleted, along with count_calls and metadata_het. Measured, BXD trait 10001 on the same request: before (Rust, alleles 1/3) top rsm10000005730 chr8 LOD 3.685 after (R/qtl2, alleles 1/2) top rs32579649 chr8 LOD 3.8917, rsm10000005700 3.8916 GEMMA LMM, same trait rsm10000005700 p 5.90e-07 so the wrong allele code was flattening this endpoint's own scan too: it still found chromosome 8, at a neighbouring marker and 0.21 LOD lower, with the marker GEMMA picks not in its top three. The two engines now agree on the locus. Cost: 38.3 s cold for 20453 autosomal markers (the R conversion is ~35 s of it), 3.5 s with the cross cached. --- scripts/qtl2-convert-geno.R | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/qtl2-convert-geno.R b/scripts/qtl2-convert-geno.R index c688930..48b4779 100755 --- a/scripts/qtl2-convert-geno.R +++ b/scripts/qtl2-convert-geno.R @@ -31,7 +31,7 @@ get <- function(flag, default = NULL) { geno_path <- get("--geno") out_dir <- get("--out") het <- match.arg(get("--het", "drop"), c("drop", "keep")) -crosstype <- match.arg(get("--crosstype", "riself"), c("riself", "f2")) +crosstype <- get("--crosstype") if (is.null(geno_path) || is.null(out_dir)) { stop("usage: qtl2-convert-geno.R --geno GROUP.geno --out DIR [--het drop|keep] [--crosstype riself|f2]", call. = FALSE) @@ -44,7 +44,7 @@ meta <- function(key) { } # The allele letters are declared by the file, not assumed: GeneNetwork panels # use B/D as often as A/B. -mat <- meta("mat"); pat <- meta("pat"); het_code <- meta("het") +mat <- meta("mat"); pat <- meta("pat"); het_code <- meta("het"); type <- meta("type") if (is.null(mat) || is.null(pat)) { stop("the .geno header declares no @mat/@pat codes, so its genotypes cannot be coded", call. = FALSE) @@ -59,12 +59,12 @@ body <- lines[!startsWith(lines, "#") & lines != hdr] autosomes <- as.character(1:19) geno <- list(); gmap <- list(); pmap <- list() -dropped <- 0L +dropped <- 0L; non_autosomal <- 0L; markers_seen <- 0L for (line in body) { f <- strsplit(line, "\t")[[1]] if (length(f) < 5) next chr <- f[1] - if (!(chr %in% autosomes)) next + if (!(chr %in% autosomes)) { non_autosomal <- non_autosomal + 1L; next } marker <- f[2] calls <- f[-(1:4)] # A call is A, B or (if the heterozygous class is kept) H; anything else -- @@ -78,6 +78,7 @@ for (line in body) { } calls[!(calls %in% c("A", "B", "H"))] <- "" geno[[marker]] <- calls + markers_seen <- markers_seen + 1L gmap[[marker]] <- c(chr = chr, pos = suppressWarnings(as.numeric(f[3]))) pmap[[marker]] <- c(chr = chr, pos = suppressWarnings(as.numeric(f[4])) * 1e6) } @@ -130,6 +131,15 @@ write_control_file( na.strings = "", geno_codes = codes, overwrite = TRUE) +# The report the caller reads back: what this cross holds, and what the +# conversion dropped. It is written beside the cross so a cached one costs +# nothing. +writeLines(jsonlite::toJSON(list( + crosstype = crosstype, markers = length(geno), non_autosomal = non_autosomal, + individuals = as.list(individuals), het_dropped = dropped, + cells = length(individuals) * length(geno)), auto_unbox = TRUE), + file.path(out_dir, "conversion.json")) + cat(sprintf("geno2cross: %d markers, %d individuals, %d heterozygous calls %s, crosstype %s -> %s\n", length(geno), length(individuals), dropped, if (het == "drop") "dropped" else "kept", crosstype, out_dir)) -- cgit 1.4.1