match_id: Match concatenated IDs in data.frame

View source: R/match_id.R

match_idR Documentation

Match concatenated IDs in data.frame

Description

Match IDs in a data.frame/tibble to a reference table and then take other columns from that reference table and bind them to the original data.frame. I mainly use this for matching metadata to UniProt accessions, but will work for any type of string ID e.g. Ensembl IDs.

Usage

match_id(
  data,
  to_match,
  ref,
  match,
  new,
  regex = "[^;]+",
  collapse = ";",
  verbose = FALSE
)

Arguments

data

data.frame or tibble. Has the ID column to be matched.

to_match

variable. Name of column in data with the IDs to be matched.

ref

data.frame. A reference data.frame with the IDs to use for matching and the new columns to add to data.

match

string. Name of column in ref to use for matching.

new

character vector. Name of column(s) in ref to bind to data. If not character columns, they will be coerced to class character with a warning, unless verbose = FALSE.

regex

string. Regular expression to use for extracting the IDs from the to_match column in data.

collapse

string. String to collapse multiple matched IDs.

verbose

logical. Show warning if new columns have been coerced to character columns. Default is FALSE.

Value

Returns a transformed data.frame or tibble.

See Also

match_id_() which takes a vector input instead.

Examples

ref_df <- data.frame(
  accession = c("AAA111", "BBB222", "CCC333", "DDD444"),
  name = c("protein a", "protein b", "protein c", "protein d"),
  value = c(11, 22, 33, 44)
)

my_df <- data.frame(
  uniprot.id = c("AAA111", "CCC333;BBB222", "EEE555"),
  r1 = c(1, 23, 5),
  r2 = c(1, 23, 5),
  r3 = c(1, 23, 5)
)

my_df2 <- match_id(
  my_df,
  uniprot.id,
  ref_df,
  "accession",
  c("name", "value")
)

csdaw/csdmisc documentation built on April 26, 2022, 5:39 a.m.