git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/rTRM@80840 bc3139a8-67e5-0310-9ffc-ced21a209358
... | ... |
@@ -112,8 +112,9 @@ layout.arc = function (g, target, query) |
112 | 112 |
target = target[target %in% query] |
113 | 113 |
|
114 | 114 |
V(g)$type = "bridge" |
115 |
- V(g)[name %in% query]$type = "query" |
|
116 |
- V(g)[name %in% target]$type = "target" |
|
115 |
+ all_name=V(g)$name # could be V(g)[ name %in% query ] but want to avoid "note's" in R CMD check. |
|
116 |
+ V(g)[all_name %in% query]$type = "query" |
|
117 |
+ V(g)[all_name %in% target]$type = "target" |
|
117 | 118 |
|
118 | 119 |
g_con = g |
119 | 120 |
n_left = character() |
... | ... |
@@ -123,9 +124,11 @@ layout.arc = function (g, target, query) |
123 | 124 |
n_left = setdiff(V(g)$name,V(g_con)$name) |
124 | 125 |
} |
125 | 126 |
|
126 |
- set = list(target = target, bridge=V(g_con)[type == "bridge"]$name, query1 = character(), query2 = character(), query3 = character(), left=n_left) |
|
127 |
- for(q in V(g_con)[type == "query"]$name) { |
|
128 |
- sp = get.all.shortest.paths(g_con,from=V(g_con)[q],to=V(g_con)[name %in% target]) |
|
127 |
+ all_type=V(g_con)$type |
|
128 |
+ all_name=V(g_con)$name |
|
129 |
+ set = list(target = target, bridge=V(g_con)[all_type == "bridge"]$name, query1 = character(), query2 = character(), query3 = character(), left=n_left) |
|
130 |
+ for(q in V(g_con)[all_type == "query"]$name) { |
|
131 |
+ sp = get.all.shortest.paths(g_con,from=V(g_con)[q],to=V(g_con)[all_name %in% target]) |
|
129 | 132 |
#print(sp) |
130 | 133 |
sp_min = min(sapply(sp$res,length)) |
131 | 134 |
#print(sp_min) |
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/rTRM@80836 bc3139a8-67e5-0310-9ffc-ced21a209358
... | ... |
@@ -126,9 +126,9 @@ layout.arc = function (g, target, query) |
126 | 126 |
set = list(target = target, bridge=V(g_con)[type == "bridge"]$name, query1 = character(), query2 = character(), query3 = character(), left=n_left) |
127 | 127 |
for(q in V(g_con)[type == "query"]$name) { |
128 | 128 |
sp = get.all.shortest.paths(g_con,from=V(g_con)[q],to=V(g_con)[name %in% target]) |
129 |
- print(sp) |
|
129 |
+ #print(sp) |
|
130 | 130 |
sp_min = min(sapply(sp$res,length)) |
131 |
- print(sp_min) |
|
131 |
+ #print(sp_min) |
|
132 | 132 |
if(sp_min == 2) { |
133 | 133 |
set$query1 = c(set$query1, V(g_con)[q]$name) |
134 | 134 |
} |
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/rTRM@79428 bc3139a8-67e5-0310-9ffc-ced21a209358
... | ... |
@@ -99,3 +99,62 @@ getConcentricList = function(g, t, e, max.size = 60, order.by = "label") { |
99 | 99 |
} |
100 | 100 |
res |
101 | 101 |
} |
102 |
+ |
|
103 |
+layout.arc = function (g, target, query) |
|
104 |
+{ |
|
105 |
+ n = vcount(g) |
|
106 |
+ if(! all(target %in% V(g)$name)) { |
|
107 |
+ warning("some targets not in graph, removing them.") |
|
108 |
+ target=target[target %in% V(g)$name] |
|
109 |
+ } |
|
110 |
+ |
|
111 |
+ # |
|
112 |
+ target = target[target %in% query] |
|
113 |
+ |
|
114 |
+ V(g)$type = "bridge" |
|
115 |
+ V(g)[name %in% query]$type = "query" |
|
116 |
+ V(g)[name %in% target]$type = "target" |
|
117 |
+ |
|
118 |
+ g_con = g |
|
119 |
+ n_left = character() |
|
120 |
+ |
|
121 |
+ if(! is.connected(g)) { |
|
122 |
+ g_con = getLargestComp(g) |
|
123 |
+ n_left = setdiff(V(g)$name,V(g_con)$name) |
|
124 |
+ } |
|
125 |
+ |
|
126 |
+ set = list(target = target, bridge=V(g_con)[type == "bridge"]$name, query1 = character(), query2 = character(), query3 = character(), left=n_left) |
|
127 |
+ for(q in V(g_con)[type == "query"]$name) { |
|
128 |
+ sp = get.all.shortest.paths(g_con,from=V(g_con)[q],to=V(g_con)[name %in% target]) |
|
129 |
+ print(sp) |
|
130 |
+ sp_min = min(sapply(sp$res,length)) |
|
131 |
+ print(sp_min) |
|
132 |
+ if(sp_min == 2) { |
|
133 |
+ set$query1 = c(set$query1, V(g_con)[q]$name) |
|
134 |
+ } |
|
135 |
+ else set$query2 = c(set$query2, V(g_con)[q]$name) |
|
136 |
+ } |
|
137 |
+ |
|
138 |
+ set = lapply(set,function(s) { |
|
139 |
+ ns = V(g)[s]$label |
|
140 |
+ s[order(ns,decreasing=TRUE)] |
|
141 |
+ }) |
|
142 |
+ |
|
143 |
+ x0 = c(left=-2,query1=-1,target=0,bridge=1,query2=2) |
|
144 |
+ y0 = sapply(set,function(x){ |
|
145 |
+ -1 * floor(length(x)/2) |
|
146 |
+ }) |
|
147 |
+ |
|
148 |
+ res = matrix(NA, nrow = n, ncol = 2) |
|
149 |
+ all_n = unlist(set) |
|
150 |
+ for(my_n in all_n) { |
|
151 |
+ k = which(V(g)$name == my_n) |
|
152 |
+ my_type = names(set)[sapply(set,function(x) my_n %in% x)] |
|
153 |
+ x1 = x0[my_type] |
|
154 |
+ y1 = y0[my_type] |
|
155 |
+ y0[my_type] = y0[my_type] + 1 |
|
156 |
+ res[k,1] = x1 |
|
157 |
+ res[k,2] = y1 |
|
158 |
+ } |
|
159 |
+ res |
|
160 |
+} |
|
102 | 161 |
\ No newline at end of file |
git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/rTRM@78001 bc3139a8-67e5-0310-9ffc-ced21a209358
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,101 @@ |
1 |
+.getCoordinates = function(x, r) { |
|
2 |
+ l = length(x) |
|
3 |
+ d = 360/l |
|
4 |
+ c1 = seq(0, 360, d) |
|
5 |
+ c1 = c1[1:(length(c1)-1)] |
|
6 |
+ tmp = t(sapply(c1, function(cc) c(cos(cc*pi/180)*r, sin(cc*pi/180)*r))) |
|
7 |
+ rownames(tmp) = x |
|
8 |
+ tmp |
|
9 |
+} |
|
10 |
+ |
|
11 |
+.checkValid = function(x) { |
|
12 |
+ if(any(table(x) > 1)) FALSE else TRUE |
|
13 |
+} |
|
14 |
+ |
|
15 |
+# TODO: make layout independent the $name $label (i.e. based on indexes.) |
|
16 |
+layout.concentric = function (g, concentric = NULL, radius = NULL, order.by) |
|
17 |
+{ |
|
18 |
+ if(is.null(concentric)) |
|
19 |
+ concentric = list(V(g)$name) |
|
20 |
+ |
|
21 |
+ all_c = unlist(concentric, use.names = FALSE) |
|
22 |
+ |
|
23 |
+ if (!.checkValid(all_c)) |
|
24 |
+ stop("Duplicated nodes in layers!") |
|
25 |
+ |
|
26 |
+ if (!.checkValid(radius)) |
|
27 |
+ stop("Duplicated radius in layers!") |
|
28 |
+ |
|
29 |
+ all_n = V(g)$name |
|
30 |
+ sel_other = all_n[ ! all_n %in% all_c ] |
|
31 |
+ |
|
32 |
+ if(length(sel_other) > 0) |
|
33 |
+ concentric[[length(concentric)+1]] = sel_other |
|
34 |
+ |
|
35 |
+ if(is.null(radius)) { |
|
36 |
+ radius = seq(0, 1, 1/(length(concentric))) |
|
37 |
+ if(length(concentric[[1]]) == 1) |
|
38 |
+ radius = radius[-length(radius)] |
|
39 |
+ else |
|
40 |
+ radius = radius[-1] |
|
41 |
+ } |
|
42 |
+ |
|
43 |
+ if( ! missing(order.by) ) |
|
44 |
+ order.values = lapply(order.by, function(b) get.vertex.attribute(g, b)) |
|
45 |
+ |
|
46 |
+ res = matrix(NA, nrow = length(all_n), ncol = 2) |
|
47 |
+ for(k in 1:length(concentric)) { |
|
48 |
+ r = radius[k] |
|
49 |
+ l = concentric[[k]] |
|
50 |
+ |
|
51 |
+ i = which(V(g)$name %in% l) - 1 |
|
52 |
+ i_o = i |
|
53 |
+ if (!missing(order.by)) { |
|
54 |
+ ob = lapply(order.values, function(v) v[i + 1]) |
|
55 |
+ ord = do.call(order, ob) |
|
56 |
+ i_o = i_o[ord] |
|
57 |
+ } |
|
58 |
+ res[i_o+1, ] = .getCoordinates(i_o, r) |
|
59 |
+ |
|
60 |
+ } |
|
61 |
+ res |
|
62 |
+} |
|
63 |
+ |
|
64 |
+getConcentricList = function(g, t, e, max.size = 60, order.by = "label") { |
|
65 |
+ sel.all = V(g)$name |
|
66 |
+ |
|
67 |
+ # filter out not in graph. |
|
68 |
+ t = t[t %in% sel.all] |
|
69 |
+ e = e[e %in% sel.all] |
|
70 |
+ |
|
71 |
+ sel.e = V(g)[ e ]$name |
|
72 |
+ sel.t = V(g)[ t ]$name |
|
73 |
+ sel.t = sel.t[sel.t %in% sel.e ] # choose only target that are enriched. |
|
74 |
+ sel.e = sel.e[! sel.e %in% sel.t ] |
|
75 |
+ |
|
76 |
+ sel.b = sel.all[! sel.all %in% c(sel.t, sel.e) ] |
|
77 |
+ |
|
78 |
+ tmp = list(sel.t, sel.b, sel.e) |
|
79 |
+ |
|
80 |
+ if(!is.null(order.by)) { |
|
81 |
+ tmp = lapply(tmp, function(l) { |
|
82 |
+ l[order(get.vertex.attribute(g, order.by, V(g)[ l ]))] |
|
83 |
+ }) |
|
84 |
+ } |
|
85 |
+ |
|
86 |
+ res = list() |
|
87 |
+ for(k in 1:length(tmp)) { |
|
88 |
+ r = tmp[[k]] |
|
89 |
+ if(length(r)>max.size) { |
|
90 |
+ s = ceiling(length(r)/max.size) |
|
91 |
+ #r1 = split(r,rep(1:s, s,length.out = length(r))) |
|
92 |
+ v = rep(1:s, each = ceiling(length(r)/s)) |
|
93 |
+ v = v[1:length(r)] |
|
94 |
+ r1 = split(r,v) |
|
95 |
+ for(kk in r1) { |
|
96 |
+ res[[length(res)+1]] = kk |
|
97 |
+ } |
|
98 |
+ } else res[[length(res)+1]] = r |
|
99 |
+ } |
|
100 |
+ res |
|
101 |
+} |