Adds a named ortholog backend so it can be selected by name in
ortholog_genes(). A backend performs gene-level cross-species mapping; this
pluggable design mirrors the liftover backends used for coordinate features.
Arguments
- name
Character scalar naming the backend.
- fn
A function with signature
function(features, from, to, gene_col, id_type, ...)returning a list with two tibbles:mapped: input rows that had at least one ortholog, carrying the.feature_idkey and anorthologcolumn with the target-species id.unmapped: input rows (carrying.feature_id) with no ortholog.
Examples
# A backend that upper-cases rodent symbols into human ones, used by name.
to_upper <- function(features, from, to, gene_col, id_type, ...) {
mapped <- features
mapped$ortholog <- toupper(mapped[[gene_col]])
list(mapped = mapped, unmapped = features[0, , drop = FALSE])
}
register_ortholog_backend("to_upper", to_upper)
"to_upper" %in% ortholog_backends()
#> [1] TRUE
genes <- data.frame(gene = c("Tp53", "Myc"))
ortholog_genes(genes, from = "rat", to = "human", backend = "to_upper")
#>
#> ── TranslationResult (rat -> human, backend: to_upper)
#> • input: 2
#> ✔ mapped: 2 (100%)
#> ✖ unmapped: 0
#> ! multi: 0