diff --git a/.gitignore b/.gitignore index f06ac644..5a7c2dee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ src/*.o +src/*.gcda src/*.so src/*.dylib src/Makevars diff --git a/R/QtlDataset.R b/R/QtlDataset.R index 684f6724..c0620680 100644 --- a/R/QtlDataset.R +++ b/R/QtlDataset.R @@ -343,7 +343,9 @@ setMethod("getScaleResiduals", "QtlDataset", function(x) x@scaleResiduals) si <- x@genotypes@snpInfo snpMask <- nchar(as.character(si$A1[snpIdx])) == 1L & nchar(as.character(si$A2[snpIdx])) == 1L - snpIdx <- snpIdx[snpMask] + # which() (not snpMask directly) so any NA in the mask drops that variant + # rather than injecting an NA index that would corrupt the extracted block. + snpIdx <- snpIdx[which(snpMask)] if (length(snpIdx) == 0L) { return(list( geno = matrix(numeric(0), nrow = 0L, ncol = 0L, diff --git a/R/genotypeIo.R b/R/genotypeIo.R index a9cd187a..68c6d975 100644 --- a/R/genotypeIo.R +++ b/R/genotypeIo.R @@ -116,8 +116,12 @@ setMethod("readGenotypes", stop("Plink file not found: ", f) } + # colClasses = "character" so type.convert() never coerces a column: a bim + # whose allele column is uniformly "T"/"F" (e.g. all-A/T SNPs) would otherwise + # be read as logical TRUE/FALSE, silently corrupting A1/A2 (BP is cast to + # integer explicitly below). bim <- read.table(bimFile, header = FALSE, - stringsAsFactors = FALSE, + colClasses = "character", col.names = c("CHR", "SNP", "CM", "BP", "A1", "A2")) fam <- read.table(famFile, header = FALSE, stringsAsFactors = FALSE) sampleIds <- as.character(fam[, 2]) # IID column