inbreedingLoops: Pedigree loops

View source: R/ped_loops.R

inbreedingLoopsR Documentation

Pedigree loops

Description

Functions for identifying, breaking and restoring loops in pedigrees.

Usage

inbreedingLoops(x)

breakLoops(x, loopBreakers = NULL, verbose = TRUE, errorIfFail = TRUE)

tieLoops(x, verbose = TRUE)

findLoopBreakers(x)

findLoopBreakers2(x, errorIfFail = TRUE)

Arguments

x

a ped() object.

loopBreakers

either NULL (resulting in automatic selection of loop breakers) or a numeric containing IDs of individuals to be used as loop breakers.

verbose

a logical: Verbose output or not?

errorIfFail

a logical: If TRUE an error is raised if the loop breaking is unsuccessful. If FALSE, the pedigree is returned unchanged.

Details

Pedigree loops are usually handled (by pedtools and related packages) under the hood - using the functions described here - without need for explicit action from end users. When a ped object x is created, an internal routine detects if the pedigree contains loops, in which case x$UNBROKEN_LOOPS is set to TRUE.

In cases with complex inbreeding, it can be instructive to plot the pedigree after breaking the loops. Duplicated individuals are plotted with appropriate labels (see examples).

The function findLoopBreakers identifies a set of individuals breaking all inbreeding loops, but not marriage loops. These require more machinery for efficient detection, and pedtools does this is a separate function, findLoopBreakers2, utilizing methods from the igraph package. Since this is rarely needed for most users, igraph is not imported when loading pedtools, only when findLoopBreakers2 is called.

In practice, breakLoops first calls findLoopBreakers and breaks at the returned individuals. If the resulting ped object still has loops, findLoopBreakers2 is called to break any marriage loops.

Value

For breakLoops, a ped object in which the indicated loop breakers are duplicated. The returned object will also have a non-null loopBreakers entry, namely a matrix with the IDs of the original loop breakers in the first column and the duplicates in the second. If loop breaking fails, then depending on errorIfFail either an error is raised, or the input pedigree is returned, still containing unbroken loops.

For tieLoops, a ped object in which any duplicated individuals (as given in the x$LOOP_BREAKERS entry) are merged. For any ped object x, the call tieLoops(breakLoops(x)) should return x.

For inbreedingLoops, a list containing all inbreeding loops (not marriage loops) found in the pedigree. Each loop is represented as a list with elements top, bottom, pathA (individuals forming a path from top to bottom) and pathB (creating a different path from top to bottom, with no individuals in common with pathA). Note that the number of loops reported here counts all closed paths in the pedigree and will in general be larger than the genus of the underlying graph.

For findLoopBreakers and findLoopBreakers2, a numeric vector of individual ID's.

Author(s)

Magnus Dehli Vigeland

Examples


x = cousinPed(1, child = TRUE)
plot(breakLoops(x))

# Pedigree with marriage loop: Double first cousins
if(requireNamespace("igraph", quietly = TRUE)) {
  y = doubleCousins(1, 1, child = TRUE)
  findLoopBreakers(y) # --> 9
  findLoopBreakers2(y) # --> 7 and 9
  y2 = breakLoops(y)
  plot(y2)

  # Or loop breakers chosen by user
  y3 = breakLoops(y, 6:7)
  plot(y3)
}


pedtools documentation built on Nov. 5, 2023, 5:06 p.m.