• R/O
  • SSH

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修订版267fb20686e1ca7ef03a921dc35d2fbc9c8910fc (tree)
时间2022-03-25 07:19:27
作者Lorenzo Isella <lorenzo.isella@gmai...>
CommiterLorenzo Isella

Log Message

I added multiple bond removal strategies.

更改概述

差异

diff -r 0b42637ca63e -r 267fb20686e1 R-codes/read_plot_aggregate_shiny.R
--- a/R-codes/read_plot_aggregate_shiny.R Thu Mar 24 12:05:24 2022 +0100
+++ b/R-codes/read_plot_aggregate_shiny.R Thu Mar 24 23:19:27 2022 +0100
@@ -164,6 +164,94 @@
164164 }
165165
166166
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+
167255 #####################################################################
168256 #####################################################################
169257 #####################################################################
@@ -251,33 +339,12 @@
251339 condition = "input.vis_calc == 'Fragmentation Statistics' ",
252340 radioButtons("frag_calc", "Select Type of Bond Removal",
253341 choices = c("Uniform Probability",
254- "Shell around CM (in units of Rg)",
255- "Bond betweenness"),
342+ "Bond betweenness",
343+ "Quantile Range for Bond Betweenness"),
256344 selected = "Uniform Probability" )
257345 ),
258346
259347
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-
281348
282349 conditionalPanel(
283350 condition = "input.vis_calc == 'Visualization' ",
@@ -301,6 +368,21 @@
301368 DTOutput("frag2")
302369 ),
303370
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+
304386 conditionalPanel(
305387 condition = "input.vis_calc == 'Fragmentation Statistics' ",
306388 downloadButton("downloadData", HTML("Download Fragmentation Raw Data"))
@@ -416,7 +498,11 @@
416498 })
417499
418500
419-
501+ fragments3 <- reactive({
502+
503+ fragment_cluster_prob2(g(), betweenness_list_quantiles())
504+
505+ })
420506
421507
422508
@@ -427,6 +513,9 @@
427513 output$frag2 <- renderDT({datatable(fragments2())
428514 })
429515
516+ output$frag3 <- renderDT({datatable(fragments3())
517+ })
518+
430519
431520
432521 df_frag <- reactive({
@@ -436,7 +525,10 @@
436525 } else if (input$frag_calc == "Bond betweenness"){
437526
438527 fragments2()
439- }
528+ } else if (input$frag_calc == "Quantile Range for Bond Betweenness"){
529+
530+ fragments3()
531+ }
440532
441533
442534
@@ -448,6 +540,17 @@
448540 mutate(n1_norm=n1/(n1+n2))
449541
450542 })
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+
451554
452555 bond_segments <- reactive({
453556 ## g <- get_network_from_table2(agg(), input$cutoff)
@@ -571,7 +674,7 @@
571674 ## ## colors = scico(n_col, palette="hawai"),
572675 ## mode = 'markers'
573676 ) %>%
574- layout( bargap=0.1)
677+ layout( bargap=0.1, xaxis = list(range=c(0,.5)))
575678 ## %>%
576679 ## layout(hovermode = "x unified",xaxis = list(title="",
577680 ## tickformat="%d %b"),