Skip to content

Commit

Permalink
In maskPed(), keep allele distances only if stepwise model
Browse files Browse the repository at this point in the history
  • Loading branch information
magnusdv committed Oct 31, 2023
1 parent 356ba6e commit 4b99816
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions R/ped_mask.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#' y = maskPed(x, seed = 1729)
#'
#' # Unmask
#' z = unmaskPed(y$maskedPed, y$keys)
#' z = unmaskPed(y$maskedPed, keys = y$keys)
#' stopifnot(identical(x, z))
#'
#' # With stepwise model
Expand All @@ -46,7 +46,7 @@
#'
#' y2 = maskPed(x2, seed = 1729)
#'
#' z2 = unmaskPed(y2$maskedPed, y2$keys)
#' z2 = unmaskPed(y2$maskedPed, keys = y2$keys)
#'
#' stopifnot(identical(x2, z2))
#'
Expand Down Expand Up @@ -81,7 +81,7 @@ maskPed = function(x, ids = NULL, markerNames = NULL, alleleLabels = NULL, seed
alleleLabels = lapply(1:nm, function(i) {
alsOld = alleles(y, marker = i)
alsNum = suppressWarnings(as.numeric(alsOld))
if(!any(is.na(alsNum)))
if(!any(is.na(alsNum)) && .hasStepwiseModel(y, i))
als = round(alsNum - round(min(alsNum)) + 1, 1)
else
als = sample.int(length(alsOld))
Expand Down Expand Up @@ -138,3 +138,11 @@ unmaskPed = function(x, keys) {
.flipNames = function(v) {
setNames(names(v), v)
}

.hasStepwiseModel = function(x, marker) {
mut = mutmod(x, marker = marker)
if(is.null(mut))
return(FALSE)
params = pedmut::getParams(mut, format = 1)
any(params$model %in% c("stepwise", "onestep"))
}
4 changes: 2 additions & 2 deletions man/maskPed.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4b99816

Please sign in to comment.