diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/qtl2-convert-geno.R | 18 |
1 files changed, 14 insertions, 4 deletions
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)) |
