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.
dDAGlevel(g, level.mode = c("longest_path", "shortest_path"), return.mode = c("node2level", "level2node"))
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
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.
# 1) load HPPA as igraph object ig.HPPA <-dRDataLoader(RData='ig.HPPA')'ig.HPPA' (from package 'dnet' version 1.1.2) has been loaded into the working environment (at 2018-01-19 12:35:01)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:0000478 HP:0000707 HP:0000924 HP:0001574 HP:0040064 HP:0012373 1 2 2 2 2 2 3 HP:0012639 HP:0040068 HP:0410008 HP:0000951 HP:0002817 HP:0011842 HP:0000539 3 3 3 3 3 3 4 HP:0000759 HP:0001155 HP:0002270 HP:0002813 HP:0003839 HP:0011314 HP:0011354 4 4 4 5 8 5 4 HP:0011844 HP:0012332 HP:0000540 HP:0001167 HP:0005924 HP:0009830 HP:0011121 4 5 5 7 9 5 5 HP:0001000 HP:0005930 HP:0006505 HP:0011297 HP:0012181 HP:0000953 HP:0001010 6 6 7 6 6 7 7 HP:0010580 HP:0012186 HP:0004188 HP:0005918 HP:0009123 HP:0010231 HP:0005920 7 7 8 8 8 11 10 HP:0007471 HP:0009172 HP:0009174 HP:0009832 HP:0009282 HP:0010243 HP:0009249 9 9 11 9 10 11 12 HP:0009396 HP:0010249 HP:0009253 12 12 13# 4b) definition based on the shortest path dDAGlevel(subg, level.mode="shortest_path")HP:0000118 HP:0000478 HP:0000707 HP:0000924 HP:0001574 HP:0040064 HP:0012373 1 2 2 2 2 2 3 HP:0012639 HP:0040068 HP:0410008 HP:0000951 HP:0002817 HP:0011842 HP:0000539 3 3 3 3 3 3 4 HP:0000759 HP:0001155 HP:0002270 HP:0002813 HP:0003839 HP:0011314 HP:0011354 4 4 4 4 4 4 4 HP:0011844 HP:0012332 HP:0000540 HP:0001167 HP:0005924 HP:0009830 HP:0011121 4 5 5 5 5 5 5 HP:0001000 HP:0005930 HP:0006505 HP:0011297 HP:0012181 HP:0000953 HP:0001010 6 5 5 5 6 7 7 HP:0010580 HP:0012186 HP:0004188 HP:0005918 HP:0009123 HP:0010231 HP:0005920 6 7 6 6 8 7 6 HP:0007471 HP:0009172 HP:0009174 HP:0009832 HP:0009282 HP:0010243 HP:0009249 9 7 7 7 8 7 8 HP:0009396 HP:0010249 HP:0009253 8 8 9# 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:0000478" "HP:0000707" "HP:0000924" "HP:0001574" "HP:0040064" $`3` [1] "HP:0012373" "HP:0012639" "HP:0040068" "HP:0410008" "HP:0000951" [6] "HP:0002817" "HP:0011842" $`4` [1] "HP:0000539" "HP:0000759" "HP:0001155" "HP:0002270" "HP:0011354" [6] "HP:0011844" $`5` [1] "HP:0002813" "HP:0011314" "HP:0012332" "HP:0000540" "HP:0009830" [6] "HP:0011121" $`6` [1] "HP:0001000" "HP:0005930" "HP:0011297" "HP:0012181" $`7` [1] "HP:0001167" "HP:0006505" "HP:0000953" "HP:0001010" "HP:0010580" [6] "HP:0012186" $`8` [1] "HP:0003839" "HP:0004188" "HP:0005918" "HP:0009123" $`9` [1] "HP:0005924" "HP:0007471" "HP:0009172" "HP:0009832" $`10` [1] "HP:0005920" "HP:0009282" $`11` [1] "HP:0010231" "HP:0009174" "HP:0010243" $`12` [1] "HP:0009249" "HP:0009396" "HP:0010249" $`13` [1] "HP:0009253"