Learn R Programming

simfam

The goal of simfam is to simulate and model families with founders drawn from a structured population. The main function simulates a random pedigree for many generations with realistic features. Additional functions calculate kinship matrices, admixture matrices, and draw random genotypes across arbitrary pedigree structures starting from the corresponding founder values.

Installation

You can install the released version of simfam from CRAN with:

install.packages("simfam")

The current development version can be installed from the GitHub repository using devtools:

install.packages("devtools") # if needed
library(devtools)
install_github('OchoaLab/simfam', build_vignettes = TRUE)

You can see the package vignette, which has more detailed documentation and examples, by typing this into your R session:

vignette('simfam')

Examples

These are some basic ways of calling the main functions.

# load package!
library(simfam)

Simulate a random pedigree with a desired number of individuals per generation n and a number of generations G:

data <- sim_pedigree( n, G )
# creates a plink-formatted FAM table
# (describes pedigree, most important!)
fam <- data$fam
# lists of IDs split by generation
ids <- data$ids
# and local kinship of last generation
kinship_local_G <- data$kinship_local

The basics of encoding a pedigree in a fam table (a data.frame) is that every individual in the pedigree is a row, column id identifies the individual with a unique number or string, columns pat and mat identify the parents of the individual (who are themselves earlier rows), and sex encodes the sex of the individual numerically (1=male, 2=female). The following functions work with arbitrary pedigrees/fam data.frames:

Prune a given fam, to speed up simulations/etc, by removing individuals without descendants among set of individuals ids (in this example, the last generation from the output of sim_pedigree):

fam <- prune_fam( fam, ids[[G]] )

Draw genotypes X through pedigree, starting from genotypes of founders (X_1):

X <- geno_fam( X_1, fam )
# Version for last generation only, which uses less memory.
# (`ids` must be as from `sim_pedigree`,
# a list partitioning non-overlapping generations)
X_G <- geno_last_gen( X_1, fam, ids )

Calculate kinship through pedigree, starting from kinship of founders (kinship_1):

kinship <- kinship_fam( kinship_1, fam )
# Version for last generation only, which uses less memory.
kinship_G <- kinship_last_gen( kinship_1, fam, ids )

Calculate expected admixture proportions through pedigree, starting from admixture of founders (admix_proportions_1):

admix_proportions <- admix_fam( admix_proportions_1, fam )
# Version for last generation only, which uses less memory.
admix_proportions_G <- admix_last_gen( admix_proportions_1, fam, ids )

Copy Link

Version

Install

install.packages('simfam')

Monthly Downloads

162

Version

1.1.6

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Alejandro Ochoa

Last Published

January 9th, 2023

Functions in simfam (1.1.6)

admix_last_gen

Calculate admixture matrix for last generation of a pedigree with admixture of founders
recomb_map_hg

Simplified recombination maps for human genomes
recomb_haplo_inds

Construct haplotypes of individuals given their ancestral blocks and the ancestral haplotype variants
recomb_map_fix_ends_chr

Extrapolate and shift recombination map of one chromosome to ends
recomb_fam

Draw recombination breaks for autosomes from a pedigree
recomb_geno_inds

Reduce haplotype data to genotype matrix
recomb_map_inds

Map recombination breaks from genetic positions to base pair coordinates
simfam-package

Simulate and Model Family Pedigrees With Structured Founders
recomb_map_simplify_chr

Simplify recombination map of one chromosome to a desired numerical precision
recomb_last_gen

Draw recombination breaks for autosomes for last generation of a pedigree
sim_pedigree

Construct a random pedigree
recomb_init_founders

Initialize chromosome structures for founders
admix_fam

Calculate admixture matrix of a pedigree with known admixture of founders
kinship_fam

Calculate kinship matrix of a pedigree with structured founders
geno_fam

Draw random genotypes on a pedigree with known founder genotypes
prune_fam

Remove non-ancestors of a set of individuals from pedigree
draw_sex

Draw sex values randomly for a list of individuals
fam_ancestors

Construct an ancestors-only pedigree for one person G-generations deep
geno_last_gen

Draw random genotypes for last generation of a pedigree with known founder genotypes
kinship_last_gen

Calculate kinship matrix for last generation of a pedigree with structured founders
recomb_admix_inds

Reduce haplotype ancestry data to population ancestry dosage matrices