From c6fb28e73ed0e19171dba8f32a2cbfdf8d926da9 Mon Sep 17 00:00:00 2001 From: Rohan Shah Date: Thu, 24 Mar 2016 12:14:28 +1000 Subject: [PATCH] Fixed spelling, other bugs found using R CMD check --- DESCRIPTION | 9 ++++-- DESCRIPTION.in | 6 ++-- R/biparentalDominant.R | 2 +- R/detailedPedigree-class.R | 6 ++++ R/estimateMap.R | 2 -- R/mpcross.R | 2 +- R/roxygen.R | 3 ++ src/estimateRFSpecificDesign.cpp | 2 +- src/estimateRFSpecificDesign.h | 2 +- src/imputeFounders.cpp | 30 +++++++++---------- src/probabilities16.h | 2 +- src/probabilities2.cpp | 8 ++--- src/probabilities2.h | 2 +- src/probabilities4.h | 2 +- src/probabilities8.h | 2 +- src/recodeFoundersFinalsHets.cpp | 2 +- src/viterbiFiniteSelfing.hpp | 24 +++++++-------- src/viterbiInfiniteSelfing.hpp | 2 +- tests/slow/test-estimateRf2Parent.R | 2 +- tests/slow/test-estimateRf8Parent.R | 2 +- tests/testthat/test-estimateRFInternal.R | 2 +- tests/testthat/test-geneticDataValidation.R | 2 +- ...st-imputeFounders4ParentFiniteIntercross.R | 6 ++-- ...t-imputeFounders4ParentFiniteNoIntecross.R | 6 ++-- 24 files changed, 71 insertions(+), 57 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6ae7b6f..acbf983 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,10 +17,12 @@ Depends: igraph, Rcpp, fastcluster, - pryr + pryr, + nnls Imports: ggplot2, - Matrix + Matrix, + methods LinkingTo: Rcpp Collate: 'Rcpp_exceptions.R' @@ -34,6 +36,7 @@ Collate: 'mpcross-class.R' 'biparentalDominant.R' 'combineGenotypes.R' + 'compressedProbabilities.R' 'detailedPedigree-class.R' 'eightWayPedigreeRandomFunnels.R' 'eightWayPedigreeSingleFunnel.R' @@ -42,6 +45,7 @@ Collate: 'expand.R' 'f2Pedigree.R' 'finals.R' + 'fixedNumberOfFounderAlleles.R' 'formGroups.R' 'founders.R' 'fourParentPedigreeRandomFunnels.R' @@ -50,6 +54,7 @@ Collate: 'hetData.R' 'impute.R' 'imputeFounders.R' + 'jitterMap.R' 'mapFunctions.R' 'markers.R' 'mpcross.R' diff --git a/DESCRIPTION.in b/DESCRIPTION.in index 31367d5..0c0a02c 100644 --- a/DESCRIPTION.in +++ b/DESCRIPTION.in @@ -15,7 +15,9 @@ Depends: methods, igraph, fastcluster, - pryr + pryr, + nnls Imports: ggplot2, - Matrix + Matrix, + methods diff --git a/R/biparentalDominant.R b/R/biparentalDominant.R index 7c7db73..bb5d78f 100644 --- a/R/biparentalDominant.R +++ b/R/biparentalDominant.R @@ -11,7 +11,7 @@ setClass("biparentalDominant", contains="NULL") #' cross <- simulateMPCross(map = map, pedigree = f2Pedigree, mapFunction = haldane, seed = 1) #' founders(cross) #' finals(cross)[1:10,] -#' The heterozygotes are initially coded as 3 +#' #The heterozygotes are initially coded as 3 #' hetData(cross)[[1]] #' #Make all markers dominant #' dominantCross <- cross + biparentalDominant() diff --git a/R/detailedPedigree-class.R b/R/detailedPedigree-class.R index 2b4ad63..0b25694 100644 --- a/R/detailedPedigree-class.R +++ b/R/detailedPedigree-class.R @@ -74,6 +74,12 @@ NULL .detailedPedigree <- setClass("detailedPedigree", contains = "pedigree", slots = list(initial = "integer", observed = "logical"), validity = checkDetailedPedigree) #' @export #' @describeIn detailedPedigree-class Construct object of class detailedPedigree +#' @param lineNames The names assigned to the lines +#' @param mother The female parent of this line +#' @param father The male parent of this line +#' @param initial The indices of the founder lines in the pedigree +#' @param observed A logical vector determining which lines are observed in the final population +#' @param selfing Value determining whether or not subsequent analysis of populations generated from this pedigree should assume infinite generations of selfing. Possible values are \code{"finite"} and \code{"infinite"}. detailedPedigree <- function(lineNames, mother, father, initial, observed, selfing) { mother <- as.integer(mother) diff --git a/R/estimateMap.R b/R/estimateMap.R index 7b031ac..f372b0e 100644 --- a/R/estimateMap.R +++ b/R/estimateMap.R @@ -36,8 +36,6 @@ estimateMap <- function(mpcrossLG, mapFunction = rfToHaldane, maxOffset = 1) b <- rfData[indices] #Values of 0.5 result in infinite estimated distance, which doesn't really work. b[b == 0.5] <- 0.49 - if (!requireNamespace("nnls", quietly=TRUE)) - stop("nnls needed for computemap to work. Please install it.\n", call.=FALSE) result <- nnls::nnls(d, mapFunction(b)) map[[as.character(group)]] <- c(0, cumsum(result$x[which(indices[,1] == indices[,2]+1)])) names(map[[as.character(group)]]) <- rfData@markers diff --git a/R/mpcross.R b/R/mpcross.R index 1325666..b2b759f 100644 --- a/R/mpcross.R +++ b/R/mpcross.R @@ -134,7 +134,7 @@ setMethod(f = "+", signature = c("mpcrossRF", "mpcross"), definition = function( stop("Internal error: Markers should have been combined as two blocks") } marker2Range <- range(match(markers(e2), markers(combined))) - extraRFData <- estimateRFInternal(object = combined, recombValues = e1@rf@r, lineWeights = rep(1, nLines(e2)), marker1Range = marker1Range, marker2Range = marker2Range, keepLod = keepLod, keepLkhd = keepLkhd, gbLimit = e1@rf@gbLimit, verbose = list(verbose = FALSE, progressStyle = 1L)) + extraRFData <- estimateRFInternal(object = combined, recombValues = e1@rf@r, lineWeights = rep(1, nLines(e2)), markerRows = marker1Range, markerColumns = marker2Range, keepLod = keepLod, keepLkhd = keepLkhd, gbLimit = e1@rf@gbLimit, verbose = list(verbose = FALSE, progressStyle = 1L)) stop("Need to check this section") } #If the markers are all the same, keep them in the same order diff --git a/R/roxygen.R b/R/roxygen.R index 2c013d0..5b56c64 100644 --- a/R/roxygen.R +++ b/R/roxygen.R @@ -1,9 +1,12 @@ #' @import qtl #' @import igraph +#' @import methods #' @importFrom pryr address +#' @importFrom nnls nnls #' @exportClass pedigreeGraph #' @exportMethod subset #' @exportMethod plot #' @importClassesFrom Matrix index dspMatrix dppMatrix +#' @importFrom methods setClass #' @useDynLib mpMap2 NULL diff --git a/src/estimateRFSpecificDesign.cpp b/src/estimateRFSpecificDesign.cpp index 80e6ba7..e4a1567 100644 --- a/src/estimateRFSpecificDesign.cpp +++ b/src/estimateRFSpecificDesign.cpp @@ -733,7 +733,7 @@ bool toInternalArgs(estimateRFSpecificDesignArgs&& args, rfhaps_internal_args& i { try { - Rcpp::Rcout << "Input data had hetrozygotes but was analysed assuming infinite selfing. " << std::endl << " All hetrozygotes were ignored." << std::endl; + Rcpp::Rcout << "Input data had heterozygotes but was analysed assuming infinite selfing. " << std::endl << " All hetrozygotes were ignored." << std::endl; } catch(...) {} diff --git a/src/estimateRFSpecificDesign.h b/src/estimateRFSpecificDesign.h index 7ea159e..f3706c7 100644 --- a/src/estimateRFSpecificDesign.h +++ b/src/estimateRFSpecificDesign.h @@ -62,7 +62,7 @@ bool estimateRFSpecificDesign(rfhaps_internal_args& internal_args, unsigned long * 3. Check that the data is consistent with the input funnels. * 4. Recode the founders and finals data in a normalised form, also working out the maximum number of alleles per marker, across the dataset * 5. Assign a unique value to each marker pattern and funnel. - * 6. In the case of infinite generations of selfing, replace hetrozygote values with NA. + * 6. In the case of infinite generations of selfing, replace heterozygote values with NA. * @param args Input arguments * @param internalArgs preprocessed arguments * @return A boolean value, with true indicating success. False indicates an error. diff --git a/src/imputeFounders.cpp b/src/imputeFounders.cpp index 8c88005..9344c3b 100644 --- a/src/imputeFounders.cpp +++ b/src/imputeFounders.cpp @@ -14,7 +14,7 @@ #include "funnelHaplotypeToMarker.hpp" #include "viterbi.hpp" #include "recodeHetsAsNA.h" -template void imputedFoundersInternal2(Rcpp::IntegerMatrix founders, Rcpp::IntegerMatrix finals, Rcpp::S4 pedigree, Rcpp::List hetData, Rcpp::List map, Rcpp::IntegerMatrix results, double homozygoteMissingProb, double hetrozygoteMissingProb, Rcpp::IntegerMatrix key) +template void imputedFoundersInternal2(Rcpp::IntegerMatrix founders, Rcpp::IntegerMatrix finals, Rcpp::S4 pedigree, Rcpp::List hetData, Rcpp::List map, Rcpp::IntegerMatrix results, double homozygoteMissingProb, double heterozygoteMissingProb, Rcpp::IntegerMatrix key) { //Work out maximum number of markers per chromosome int maxChromosomeMarkers = 0; @@ -66,7 +66,7 @@ template void imputedFoundersInternal2(Rcpp //Technically a warning could lead to an error if options(warn=2). This would be bad because it would break out of our code. This solution generates a c++ exception in that case, which we can then ignore. try { - warning("Input data had hetrozygotes but was analysed assuming infinite selfing. All hetrozygotes were ignored. \n"); + warning("Input data had heterozygotes but was analysed assuming infinite selfing. All heterozygotes were ignored. \n"); } catch(...) {} @@ -157,7 +157,7 @@ template void imputedFoundersInternal2(Rcpp viterbi.results = results; viterbi.key = key; viterbi.homozygoteMissingProb = homozygoteMissingProb; - viterbi.hetrozygoteMissingProb = hetrozygoteMissingProb; + viterbi.heterozygoteMissingProb = heterozygoteMissingProb; viterbi.intercrossingSingleLociHaplotypeProbabilities = &intercrossingSingleLociHaplotypeProbabilities; viterbi.funnelSingleLociHaplotypeProbabilities = &funnelSingleLociHaplotypeProbabilities; @@ -188,18 +188,18 @@ template void imputedFoundersInternal2(Rcpp cumulativeMarkerCounter += (int)positions.size(); } } -template void imputedFoundersInternal1(Rcpp::IntegerMatrix founders, Rcpp::IntegerMatrix finals, Rcpp::S4 pedigree, Rcpp::List hetData, Rcpp::List map, Rcpp::IntegerMatrix results, bool infiniteSelfing, double homozygoteMissingProb, double hetrozygoteMissingProb, Rcpp::IntegerMatrix key) +template void imputedFoundersInternal1(Rcpp::IntegerMatrix founders, Rcpp::IntegerMatrix finals, Rcpp::S4 pedigree, Rcpp::List hetData, Rcpp::List map, Rcpp::IntegerMatrix results, bool infiniteSelfing, double homozygoteMissingProb, double heterozygoteMissingProb, Rcpp::IntegerMatrix key) { if(infiniteSelfing) { - imputedFoundersInternal2(founders, finals, pedigree, hetData, map, results, homozygoteMissingProb, hetrozygoteMissingProb, key); + imputedFoundersInternal2(founders, finals, pedigree, hetData, map, results, homozygoteMissingProb, heterozygoteMissingProb, key); } else { - imputedFoundersInternal2(founders, finals, pedigree, hetData, map, results, homozygoteMissingProb, hetrozygoteMissingProb, key); + imputedFoundersInternal2(founders, finals, pedigree, hetData, map, results, homozygoteMissingProb, heterozygoteMissingProb, key); } } -SEXP imputeFounders(SEXP geneticData_sexp, SEXP map_sexp, SEXP homozygoteMissingProb_sexp, SEXP hetrozygoteMissingProb_sexp) +SEXP imputeFounders(SEXP geneticData_sexp, SEXP map_sexp, SEXP homozygoteMissingProb_sexp, SEXP heterozygoteMissingProb_sexp) { BEGIN_RCPP Rcpp::S4 geneticData; @@ -296,16 +296,16 @@ BEGIN_RCPP } if(homozygoteMissingProb < 0 || homozygoteMissingProb > 1) throw std::runtime_error("Input homozygoteMissingProb must be a number between 0 and 1"); - double hetrozygoteMissingProb; + double heterozygoteMissingProb; try { - hetrozygoteMissingProb = Rcpp::as(hetrozygoteMissingProb_sexp); + heterozygoteMissingProb = Rcpp::as(heterozygoteMissingProb_sexp); } catch(...) { - throw std::runtime_error("Input hetrozygoteMissingProb must be a number between 0 and 1"); + throw std::runtime_error("Input heterozygoteMissingProb must be a number between 0 and 1"); } - if(hetrozygoteMissingProb < 0 || hetrozygoteMissingProb > 1) throw std::runtime_error("Input hetrozygoteMissingProb must be a number between 0 and 1"); + if(heterozygoteMissingProb < 0 || heterozygoteMissingProb > 1) throw std::runtime_error("Input heterozygoteMissingProb must be a number between 0 and 1"); std::vector foundersMarkers = Rcpp::as >(Rcpp::colnames(founders)); std::vector finalsMarkers = Rcpp::as >(Rcpp::colnames(finals)); @@ -378,19 +378,19 @@ BEGIN_RCPP { if(nFounders == 2) { - imputedFoundersInternal1<2>(founders, finals, pedigree, hetData, map, results, infiniteSelfing, homozygoteMissingProb, hetrozygoteMissingProb, key); + imputedFoundersInternal1<2>(founders, finals, pedigree, hetData, map, results, infiniteSelfing, homozygoteMissingProb, heterozygoteMissingProb, key); } else if(nFounders == 4) { - imputedFoundersInternal1<4>(founders, finals, pedigree, hetData, map, results, infiniteSelfing, homozygoteMissingProb, hetrozygoteMissingProb, key); + imputedFoundersInternal1<4>(founders, finals, pedigree, hetData, map, results, infiniteSelfing, homozygoteMissingProb, heterozygoteMissingProb, key); } else if(nFounders == 8) { - imputedFoundersInternal1<8>(founders, finals, pedigree, hetData, map, results, infiniteSelfing, homozygoteMissingProb, hetrozygoteMissingProb, key); + imputedFoundersInternal1<8>(founders, finals, pedigree, hetData, map, results, infiniteSelfing, homozygoteMissingProb, heterozygoteMissingProb, key); } else if(nFounders == 16) { - imputedFoundersInternal1<16>(founders, finals, pedigree, hetData, map, results, infiniteSelfing, homozygoteMissingProb, hetrozygoteMissingProb, key); + imputedFoundersInternal1<16>(founders, finals, pedigree, hetData, map, results, infiniteSelfing, homozygoteMissingProb, heterozygoteMissingProb, key); } else { diff --git a/src/probabilities16.h b/src/probabilities16.h index 5b9f6cd..acd9a71 100644 --- a/src/probabilities16.h +++ b/src/probabilities16.h @@ -6,7 +6,7 @@ template<> struct probabilityData<16> public: /*See Karl Bromans paper on intermediate generations. This mask converts allele encodings (0 - 2) into indices into the array of 4 different probabilities. In terms of indices, - Zero = homozygote, One = other homozygote, Two = hetrozygote + Zero = homozygote, One = other homozygote, Two = heterozygote In terms of values, see Table one of the paper. Zero = first equation of table, one = second equation, etc. Note that we combine equations 4 and 5 into a single state. */ diff --git a/src/probabilities2.cpp b/src/probabilities2.cpp index cc32fa9..d3b307b 100644 --- a/src/probabilities2.cpp +++ b/src/probabilities2.cpp @@ -30,14 +30,14 @@ template<> void genotypeProbabilitiesNoIntercross<2, false>(std::array void genotypeProbabilitiesWithIntercross<2, false>(std::array void singleLocusGenotypeProbabilitiesNoIntercross<2, true>(array2<2>&data, int selfingGenerations, std::size_t nFunnels) diff --git a/src/probabilities2.h b/src/probabilities2.h index 591a885..9186399 100644 --- a/src/probabilities2.h +++ b/src/probabilities2.h @@ -6,7 +6,7 @@ template<> struct probabilityData<2> public: /*See Karl Bromans paper on intermediate generations. This mask converts allele encodings (0 - 2) into indices into the array of 4 different probabilities. In terms of indices, - Zero = homozygote, One = other homozygote, Two = hetrozygote + Zero = homozygote, One = other homozygote, Two = heterozygote In terms of values, see Table one of the paper. Zero = first equation of table, one = second equation, etc. Note that we combine equations 4 and 5 into a single state. */ diff --git a/src/probabilities4.h b/src/probabilities4.h index b2d2828..ac46bdf 100644 --- a/src/probabilities4.h +++ b/src/probabilities4.h @@ -6,7 +6,7 @@ template<> struct probabilityData<4> public: /*See Karl Bromans paper on intermediate generations. This mask converts allele encodings (0 - 2) into indices into the array of 4 different probabilities. In terms of indices, - Zero = homozygote, One = other homozygote, Two = hetrozygote + Zero = homozygote, One = other homozygote, Two = heterozygote In terms of values, see Table one of the paper. Zero = first equation of table, one = second equation, etc. Note that we combine equations 4 and 5 into a single state. */ diff --git a/src/probabilities8.h b/src/probabilities8.h index 4c939d4..17d5b3c 100644 --- a/src/probabilities8.h +++ b/src/probabilities8.h @@ -6,7 +6,7 @@ template<> struct probabilityData<8> public: /*See Karl Bromans paper on intermediate generations. This mask converts allele encodings (0 - 2) into indices into the array of 4 different probabilities. In terms of indices, - Zero = homozygote, One = other homozygote, Two = hetrozygote + Zero = homozygote, One = other homozygote, Two = heterozygote In terms of values, see Table one of the paper. Zero = first equation of table, one = second equation, etc. Note that we combine equations 4 and 5 into a single state. */ diff --git a/src/recodeFoundersFinalsHets.cpp b/src/recodeFoundersFinalsHets.cpp index a0b0150..c3c5651 100644 --- a/src/recodeFoundersFinalsHets.cpp +++ b/src/recodeFoundersFinalsHets.cpp @@ -52,7 +52,7 @@ void recodeFoundersFinalsHets(recodeDataStruct& inputs) recodedCurrentMarkerHetData(i, 2) = recodedCurrentMarkerHetData(i, 0); } } - //The homozygotes get translated as-is, the hetrozygotes are given sequential labels afterwards. + //The homozygotes get translated as-is, the heterozygotes are given sequential labels afterwards. std::sort(hetValues.begin(), hetValues.end()); hetValues.erase(std::unique(hetValues.begin(), hetValues.end()), hetValues.end()); inputs.maxAlleles = std::max(inputs.maxAlleles, (unsigned int)(nFounderAlleles + hetValues.size())); diff --git a/src/viterbiFiniteSelfing.hpp b/src/viterbiFiniteSelfing.hpp index 1dcfff6..db30c56 100644 --- a/src/viterbiFiniteSelfing.hpp +++ b/src/viterbiFiniteSelfing.hpp @@ -35,7 +35,7 @@ template struct viterbiAlgorithm int minAIGenerations; int maxAIGenerations; Rcpp::IntegerMatrix key; - double hetrozygoteMissingProb, homozygoteMissingProb; + double heterozygoteMissingProb, homozygoteMissingProb; std::vector >* intercrossingSingleLociHaplotypeProbabilities; std::vector >* funnelSingleLociHaplotypeProbabilities; viterbiAlgorithm(markerPatternsToUniqueValuesArgs& markerData, xMajorMatrix& intercrossingHaplotypeProbabilities, rowMajorMatrix& funnelHaplotypeProbabilities, int maxChromosomeSize) @@ -51,7 +51,7 @@ template struct viterbiAlgorithm int nFinals = recodedFinals.nrow(); //If there's not meant to be any missing values, check that first - if(homozygoteMissingProb == 0 && hetrozygoteMissingProb == 0) + if(homozygoteMissingProb == 0 && heterozygoteMissingProb == 0) { for(int finalCounter = 0; finalCounter < nFinals; finalCounter++) { @@ -59,7 +59,7 @@ template struct viterbiAlgorithm { if(recodedFinals(finalCounter, markerCounter) == NA_INTEGER) { - throw std::runtime_error("Inputs hetrozygoteMissingProb and homozygoteMissingProb imply that missing values are not allowed"); + throw std::runtime_error("Inputs heterozygoteMissingProb and homozygoteMissingProb imply that missing values are not allowed"); } } } @@ -85,7 +85,7 @@ template struct viterbiAlgorithm void applyFunnel(int start, int end, int finalCounter, int funnelID, int selfingGenerations) { double logHomozygoteMissingProb = log(homozygoteMissingProb); - double logHetrozygoteMissingProb = log(hetrozygoteMissingProb); + double logHetrozygoteMissingProb = log(heterozygoteMissingProb); //Initialise the algorithm funnelEncoding enc = (*lineFunnelEncodings)[(*lineFunnelIDs)[finalCounter]]; int funnel[16]; @@ -106,7 +106,7 @@ template struct viterbiAlgorithm int markerEncodingTheseFounders = startMarkerData.hetData(funnel[founderCounter], funnel[founderCounter2]); int encodingTheseFounders = key(funnel[founderCounter], funnel[founderCounter2]); intermediate1(encodingTheseFounders, 0) = encodingTheseFounders; - if(markerEncodingTheseFounders == startMarkerValue || (startMarkerValue == NA_INTEGER && ((recodedFounders(funnel[founderCounter2], start) == recodedFounders(funnel[founderCounter], start) && homozygoteMissingProb != 0) || (recodedFounders(funnel[founderCounter2], start) != recodedFounders(funnel[founderCounter], start) && hetrozygoteMissingProb != 0)))) + if(markerEncodingTheseFounders == startMarkerValue || (startMarkerValue == NA_INTEGER && ((recodedFounders(funnel[founderCounter2], start) == recodedFounders(funnel[founderCounter], start) && homozygoteMissingProb != 0) || (recodedFounders(funnel[founderCounter2], start) != recodedFounders(funnel[founderCounter], start) && heterozygoteMissingProb != 0)))) { pathLengths2[encodingTheseFounders] = pathLengths1[encodingTheseFounders] = (*funnelSingleLociHaplotypeProbabilities)[selfingGenerations - minSelfingGenerations].values[founderCounter][founderCounter2]; } @@ -130,7 +130,7 @@ template struct viterbiAlgorithm { int encodingMarker = currentMarkerData.hetData(funnel[founderCounter], funnel[founderCounter2]); int encodingTheseFounders = key(funnel[founderCounter], funnel[founderCounter2]); - if(encodingMarker == markerValue || (markerValue == NA_INTEGER && ((recodedFounders(funnel[founderCounter2], markerCounter) == recodedFounders(funnel[founderCounter], markerCounter) && homozygoteMissingProb != 0) || (recodedFounders(funnel[founderCounter2], markerCounter) != recodedFounders(funnel[founderCounter], markerCounter) && hetrozygoteMissingProb != 0)))) + if(encodingMarker == markerValue || (markerValue == NA_INTEGER && ((recodedFounders(funnel[founderCounter2], markerCounter) == recodedFounders(funnel[founderCounter], markerCounter) && homozygoteMissingProb != 0) || (recodedFounders(funnel[founderCounter2], markerCounter) != recodedFounders(funnel[founderCounter], markerCounter) && heterozygoteMissingProb != 0)))) { //Founder at the previous marker. std::fill(working.begin(), working.end(), -std::numeric_limits::infinity()); @@ -140,7 +140,7 @@ template struct viterbiAlgorithm { int encodingPreviousMarker = previousMarkerData.hetData(funnel[founderPreviousCounter], funnel[founderPreviousCounter2]); int encodingPreviousTheseFounders = key(funnel[founderPreviousCounter], funnel[founderPreviousCounter2]); - if(encodingPreviousMarker == previousMarkerValue || (previousMarkerValue == NA_INTEGER && ((recodedFounders(funnel[founderPreviousCounter2], markerCounter) == recodedFounders(funnel[founderPreviousCounter], markerCounter) && homozygoteMissingProb != 0) || (recodedFounders(funnel[founderPreviousCounter2], markerCounter) != recodedFounders(funnel[founderPreviousCounter], markerCounter) && hetrozygoteMissingProb != 0)))) + if(encodingPreviousMarker == previousMarkerValue || (previousMarkerValue == NA_INTEGER && ((recodedFounders(funnel[founderPreviousCounter2], markerCounter) == recodedFounders(funnel[founderPreviousCounter], markerCounter) && homozygoteMissingProb != 0) || (recodedFounders(funnel[founderPreviousCounter2], markerCounter) != recodedFounders(funnel[founderPreviousCounter], markerCounter) && heterozygoteMissingProb != 0)))) { double multiple = 0; if(founderCounter != founderCounter2) multiple += log(2); @@ -162,7 +162,7 @@ template struct viterbiAlgorithm } //Get the shortest one, and check that it's not negative infinity. std::vector::iterator longest = std::max_element(working.begin(), working.end()); - //This error is no longer valid, because some states are impossible to ever be in - E.g. hetrozygote {1,2} with funnel {1,2,3,4} and no intercrossing. In this case all the probabilities are zero and all the log probabilities are -inf. So *longest == -std::numeric_limits::infinity() doesn't indicate that there is no valid next state. It indicates that the state for the previous marker is impossible. + //This error is no longer valid, because some states are impossible to ever be in - E.g. heterozygote {1,2} with funnel {1,2,3,4} and no intercrossing. In this case all the probabilities are zero and all the log probabilities are -inf. So *longest == -std::numeric_limits::infinity() doesn't indicate that there is no valid next state. It indicates that the state for the previous marker is impossible. //if(*longest == -std::numeric_limits::infinity()) throw std::runtime_error("Internal error"); int bestPrevious = (int)std::distance(working.begin(), longest); @@ -210,7 +210,7 @@ template struct viterbiAlgorithm void applyIntercrossing(int start, int end, int finalCounter, int intercrossingGeneration, int selfingGenerations) { double logHomozygoteMissingProb = log(homozygoteMissingProb); - double logHetrozygoteMissingProb = log(hetrozygoteMissingProb); + double logHetrozygoteMissingProb = log(heterozygoteMissingProb); //Initialise the algorithm int startMarkerValue = recodedFinals(finalCounter, start); ::markerData& startMarkerData = markerData.allMarkerPatterns[markerData.markerPatternIDs[start]]; @@ -225,7 +225,7 @@ template struct viterbiAlgorithm int markerEncodingTheseFounders = startMarkerData.hetData(founderCounter, founderCounter2); int encodingTheseFounders = key(founderCounter, founderCounter2); intermediate1(encodingTheseFounders, 0) = encodingTheseFounders; - if(markerEncodingTheseFounders == startMarkerValue || (startMarkerValue == NA_INTEGER && ((recodedFounders(founderCounter2, start) == recodedFounders(founderCounter, start) && homozygoteMissingProb != 0) || (recodedFounders(founderCounter2, start) != recodedFounders(founderCounter, start) && hetrozygoteMissingProb != 0)))) + if(markerEncodingTheseFounders == startMarkerValue || (startMarkerValue == NA_INTEGER && ((recodedFounders(founderCounter2, start) == recodedFounders(founderCounter, start) && homozygoteMissingProb != 0) || (recodedFounders(founderCounter2, start) != recodedFounders(founderCounter, start) && heterozygoteMissingProb != 0)))) { pathLengths2[encodingTheseFounders] = pathLengths1[encodingTheseFounders] = (*intercrossingSingleLociHaplotypeProbabilities)[selfingGenerations - minSelfingGenerations].values[founderCounter][founderCounter2]; } @@ -249,7 +249,7 @@ template struct viterbiAlgorithm { int encodingMarker = currentMarkerData.hetData(founderCounter, founderCounter2); int encodingTheseFounders = key(founderCounter, founderCounter2); - if(encodingMarker == markerValue || (markerValue == NA_INTEGER && ((recodedFounders(founderCounter2, markerCounter) == recodedFounders(founderCounter, markerCounter) && homozygoteMissingProb != 0) || (recodedFounders(founderCounter2, markerCounter) != recodedFounders(founderCounter, markerCounter) && hetrozygoteMissingProb != 0)))) + if(encodingMarker == markerValue || (markerValue == NA_INTEGER && ((recodedFounders(founderCounter2, markerCounter) == recodedFounders(founderCounter, markerCounter) && homozygoteMissingProb != 0) || (recodedFounders(founderCounter2, markerCounter) != recodedFounders(founderCounter, markerCounter) && heterozygoteMissingProb != 0)))) { //Founder at the previous marker. std::fill(working.begin(), working.end(), -std::numeric_limits::infinity()); @@ -259,7 +259,7 @@ template struct viterbiAlgorithm { int encodingPreviousMarker = previousMarkerData.hetData(founderPreviousCounter, founderPreviousCounter2); int encodingPreviousTheseFounders = key(founderPreviousCounter, founderPreviousCounter2); - if(encodingPreviousMarker == previousMarkerValue || (previousMarkerValue == NA_INTEGER && ((recodedFounders(founderPreviousCounter2, markerCounter) == recodedFounders(founderPreviousCounter, markerCounter) && homozygoteMissingProb != 0) || (recodedFounders(founderPreviousCounter2, markerCounter) != recodedFounders(founderPreviousCounter, markerCounter) && hetrozygoteMissingProb != 0)))) + if(encodingPreviousMarker == previousMarkerValue || (previousMarkerValue == NA_INTEGER && ((recodedFounders(founderPreviousCounter2, markerCounter) == recodedFounders(founderPreviousCounter, markerCounter) && homozygoteMissingProb != 0) || (recodedFounders(founderPreviousCounter2, markerCounter) != recodedFounders(founderPreviousCounter, markerCounter) && heterozygoteMissingProb != 0)))) { double multiple = 0; if(founderCounter != founderCounter2) multiple += log(2); diff --git a/src/viterbiInfiniteSelfing.hpp b/src/viterbiInfiniteSelfing.hpp index b9de9f5..0f98cdf 100644 --- a/src/viterbiInfiniteSelfing.hpp +++ b/src/viterbiInfiniteSelfing.hpp @@ -33,7 +33,7 @@ template struct viterbiAlgorithm int minSelfingGenerations; int maxSelfingGenerations; int minAIGenerations, maxAIGenerations; - double hetrozygoteMissingProb, homozygoteMissingProb; + double heterozygoteMissingProb, homozygoteMissingProb; Rcpp::IntegerMatrix key; std::vector >* intercrossingSingleLociHaplotypeProbabilities; std::vector >* funnelSingleLociHaplotypeProbabilities; diff --git a/tests/slow/test-estimateRf2Parent.R b/tests/slow/test-estimateRf2Parent.R index 453bbae..a5763d8 100644 --- a/tests/slow/test-estimateRf2Parent.R +++ b/tests/slow/test-estimateRf2Parent.R @@ -50,7 +50,7 @@ test_that("Numerically accurate for a RIL design", distance <- distances[index] map <- getMap(distance) cross <- simulateMPCross(map=map, pedigree=pedigree, mapFunction = haldane) - #There is a warning that we're analysing a population with hetrozygotes as if hetrozygotes were impossible. + #There is a warning that we're analysing a population with heterozygotes as if heterozygotes were impossible. capture.output(suppressWarnings(rf <- estimateRF(cross, recombValues = c(haldaneToRf(distance), (0:100)/200), keepLod = TRUE, keepLkhd=TRUE))) expect_equal(rfToHaldane(rf@rf@theta[1,2]), distance, tolerance=tolerances[index]) expect_identical(rf@rf@theta[1,2], rf@rf@theta[2,1]) diff --git a/tests/slow/test-estimateRf8Parent.R b/tests/slow/test-estimateRf8Parent.R index 85e222d..4330abd 100644 --- a/tests/slow/test-estimateRf8Parent.R +++ b/tests/slow/test-estimateRf8Parent.R @@ -15,7 +15,7 @@ test_that("Numerically accurate with randomly chosen funnels", { map <- getMap(distance) cross <- simulateMPCross(map=map, pedigree=pedigree, mapFunction = haldane) - #Ignore the warning about residual hetrozygosity + #Ignore the warning about residual heterozygosity capture.output(rf <- estimateRF(cross, recombValues = c(haldaneToRf(distance), (0:100)/200), keepLod = TRUE, keepLkhd=TRUE)) expect_equal(rfToHaldane(rf@rf@theta[1,2]), distance, tolerance=0.02) expect_identical(rf@rf@theta[1,2], rf@rf@theta[2,1]) diff --git a/tests/testthat/test-estimateRFInternal.R b/tests/testthat/test-estimateRFInternal.R index cd56ef2..eaece4c 100644 --- a/tests/testthat/test-estimateRFInternal.R +++ b/tests/testthat/test-estimateRFInternal.R @@ -37,7 +37,7 @@ test_that("Arguments must have correct types", expect_that(estimateRFInternal(object = cross, recombValues = c(0.0, 0.5), lineWeights = list(1), markerRows = 1:2, markerColumns = 1:2, keepLod = TRUE, keepLkhd = list(), gbLimit = -1, verbose = NULL), throws_error("keepLkhd must be a boolean")) #verbose must be a boolean - expect_that(estimateRFInternal(object = cross, recombValues = c(0.0, 0.5), lineWeights = list(1), markerRows = 1:2, markerColumns = 1:2, keepLod = TRUE, keepLkhd = TRUE, gbLimit = -1, verbose = list()), throws_error("verbose must be a list")) + expect_that(estimateRFInternal(object = cross, recombValues = c(0.0, 0.5), lineWeights = list(1), markerRows = 1:2, markerColumns = 1:2, keepLod = TRUE, keepLkhd = TRUE, gbLimit = -1, verbose = list()), throws_error("verbose must be a")) #There must be at least one design copiedCross <- cross diff --git a/tests/testthat/test-geneticDataValidation.R b/tests/testthat/test-geneticDataValidation.R index 3a1b435..baa8253 100644 --- a/tests/testthat/test-geneticDataValidation.R +++ b/tests/testthat/test-geneticDataValidation.R @@ -250,7 +250,7 @@ test_that("Values in first two columns of hetData matrix must be founder alleles }) test_that("Values in finals must be valid according to hetData", { - #Remove hetrozygotes from hetData + #Remove heterozygotes from hetData copied <- geneticData indices <- copied@hetData[[1]][,1] == copied@hetData[[1]][,2] copied@hetData[[1]] <- copied@hetData[[1]][indices,] diff --git a/tests/testthat/test-imputeFounders4ParentFiniteIntercross.R b/tests/testthat/test-imputeFounders4ParentFiniteIntercross.R index 1261b7e..59f4ae6 100644 --- a/tests/testthat/test-imputeFounders4ParentFiniteIntercross.R +++ b/tests/testthat/test-imputeFounders4ParentFiniteIntercross.R @@ -1,5 +1,5 @@ context("Founder imputation, four parents, finite selfing, with intercrossing") -test_that("Test non-zero generations of intercrossing, with marker hetrozygotes", +test_that("Test non-zero generations of intercrossing, with marker heterozygotes", { testFunc <- function(pedigree, map) { @@ -50,7 +50,7 @@ test_that("Test non-zero generations of intercrossing, with marker hetrozygotes" } }) -test_that("Test non-zero generations of intercrossing, without marker hetrozygotes", +test_that("Test non-zero generations of intercrossing, without marker heterozygotes", { testFunc <- function(pedigree, map) { @@ -63,7 +63,7 @@ test_that("Test non-zero generations of intercrossing, without marker hetrozygot cross2 <- cross + multiparentSNP(keepHets=FALSE) mapped <- new("mpcrossMapped", cross2, map = map) - result <- imputeFounders(mapped, hetrozygoteMissingProb = 1, homozygoteMissingProb = 0.01) + result <- imputeFounders(mapped, heterozygoteMissingProb = 1, homozygoteMissingProb = 0.01) tmp <- table(result@geneticData[[1]]@imputed@data, cross@geneticData[[1]]@finals) #Correct imputation rate should be 0.925 expect_true(sum(diag(tmp)) / sum(tmp) > 0.9) diff --git a/tests/testthat/test-imputeFounders4ParentFiniteNoIntecross.R b/tests/testthat/test-imputeFounders4ParentFiniteNoIntecross.R index a85df89..f957978 100644 --- a/tests/testthat/test-imputeFounders4ParentFiniteNoIntecross.R +++ b/tests/testthat/test-imputeFounders4ParentFiniteNoIntecross.R @@ -1,5 +1,5 @@ context("Founder imputation, four parents, finite selfing, no intercrossing") -test_that("Test zero generations of intercrossing, with marker hetrozygotes", +test_that("Test zero generations of intercrossing, with marker heterozygotes", { testFunc <- function(pedigree, map) { @@ -50,7 +50,7 @@ test_that("Test zero generations of intercrossing, with marker hetrozygotes", } }) -test_that("Test zero generations of intercrossing, without marker hetrozygotes", +test_that("Test zero generations of intercrossing, without marker heterozygotes", { testFunc <- function(pedigree, map) { @@ -63,7 +63,7 @@ test_that("Test zero generations of intercrossing, without marker hetrozygotes", cross2 <- cross + multiparentSNP(keepHets=FALSE) mapped <- new("mpcrossMapped", cross2, map = map) - result <- imputeFounders(mapped, hetrozygoteMissingProb = 1, homozygoteMissingProb = 0.01) + result <- imputeFounders(mapped, heterozygoteMissingProb = 1, homozygoteMissingProb = 0.01) tmp <- table(result@geneticData[[1]]@imputed@data, cross@geneticData[[1]]@finals) #Correct imputation rate should be 0.925 expect_true(sum(diag(tmp)) / sum(tmp) > 0.925)