diff options
| author | Pjotr <wrk@bosa.lan> | 2026-11-09 22:28:20 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-11-09 22:28:22 +0000 |
| commit | 7646276e63fb7c4a7433530cfc3314ace3d362d8 (patch) | |
| tree | 18a0e233b30748bb433669716b8b88e502af44d9 /scripts | |
| parent | dc3e0e5ba0fa6f9462d55e9ca9a4802a60eb205f (diff) | |
| download | genenetwork4-7646276e63fb7c4a7433530cfc3314ace3d362d8.tar.gz | |
compute: R/qtl2 as a third scan, POST /compute/qtl2
R/qtl sits between the existing two scans: Haley-Knott on marker
genotypes, no kinship. GEMMA is an LMM but biallelic BIMBAM with
mean-imputed genotypes. Neither can analyse a multiparent population,
and neither models relatedness from the actual genotype data. R/qtl2
does both -- HMM genotype probabilities, then an LMM with
leave-one-chromosome-out kinship -- and it is what names the third peak
on DOL trait 10003 that R/qtl's scan cannot see (chr16, LOD 4.24,
against GEMMA's -log10 p 7.15 there).
* src/qtl2.rs converts this deployment's own .geno into a qtl2 cross
under QTL2_CACHE_DIR: control.json plus geno/gmap/pmap/pheno, with
the genotype-code map, the orientation and the paths written out
explicitly. The shipped genotype/rqtl2/ control files cannot be
used -- they point outside the data directory, declare no code map
(every genotype reads as missing) and no orientation (individuals
read as markers) -- and each of those produces a plausible flat
scan instead of an error, which is why the conversion is ours.
* Heterozygous calls are dropped on a riself panel, as R/qtl's
convert2riself does. Left in, qtl2 reads the cross as multiparent
and its scan1 takes a path the panel cannot satisfy ("Error in
scan1_pg ... : No individuals in common").
* Autosomes only: X needs a sex covariate to be fitted properly and
Y/MT degenerate the per-chromosome kinship. GEMMA's LOCO scan is
restricted the same way. The note says how many markers were left
out.
* scripts/qtl2_scan.R caches genotype probabilities and kinship by a
hash of the control file *and its directory*; two conversions of
the same panel can have identical control files and identical file
sizes, and reusing the first one's probabilities silently scans the
wrong cross. It also takes the individual names from whichever
shape the cross's pheno slot has -- a single-column pheno file
leaves it a plain matrix, and the resulting empty phenotype reads
as scan1's "No individuals in common".
* Rows are marker, chr, pos, lod, so /plot/rqtl draws the reply
unchanged -- post the same samples as /compute/rqtl.
* tests/qtl2.rs: the fixture scans and its notes name the cross; BXD
trait 10001 peaks on chr8 under both scans; refusals carry
missing_genotype / invalid_kinship.
cost: 2 concurrent scans, gated from RQTL_LARGE_PANEL individuals like
R/qtl; a DO cross costs minutes of genotype probabilities, paid once
per panel. QTL2_SCRIPT_PATH and QTL2_CACHE_DIR configure it.
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/qtl2_scan.R | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/scripts/qtl2_scan.R b/scripts/qtl2_scan.R index 258eae0..6c0d355 100755 --- a/scripts/qtl2_scan.R +++ b/scripts/qtl2_scan.R @@ -61,7 +61,11 @@ say <- function(...) if (!opt$quiet) cat(..., "\n") cache_stem <- NULL if (!is.null(opt[["cache-dir"]])) { control <- jsonlite::fromJSON(opt$control, simplifyVector = FALSE) - parts <- list(control) + # The control file's own directory is part of the key: two conversions of + # the same panel (an older one in another cache directory, say) can have + # identical control files and identical file sizes, and reusing the first + # one's probabilities silently scans the wrong cross. + parts <- list(dirname(normalizePath(opt$control, mustWork = FALSE)), control) for (key in c("geno", "founder_geno", "gmap", "pmap", "pheno", "covar")) { path <- control[[key]] if (!is.null(path)) { @@ -127,7 +131,15 @@ if (opt$kinship != "none") { # ---- phenotype and covariates, aligned by name ------------------------ df <- read.table(opt$pheno, na.strings = "x", header = TRUE, check.names = FALSE) trait_name <- colnames(df)[2] +# The cross's individuals, whatever shape its pheno slot takes: a matrix +# with rownames when the cross file carries several phenotypes, a named +# vector for one, and neither when the pheno file holds a single column -- +# in which case the genotype matrix's row names are the individuals. An +# empty `ind` produced an empty phenotype and scan1's "No individuals in +# common", which reads like a data problem rather than a shape one. ind <- rownames(cross$pheno) +if (is.null(ind)) ind <- names(cross$pheno) +if (is.null(ind)) ind <- rownames(cross$geno[[1]]) values <- df[[2]][match(ind, df$Sample)] if (all(is.na(values))) { stop("none of the phenotype file's samples appear in the cross", call.=FALSE) @@ -179,7 +191,11 @@ in_mb <- !is.null(cross$pmap) rows <- list() for (chr_name in names(map)) { positions <- map[[chr_name]] - markers <- names(positions) + # qtl2 drops markers it cannot use (all-missing genotypes, say); scanning + # them by name would be "subscript out of bounds". + markers <- intersect(names(positions), rownames(scan)) + if (length(markers) == 0) next + positions <- positions[markers] lod <- scan[markers, 1] if (in_mb) positions <- positions / 1e6 rows[[length(rows) + 1]] <- data.frame( |
