addSwitch: Add Switches

View source: R/switch.R

addSwitchR Documentation

Add Switches

Description

Add switch points to haplotypes by swapping the two haplotype rows for an individual from each switch point to the end of the chromosome.

Usage

addSwitch(haplotypeMatrix, switchPoints, minLength)

Arguments

haplotypeMatrix

matrix. Haplotypes for a half-sib family (two rows per individual).

switchPoints

list of integer/numeric vectors. Length must equal the number of individuals. Each element contains the switch positions (0-based/1-based depends on how they were produced; see Details). If there are no switches for an individual, use 0.

minLength

integer. Minimum distance between consecutive switch points. Note: in the current implementation this filter may not be enforced (depends on package version).

Details

Important: Each switch point causes a swap of the two haplotype rows for that individual from the switch position to the end.

The switchPoints list must have one element per individual (not per haplotype row). If an element is 0, no switch is applied for that individual.

If you rely on minLength to ignore nearby switches, verify your installed version enforces this rule.

Value

A matrix of the same dimension as haplotypeMatrix with switches applied.

See Also

groupMatSingle and fixSW

Examples

haplotype <- matrix(c(0, 0, 0, 0,
                      1, 1, 1, 1,
                      0, 0, 1, 1,
                      1, 1, 0, 0,
                      1, 1, 1, 1,
                      0, 0, 0, 0), byrow = TRUE, nrow = 6)

switchPoints <- list(firstInd = c(2), secondInd = c(1, 3), lastInd = 0)
addSwitch(haplotype, switchPoints, 0)

hsphase documentation built on Feb. 17, 2026, 5:07 p.m.