Obtains a presence-absence dependency matrix for the given set of terms. The resulting matrix M will have values 1 and 0, where M[i,j] = 1 iff the presence if term i implies the presence of term j. Note that it follows that M[i,j] = 1 iff the absence of term j implies the absence of term i. Note also that the matrix is asymmetric; that is, M[i,j] = 1 does not imply M[j,i] = 1 for \(i\neq j\). Terms i and j (\(i\neq j\)) for which M[i,j] = M[j,i] = 1 are sometimes referred to as super-dependent.

pa_dep_matrix(
  terms,
  .names = c("ID", "IRI", "label"),
  .labels = NULL,
  preserveOrder = FALSE,
  verbose = FALSE
)

Arguments

terms

character, the list of terms for which to compute the dependency matrix. Can be given as term IRIs or term labels, and the list can contain both. Terms given as labels will first be resolved to IRIs, assuming they are from an anatomy ontology.

.names

character, how to name the rows and columns of the resulting matrix.

  • "ID" (the default): use the term IDs (the last component of the term IRIs).

  • "IRI": use the term IRIs as names.

  • "label": use the terms' labels (see .labels parameter).

.labels

character, the labels for terms where known. Only used if .names = "label". If NULL (the default), labels will be looked up if terms are provided as IRIs; elements of the terms list that are not in IRI form are assumed to be the label. If a list, must have the same length and ordering as terms; any NA elements will be looked up (from the corresponding term IRI).

preserveOrder

logical, whether to return rows (and columns) in the same order as terms. The default is not to preserve the order.

verbose

logical, whether to print informative messages about certain potentially time-consuming operations.

Value

A data.fram M with M[i,j] = 1 iff the presence of term i implies the presence of term j, and 0 otherwise.

The matrix will have additional attributes depending on the choice of how to name rows and columns. If .names = "ID" (the default), the matrix will have an attribute prefixes giving the URL prefixes removed from the term IRIs to yield the IDs, in the order of the rows. If .names = "label", it will have attribute term.iris, giving the term IRIs for the rows (and columns). Note that these extra attributes will be lost upon subsetting the returned matrix.

Examples

tl <- c("http://purl.obolibrary.org/obo/UBERON_0000981",
        "http://purl.obolibrary.org/obo/UBERON_0002103",
        "http://purl.obolibrary.org/obo/UBERON_0000976",
        "http://purl.obolibrary.org/obo/UBERON_0002102")
m <- pa_dep_matrix(tl)
m # term IDs as row and column names
#>                UBERON_0000981 UBERON_0002103 UBERON_0000976 UBERON_0002102
#> UBERON_0000981              1              1              0              0
#> UBERON_0002103              0              1              0              0
#> UBERON_0000976              0              0              1              1
#> UBERON_0002102              0              0              0              1
id_prefixes <- attr(m, "prefixes")
id_prefixes # 4x "http://purl.obolibrary.org/obo/"
#> [1] "http://purl.obolibrary.org/obo/" "http://purl.obolibrary.org/obo/"
#> [3] "http://purl.obolibrary.org/obo/" "http://purl.obolibrary.org/obo/"

m <- pa_dep_matrix(tl, .names = "label")
m # term labels as row and column names
#>          femur hindlimb humerus forelimb
#> femur        1        1       0        0
#> hindlimb     0        1       0        0
#> humerus      0        0       1        1
#> forelimb     0        0       0        1
mat_terms <- attr(m, "term.iris")
mat_terms # term IRIs in the same order as rows (and columns)
#> [1] "http://purl.obolibrary.org/obo/UBERON_0000981"
#> [2] "http://purl.obolibrary.org/obo/UBERON_0002103"
#> [3] "http://purl.obolibrary.org/obo/UBERON_0000976"
#> [4] "http://purl.obolibrary.org/obo/UBERON_0002102"