snp_ibs: Compute the Identity by State Matrix for a bigSNP object

View source: R/snp_ibs.R

snp_ibsR Documentation

Compute the Identity by State Matrix for a bigSNP object

Description

This function computes the IBS matrix.

Usage

snp_ibs(
  X,
  ind.row = bigstatsr::rows_along(X),
  ind.col = bigstatsr::cols_along(X),
  type = c("proportion", "adjusted_counts", "raw_counts"),
  block.size = bigstatsr::block_size(nrow(X))
)

Arguments

X

a bigstatsr::FBM.code256 matrix (as found in the genotypes slot of a bigsnpr::bigSNP object).

ind.row

An optional vector of the row indices that are used. If not specified, all rows are used. Don't use negative indices.

ind.col

An optional vector of the column indices that are used. If not specified, all columns are used. Don't use negative indices.

type

one of "proportion" (equivalent to "ibs" in PLINK), "adjusted_counts" ("distance" in PLINK), and "raw_counts" (the counts of identical alleles and non-missing alleles, from which the two other quantities are computed)

block.size

maximum number of columns read at once. Note that, to optimise the speed of matrix operations, we have to store in memory 3 times the columns.

Details

Note that monomorphic sites are currently counted. Should we filter them beforehand? What does plink do?

Value

if as.counts = TRUE function returns a list of two bigstatsr::FBM matrices, one of counts of IBS by alleles (i.e. 2*n loci), and one of valid alleles (i.e. 2 * n_loci - 2 * missing_loci). If as.counts = FALSE returns a single matrix of IBS proportions.

Examples

example_gt <- load_example_gt("gen_tbl")

X <- attr(example_gt$genotypes, "bigsnp")
snp_ibs(X$genotypes)

# Compute for individuals 1 to 5
snp_ibs(X$genotypes, ind.row = 1:5, ind.col = 1:5)

# Adjust block.size
snp_ibs(X$genotypes, block.size = 2)

# Change type
snp_ibs(X$genotypes, type = "proportion")
snp_ibs(X$genotypes, type = "adjusted_counts")
snp_ibs(X$genotypes, type = "raw_counts")


tidypopgen documentation built on Aug. 28, 2025, 1:08 a.m.