修订版 | 267fb20686e1ca7ef03a921dc35d2fbc9c8910fc (tree) |
---|---|
时间 | 2022-03-25 07:19:27 |
作者 | Lorenzo Isella <lorenzo.isella@gmai...> |
Commiter | Lorenzo Isella |
I added multiple bond removal strategies.
@@ -164,6 +164,94 @@ | ||
164 | 164 | } |
165 | 165 | |
166 | 166 | |
167 | + | |
168 | + | |
169 | +fragment_cluster_prob2 <- function(g, probs){ | |
170 | + | |
171 | + n_rep <- 4 | |
172 | + set.seed(1234) | |
173 | + | |
174 | + | |
175 | + n_links=E(g) | |
176 | + mysamp <- seq(n_links) | |
177 | + | |
178 | + n_rem <- sum(probs>0)*n_rep | |
179 | + | |
180 | + myseq <- sample(mysamp, n_rem,replace=T, probs) | |
181 | + | |
182 | + frag_dist <- c() | |
183 | + | |
184 | + | |
185 | + for (i in myseq){ | |
186 | + | |
187 | + | |
188 | + g_broken <- delete.edges(g,i) | |
189 | + | |
190 | + fragments <- clusters(g_broken)$csize | |
191 | + if(length(fragments)==1){ | |
192 | + fragments=c(0, fragments) | |
193 | + | |
194 | + ## print("No frag!!!") | |
195 | + } | |
196 | + fragments_tibble <- tibble(n1=fragments[1], n2=fragments[2]) | |
197 | + ## print(fragments_tibble) | |
198 | + | |
199 | + frag_dist <- bind_rows(frag_dist, fragments_tibble) | |
200 | + | |
201 | + } | |
202 | + | |
203 | + frag_dist <- frag_dist %>% | |
204 | + mutate(e1=if_else(n1<=n2, n1, n2), | |
205 | + e2=if_else(n1>=n2, n1, n2)) %>% | |
206 | + mutate(n1=e1,n2=e2) %>% | |
207 | + select(-c(e1,e2)) | |
208 | + | |
209 | + return(frag_dist) | |
210 | +} | |
211 | + | |
212 | + | |
213 | + | |
214 | + | |
215 | + | |
216 | +select_chunk <- function(x, low, high){ | |
217 | + | |
218 | + if (low<0 | high<0 | low>1 | high>1 | low >=high){ | |
219 | + | |
220 | + print("error in the definition of high and low") | |
221 | + | |
222 | + } else { | |
223 | + | |
224 | + ss <- sort(x, index.return=T, decreasing=F) | |
225 | + n <- length(x) | |
226 | + | |
227 | + low_cut <- round(n*low, 0) | |
228 | + high_cut <- round(n*high, 0) | |
229 | + res <- ss$ix[low_cut:high_cut] | |
230 | + | |
231 | + } | |
232 | + | |
233 | +} | |
234 | + | |
235 | + | |
236 | + | |
237 | +select_chunk_reset <- function(x, low, high){ | |
238 | + | |
239 | + | |
240 | + chunk <- select_chunk(x, low, high) | |
241 | + | |
242 | + ## print("chunk is, ") | |
243 | + ## print(chunk) | |
244 | + | |
245 | + x[-chunk] <- 0 | |
246 | + | |
247 | + return(x) | |
248 | + | |
249 | + | |
250 | +} | |
251 | + | |
252 | + | |
253 | + | |
254 | + | |
167 | 255 | ##################################################################### |
168 | 256 | ##################################################################### |
169 | 257 | ##################################################################### |
@@ -251,33 +339,12 @@ | ||
251 | 339 | condition = "input.vis_calc == 'Fragmentation Statistics' ", |
252 | 340 | radioButtons("frag_calc", "Select Type of Bond Removal", |
253 | 341 | choices = c("Uniform Probability", |
254 | - "Shell around CM (in units of Rg)", | |
255 | - "Bond betweenness"), | |
342 | + "Bond betweenness", | |
343 | + "Quantile Range for Bond Betweenness"), | |
256 | 344 | selected = "Uniform Probability" ) |
257 | 345 | ), |
258 | 346 | |
259 | 347 | |
260 | - # Main panel for displaying outputs ---- | |
261 | - ## mainPanel( | |
262 | - | |
263 | - # Output: Data file ---- | |
264 | - ## tableOutput("contents2"), | |
265 | - | |
266 | - ## tableOutput("contents3"), | |
267 | - | |
268 | - ## conditionalPanel( | |
269 | - ## condition = "input.data_choice == 'ingressi_terapia_intensiva' ", | |
270 | - ## plotlyOutput("myplot3" | |
271 | - ## ) | |
272 | - ## ) | |
273 | - | |
274 | - | |
275 | - | |
276 | - ## ({ | |
277 | - ## rglwidgetOutput("myplot" , width = "auto" , height = "1280" | |
278 | - ## ) | |
279 | - ## }) | |
280 | - | |
281 | 348 | |
282 | 349 | conditionalPanel( |
283 | 350 | condition = "input.vis_calc == 'Visualization' ", |
@@ -301,6 +368,21 @@ | ||
301 | 368 | DTOutput("frag2") |
302 | 369 | ), |
303 | 370 | |
371 | + | |
372 | + conditionalPanel( | |
373 | + condition = "input.vis_calc == 'Fragmentation Statistics' && | |
374 | +input.frag_calc == 'Quantile Range for Bond Betweenness' ", | |
375 | + DTOutput("frag3") | |
376 | +), | |
377 | + | |
378 | + conditionalPanel( | |
379 | + condition = "input.vis_calc == 'Fragmentation Statistics' && | |
380 | +input.frag_calc == 'Quantile Range for Bond Betweenness' ", | |
381 | + | |
382 | +sliderInput("betrange", "Quantile Range:",min = 0, max = 1, value = c(0,0.3), | |
383 | + step=1e-2) | |
384 | +), | |
385 | + | |
304 | 386 | conditionalPanel( |
305 | 387 | condition = "input.vis_calc == 'Fragmentation Statistics' ", |
306 | 388 | downloadButton("downloadData", HTML("Download Fragmentation Raw Data")) |
@@ -416,7 +498,11 @@ | ||
416 | 498 | }) |
417 | 499 | |
418 | 500 | |
419 | - | |
501 | + fragments3 <- reactive({ | |
502 | + | |
503 | + fragment_cluster_prob2(g(), betweenness_list_quantiles()) | |
504 | + | |
505 | + }) | |
420 | 506 | |
421 | 507 | |
422 | 508 |
@@ -427,6 +513,9 @@ | ||
427 | 513 | output$frag2 <- renderDT({datatable(fragments2()) |
428 | 514 | }) |
429 | 515 | |
516 | + output$frag3 <- renderDT({datatable(fragments3()) | |
517 | + }) | |
518 | + | |
430 | 519 | |
431 | 520 | |
432 | 521 | df_frag <- reactive({ |
@@ -436,7 +525,10 @@ | ||
436 | 525 | } else if (input$frag_calc == "Bond betweenness"){ |
437 | 526 | |
438 | 527 | fragments2() |
439 | - } | |
528 | + } else if (input$frag_calc == "Quantile Range for Bond Betweenness"){ | |
529 | + | |
530 | + fragments3() | |
531 | + } | |
440 | 532 | |
441 | 533 | |
442 | 534 |
@@ -448,6 +540,17 @@ | ||
448 | 540 | mutate(n1_norm=n1/(n1+n2)) |
449 | 541 | |
450 | 542 | }) |
543 | + | |
544 | + | |
545 | + betweenness_list_quantiles <- reactive({ | |
546 | + | |
547 | + eb <- edge_betweenness(g(), directed=F) %>% | |
548 | + select_chunk_reset(min(input$betrange), max(input$betrange)) | |
549 | + | |
550 | + | |
551 | +}) | |
552 | + | |
553 | + | |
451 | 554 | |
452 | 555 | bond_segments <- reactive({ |
453 | 556 | ## g <- get_network_from_table2(agg(), input$cutoff) |
@@ -571,7 +674,7 @@ | ||
571 | 674 | ## ## colors = scico(n_col, palette="hawai"), |
572 | 675 | ## mode = 'markers' |
573 | 676 | ) %>% |
574 | - layout( bargap=0.1) | |
677 | + layout( bargap=0.1, xaxis = list(range=c(0,.5))) | |
575 | 678 | ## %>% |
576 | 679 | ## layout(hovermode = "x unified",xaxis = list(title="", |
577 | 680 | ## tickformat="%d %b"), |