Skip to content

Commit

Permalink
In selfingPed(), allow ID vector as input
Browse files Browse the repository at this point in the history
  • Loading branch information
magnusdv committed Jun 27, 2024
1 parent 3f2a1d7 commit 100f23f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
^Meta$
^Rprof.out$
^LICENSE\.md$
^\.github$
26 changes: 19 additions & 7 deletions R/ped_basic.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@
#' @param g A nonnegative integer indicating the number of ancestral generations
#' to include. The resulting pedigree has `2^(g+1)-1` members. The case `g =
#' 0` results in a singleton.
#' @param s A nonnegative integer indicating the number of consecutive selfings.
#' The case `s = 0` results in a singleton.
#' @param s Either a character vector of ID labels, or a nonnegative integer
#' indicating the number of consecutive selfings. The case `s = 0` results in
#' a singleton.
#' @return A `ped` object.
#'
#' @seealso [ped()], [singleton()], [ped_complex], [ped_subgroups]
Expand Down Expand Up @@ -316,12 +317,23 @@ ancestralPed = function(g) {
#' @rdname ped_basic
#' @export
selfingPed = function(s, sex = 1) {
if(!isCount(s, minimum = 0))
stop2("`s` must be a nonnegative integer: ", s)
if(is.character(s)) {
ids = s
}
else if(isCount(s, minimum = 0)) {
ids = 1:(s+1)
}
else
stop2("`s` must be either a character vector or a nonnegative integer: ", s)

n = length(ids)

if(n == 1)
return(singleton(ids, sex = sex))

if(s == 0)
return(singleton(1, sex = sex))
# fid and mid
parid = c(0, ids[-n])

ped(id = 1:(s+1), fid = 0:s, mid = 0:s, sex = c(rep(0, s), sex),
ped(id = ids, fid = parid, mid = parid, sex = c(rep(0, n-1), sex),
reorder = FALSE, validate = FALSE, verbose = FALSE)
}
5 changes: 3 additions & 2 deletions man/ped_basic.Rd

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

0 comments on commit 100f23f

Please sign in to comment.