Filter the DAG

dag_filter(
  dag,
  terms = NULL,
  relations = NULL,
  root = NULL,
  leaves = NULL,
  mcols_filter = NULL,
  namespace = NULL
)

Arguments

dag

An ontology_DAG object.

terms

A vector of term names. The sub-DAG will only contain these terms.

relations

A vector of relations. The sub-DAG will only contain these relations. Valid values of "relations" should correspond to the values set in the relations argument in the create_ontology_DAG(). If relations_DAG is already provided, offspring relation types will all be selected. Note "is_a" is always included.

root

A vector of term names which will be used as roots of the sub-DAG. Only these with their offspring terms will be kept. If there are multiple root terms, a super root will be automatically added.

leaves

A vector of leaf terms. Only these with their ancestor terms will be kept.

mcols_filter

Filtering on columns in the meta data frame.

namespace

The prefix before ":" of the term IDs.

Value

An ontology_DAG object.

Details

If the DAG is reduced into several disconnected parts after the filtering, a super root is automatically added.

Examples

parents  = c("a", "a", "b", "b", "c", "d")
children = c("b", "c", "c", "d", "e", "f")
dag = create_ontology_DAG(parents, children)
dag_filter(dag, terms = c("b", "d", "f"))
#> An ontology_DAG object:
#>   Source: Ontology 
#>   3 terms / 2 relations / a tree
#>   Root: b 
#>   Terms: b, d, f, ...
#>   Max depth: 2 
#>   Aspect ratio: 0.51:1
dag_filter(dag, root = "b")
#> An ontology_DAG object:
#>   Source: Ontology 
#>   5 terms / 4 relations / a tree
#>   Root: b 
#>   Terms: b, c, d, e, ...
#>   Max depth: 2 
#>   Aspect ratio: 1:1
dag_filter(dag, leaves = c("c", "b"))
#> An ontology_DAG object:
#>   Source: Ontology 
#>   3 terms / 3 relations
#>   Root: a 
#>   Terms: a, b, c, ...
#>   Max depth: 2 
#>   Avg number of parents: 1.50
#>   Avg number of children: 0.50
#>   Aspect ratio: 0.51:1 (based on the longest distance from root)
#>                 2:1 (based on the shortest distance from root)
dag_filter(dag, root = "b", leaves = "e")
#> An ontology_DAG object:
#>   Source: Ontology 
#>   3 terms / 2 relations / a tree
#>   Root: b 
#>   Terms: b, c, e, ...
#>   Max depth: 2 
#>   Aspect ratio: 0.51:1

# \donttest{
dag = create_ontology_DAG_from_GO_db()
#> relations: is_a, part_of
dag_filter(dag, relations = "is_a")
#> An ontology_DAG object:
#>   Source: GO BP / GO.db package 3.17.0 
#>   27942 terms / 50938 relations
#>   Root: GO:0008150 
#>   Terms: GO:0000001, GO:0000002, GO:0000003, GO:0000011, ...
#>   Max depth: 16 
#>   Avg number of parents: 1.82
#>   Avg number of children: 1.76
#>   Aspect ratio: 385.17:1 (based on the longest distance from root)
#>                 751.33:1 (based on the shortest distance from root)
#>   Relations: is_a
#> 
#> With the following columns in the metadata data frame:
#>   id, name, definition
# }