mergePed: Merge two pedigrees

View source: R/mergePed.R

mergePedR Documentation

Merge two pedigrees

Description

This function merges two ped objects, joining them at the indicated individuals. Only ped objects without marker data are supported.

Usage

mergePed(x, y, by = NULL, relabel = FALSE, ...)

Arguments

x, y

ped() objects

by

The individuals to merge by. The most general form uses a named vector with entries of the form id.x = id.y (see Examples). If the vector is unnamed, it is assumed that the merging individuals have the same labels in both pedigrees. Finally, if by = NULL (default), it is set to intersect(labels(x), labels(y)).

relabel

A logical, by default FALSE. If TRUE, relabel(..., "asPlot") is run on the merged pedigree before returning.

...

further arguments passed along to ped(), e.g. famid, validate and reorder.

Details

Some internal checks are done to ensure that merging individuals have the same sex and the same parents.

If relabel = FALSE, some relabelling might still be performed in order to ensure unique labels for everyone. Specifically, this is the case if some ID labels occur in both x and y other than those given in the by argument. In such cases, the relevant members of y get a suffix .y.

Value

A ped object.

Author(s)

Magnus Dehli Vigeland

Examples


############
# Example 1
# A family trio where each parent have first cousin parents.
############

# Trio
x = nuclearPed(1)

# Add paternal family
pat = cousinPed(1, child = TRUE)
x = mergePed(x, pat, by = c("1" = "9"))

# Maternal family
mat = cousinPed(1, child = TRUE) |> swapSex("9")
x = mergePed(x, mat, by = c("2" = "9"))

# Relabel (Alternative: add `relabel = TRUE` in the previous call)
x = relabel(x, "asPlot")

plot(x)


##################################
# Example 2: Double first cousins
##################################

# First cousins, whose fathers are brothers
y = cousinPed(degree = 1)

# Create two sisters
motherPed = nuclearPed(2, sex = 2)

# Plot to see who is who: `plotPedList(list(y, motherPed))`

# Merge
z = mergePed(y, motherPed, by = c("4" = 3, "6" = 4), relabel = TRUE)
plot(z)


magnusdv/pedtools documentation built on April 25, 2024, 4:25 a.m.