bim_add_posg: Calculate genetic positions from base pair positions and a...

View source: R/bim_add_posg.R

bim_add_posgR Documentation

Calculate genetic positions from base pair positions and a genetic map

Description

Given a table of base pair positions (a data frame with chromosome and position values), and a genetic map (see recomb_map_hg), this function calculates genetic positions. If genetic positions existed in input, they are overwritten.

Usage

bim_add_posg(bim, map)

Arguments

bim

The table of variants, which is a data.frame/tibble with at least two columns: chr (must be numeric between 1 and the maximum chromosome in map below for map to work, otherwise ignored with a warning) and pos (base pair position, usually an integer). If column posg is present, it will be overwritten in the output, otherwise it is created. Additional columns may be present and will be unedited.

map

The genetic map, a list of chromosomes each of which is a data.frame/tibble with columns pos for base pair position and posg for genetic position.

Details

Base pair positions are converted to genetic positions from the provided map using linear interpolation, using stats::approx() with options rule = 2 (out of range cases are set to nearest end's value) and ties = list( 'ordered', mean ) (assume data is ordered, interpolate ties in base pair positions in map using mean of genetic positions). Output will be incorrect, without throwing errors, if genetic map is not ordered.

Value

The bim input with new or overwritten column posg of genetic positions in cM. Rows with values of chr that are not numeric or are out of range (for given map) are unedited if the posg column was present, or assigned NA otherwise.

See Also

recomb_map_hg for simplified human recombination maps included in this package.

Examples

# let's define a very simple table of base pair positions, with minimal information
library(tibble)
bim <- tibble(
  chr = c(1, 1, 2, 2),
  pos = c(50, 200, 30, 123) * 1000000
)
# use latest human recombination map
map <- recomb_map_hg38

# now use this function to add genetic positions column to `bim`!
bim <- bim_add_posg( bim, map )


OchoaLab/simfam documentation built on Jan. 11, 2025, 12:23 a.m.