Function to define/calculate the level of nodes in a direct acyclic graph (DAG)

Description

dDAGlevel is supposed to calculate the level of nodes, given a direct acyclic graph (DAG; an ontology). The input is a graph of "igraph" or "graphNET" object, and the definition of the node level. The return can be the level for each node or the nodes for each level.

Usage

dDAGlevel(g, level.mode = c("longest_path", "shortest_path"), return.mode = c("node2level", 
  "level2node"))

Arguments

g
an object of class "igraph" or "graphNEL"
level.mode
the mode of how to define the level of nodes in DAG. It can be "longest_path" for defining the node level as the length of the longest path from the node to the root, and "shortest_paths" for defining the node level as the length of the shortest path from the node to the root
return.mode
the mode of how to return the node level information. It can be "node2level" for returning a named vector (i.e. the level for each node), and "level2node" for returning a named list (i.e. nodes for each level)

Value

When "return.mode" is "node2level", it returns a named vector: for each named node (i.e. Term ID), it stores its level When "return.mode" is "level2node", it returns a named list: for each named level, it contains the names (i.e. Term ID) of nodes belonging to this level

Note

The level for the root is 1. The level based on the longest path will ensure that nodes at the same level will never be reachable (i.e. in the same path), while the level based on the shortest path will not be necessary. The "longest path" based level can be useful in visiting nodes from the tipmost level to the root: 1) for the current node, all children have been visited; 2) nodes at the same level can be looked at independantly. The "shortest path" based level can be useful in deriving nodes according to their closeness to the root.

Examples

# 1) load HPPA as igraph object ig.HPPA <-dRDataLoader(RData='ig.HPPA')
'ig.HPPA' (from package 'dnet' version 1.0.11) has been loaded into the working environment (at 2017-03-27 19:54:14)
g <- ig.HPPA # 2) randomly select vertices as the query nodes nodes_query <- sample(V(g),5)$name # 3) obtain the complete subgraph induced subg <- dDAGinduce(g, nodes_query) # 4) calculate the node levels # 4a) definition based on the longest path dDAGlevel(subg, level.mode="longest_path")
HP:0000118 HP:0000119 HP:0000818 HP:0000924 HP:0001574 HP:0001626 HP:0002664 1 2 2 2 2 2 2 HP:0040064 HP:0040068 HP:0000951 HP:0001627 HP:0002817 HP:0007379 HP:0008373 2 3 3 3 3 4 3 HP:0010766 HP:0011793 HP:0011842 HP:0011915 HP:0001155 HP:0002564 HP:0002813 3 3 3 4 4 4 5 HP:0003330 HP:0003839 HP:0008193 HP:0010655 HP:0011314 HP:0011355 HP:0011844 4 8 4 8 5 4 4 HP:0001167 HP:0001654 HP:0005146 HP:0005924 HP:0006758 HP:0008065 HP:0010660 7 5 6 9 5 5 7 HP:0011849 HP:0003336 HP:0005930 HP:0006505 HP:0006705 HP:0007383 HP:0011297 5 6 6 7 6 6 6 HP:0001633 HP:0004382 HP:0010656 HP:0001718 HP:0005918 HP:0010237 HP:0200129 7 8 7 8 8 11 9 HP:0005920 HP:0009834 HP:0010245 HP:0010277 10 9 11 12
# 4b) definition based on the shortest path dDAGlevel(subg, level.mode="shortest_path")
HP:0000118 HP:0000119 HP:0000818 HP:0000924 HP:0001574 HP:0001626 HP:0002664 1 2 2 2 2 2 2 HP:0040064 HP:0040068 HP:0000951 HP:0001627 HP:0002817 HP:0007379 HP:0008373 2 3 3 3 3 3 3 HP:0010766 HP:0011793 HP:0011842 HP:0011915 HP:0001155 HP:0002564 HP:0002813 3 3 3 3 4 4 4 HP:0003330 HP:0003839 HP:0008193 HP:0010655 HP:0011314 HP:0011355 HP:0011844 4 4 4 4 4 4 4 HP:0001167 HP:0001654 HP:0005146 HP:0005924 HP:0006758 HP:0008065 HP:0010660 5 5 4 5 4 5 5 HP:0011849 HP:0003336 HP:0005930 HP:0006505 HP:0006705 HP:0007383 HP:0011297 5 6 5 5 6 6 5 HP:0001633 HP:0004382 HP:0010656 HP:0001718 HP:0005918 HP:0010237 HP:0200129 7 5 7 8 6 5 6 HP:0005920 HP:0009834 HP:0010245 HP:0010277 6 7 7 6
# 4c) definition based on the longest path, and return nodes for each level dDAGlevel(subg, level.mode="longest_path", return.mode="level2node")
$`1` [1] "HP:0000118" $`2` [1] "HP:0000119" "HP:0000818" "HP:0000924" "HP:0001574" "HP:0001626" [6] "HP:0002664" "HP:0040064" $`3` [1] "HP:0040068" "HP:0000951" "HP:0001627" "HP:0002817" "HP:0008373" [6] "HP:0010766" "HP:0011793" "HP:0011842" $`4` [1] "HP:0007379" "HP:0011915" "HP:0001155" "HP:0002564" "HP:0003330" [6] "HP:0008193" "HP:0011355" "HP:0011844" $`5` [1] "HP:0002813" "HP:0011314" "HP:0001654" "HP:0006758" "HP:0008065" [6] "HP:0011849" $`6` [1] "HP:0005146" "HP:0003336" "HP:0005930" "HP:0006705" "HP:0007383" [6] "HP:0011297" $`7` [1] "HP:0001167" "HP:0010660" "HP:0006505" "HP:0001633" "HP:0010656" $`8` [1] "HP:0003839" "HP:0010655" "HP:0004382" "HP:0001718" "HP:0005918" $`9` [1] "HP:0005924" "HP:0200129" "HP:0009834" $`10` [1] "HP:0005920" $`11` [1] "HP:0010237" "HP:0010245" $`12` [1] "HP:0010277"

Source code

dDAGlevel.r

Source man

dDAGlevel.Rd dDAGlevel.pdf

See also

dDAGroot, dDAGreverse