Skip to contents

Fetches genotype data from a BrAPI server and converts it into a numeric dosage matrix (samples × markers) compatible with genomic selection packages like rrBLUP, BGLR, and sommer.

Usage

brapi_get_dosage_matrix(con, variantSetDbId, sep = "/", unknown_string = ".")

Arguments

con

A brapi_connection() object.

variantSetDbId

Character. The variant set to retrieve.

sep

Character. Unphased allele separator. Default "/" (e.g. "0/1"). Phased calls using "|" are also handled automatically.

unknown_string

Character. String representing missing data. Default ".".

Value

A numeric (double) matrix: rows = samples (callSetDbIds), columns = markers (variantDbIds). Values are whole-number dosages (0, 1, 2 for diploids; 0–N for polyploids). Missing calls are NA.

Details

The server is asked for expanded homozygotes, sep as the unphased separator and unknown_string for missing data. Allele dosage is then computed by splitting each genotype string on sep (or "|" for phased calls) and counting how many alleles are non-reference (i.e. not "0"). A call with any missing allele (unknown_string, "." or ""), such as "./1", becomes NA. A server that still collapses a homozygote to a single allele ("1") gets it expanded to the ploidy seen in the rest of the data, or to 2 if every call is collapsed. Alleles must be numeric indices ("0", "1", ...); nucleotide calls such as "A/T" are an error.

BrAPI endpoint

GET /allelematrix - see the v2.1 specification.

Examples

# \donttest{
con <- brapi_connection("https://test-server.brapi.org")
if (brapi_ping(con)) {
  dosage <- brapi_get_dosage_matrix(con, "variantset1")
  dim(dosage)
  # Use with rrBLUP:
  # library(rrBLUP)
  # result <- mixed.solve(y = pheno$yield, Z = dosage)
}
#> ✔ Server <https://test-server.brapi.org> is reachable.
#> ℹ Fetching allele matrix for variant set "variantset1"...
#> ℹ Encoding 260 genotype calls as allele dosages...
#> ✔ Dosage matrix ready: 13 samples x 20 markers.
#> [1] 13 20
# }