R/getDescendantPedigree.R

Defines functions getDescendantPedigree

Documented in getDescendantPedigree

## Copyright(c) 2017-2026 R. Mark Sharp
## This file is part of nprcgenekeepr

#' Reduce a pedigree to a group and its descendants
#'
#' Filters a pedigree down to only the descendants of the provided group,
#' building the pedigree forward in time starting from a group of probands.
#' This is the downward (descendants-only) mirror of
#' \code{\link{getProbandPedigree}}: it takes the transitive closure over
#' offspring and returns the probands together with all of their descendants.
#' It does not include collateral relatives (siblings, cousins, or mates).
#'
#' @param probands a character vector with the list of animals whose
#' descendants should be included in the final pedigree.
#' @param ped datatable that is the \code{Pedigree}. It contains pedigree
#' information. The fields \code{id}, \code{sire} and \code{dam} are required.
#' @return A reduced pedigree containing the probands and all of their
#' descendants.
#'
#' @export
#' @examples
#' library(nprcgenekeepr)
#' ped <- nprcgenekeepr::lacy1989Ped
#' ## D's descendants are F and G
#' getDescendantPedigree(probands = "D", ped = ped)$id
getDescendantPedigree <- function(probands, ped) {
  repeat {
    offspring <- getOffspring(ped, probands)
    added <- setdiff(offspring, probands)
    if (length(added) == 0L) {
      break
    }
    probands <- union(probands, offspring)
  }

  ped <- ped[ped$id %in% probands, ]
  ped
}

Try the nprcgenekeepr package in your browser

Any scripts or data that you put into this service are public.

nprcgenekeepr documentation built on July 26, 2026, 5:06 p.m.