about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/qtl2_scan.R20
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(