Browse code

renaming

Jitao David Zhang authored on 11/02/2019 08:29:38
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,59 @@
1
+library(KEGGgraph)
2
+library(graph)
3
+library(Rgraphviz)
4
+
5
+## If edges of a node is not explicitly specified in a directed graph (i.e. the node "D" in the graph object 'test' in the following example),
6
+## its incoming edges will be interpreted as reciprocal edges ( hence inEdges(test)[["B"]]==c("A","D") )
7
+test.nodes <- LETTERS[1:4];
8
+test.edges <- list(A=c("B","C"), B=c("C","D"), C=c("A","D"));
9
+test <- new("graphNEL", nodes=test.nodes, edgeL=test.edges, edgemode="directed");
10
+stopifnot(is.null(adj(test, "D")[[1]]))
11
+stopifnot(inEdges(test)[["B"]]==c("A","D"))
12
+
13
+## so if we don't want the side effect above, we have to specify the edges of a no-out-edge node to c() or NULL
14
+test.edges2 <- list(A=c("B","C"), B=c("C","D"), C=c("A","D"), D=NULL);
15
+test2 <- new("graphNEL", nodes=test.nodes, edgeL=test.edges2, edgemode="directed");
16
+inEdges(test2)
17
+stopifnot(adj(test2, "C")[["C"]] == adj(test, "C")[["C"]])
18
+stopifnot(length(adj(test2,"D")[["D"]]) == 0)
19
+stopifnot(inEdges(test2)[["B"]]=="A")
20
+
21
+## DO NOT RUN -- it leads to segfault
22
+# plot(test)
23
+## test2 without problem
24
+plot(test2)
25
+
26
+## question: a bug or intended so?
27
+
28
+##----------------------------------------##
29
+## all edges set to NULL -- disabled!
30
+##----------------------------------------##
31
+test.edge3 <- list(A=NULL, B=NULL, C=NULL, D=NULL)
32
+tryres <- try(test3 <- new("graphNEL", nodes=test.nodes, edgeL=test.edge3, edgemode="directed"))
33
+
34
+test.edge4 <- list(A=list(),  B=NULL, C=NULL, D=NULL)
35
+test4 <- new("graphNEL", nodes=test.nodes, edgeL=test.edge4, edgemode="directed")
36
+adj(test4, "A")
37
+inEdges(test4)
38
+
39
+test.edge5 <- list(A=c("B","C"),  B=c("A","C"), C=character(0), D=character(0))
40
+test5 <- new("graphNEL", nodes=test.nodes, edgeL=test.edge5, edgemode="directed")
41
+adj(test5, "B")
42
+inEdges(test5)
43
+
44
+##----------------------------------------##
45
+## edges must be unique, otherwise an implicit bug will apper
46
+##----------------------------------------##
47
+test.edge6 <- list(A=c("B","B","C"), B=c("A","C"),C=character(0), D=c("A"))
48
+test6 <- new("graphNEL", nodes=test.nodes, edgeL=test.edge6, edgemode="directed")
49
+tryerr <- try(randomSubGraph(test6))
50
+
51
+##----------------------------------------##
52
+## test known well-formed graph
53
+##----------------------------------------##
54
+#allpackages <- .packages(all=TRUE)
55
+#if("keggorthology" %in% allpackages) {
56
+#  library(keggorthology)
57
+#  data(KOgraph)
58
+#  randomSubGraph(KOgraph)
59
+#}