-
Notifications
You must be signed in to change notification settings - Fork 0
/
widgetRelevantGenes.R
99 lines (78 loc) · 3.36 KB
/
widgetRelevantGenes.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#'
#' Defines widget that allows finding the clustering relevant genes using
#' a heuristic.
#'
library(DT)
library(shiny)
source("uiHelper.R")
source("plotAgglomerativeClusteringPlot.R")
source("relevantGenes.R")
source("helpers.R")
relevantGenesUI <- function(id) {
ns <- NS(id)
return(tagList(
selectizeInput(ns("fdistance"), "Distance method", choices = plotAgglomerativeClusteringPlotUI.dist.methodsSelection),
selectizeInput(ns("flink"), "Clustering method", choices = plotAgglomerativeClusteringPlotUI.hclust.methodsSelection),
checkboxInput(ns("pca.enable"), "Apply PCA", value = F),
conditionalPanel(conditionalPanel.equals(ns("pca.enable"), "true"),
tags$p("Result depends on PCA parameters.")),
actionButton(ns("calculate"), "Calculate threshold")
))
}
relevantGenesValue_ <- function(input,
output,
session,
readcounts,
pca.center,
pca.scale) {
values <- reactiveValues(threshold = NULL)
observeEvent(input$calculate, {
if(is.null(readcounts())) {
showNotification("No read counts to process!", type = "error")
return()
}
shinyjs::disable("calculate")
progress <- shiny::Progress$new()
progress$set(message = "Running calculations ...", value = 0)
# Status callback function
updateProgress <- function(detail = NULL, value = NULL) {
progress$set(value = value, detail = detail)
}
values$threshold <- NULL
data <- assay(readcounts())
data <- data[order(rowVars(data), decreasing = T),]
reference.clustering <- clustering(data,
method.dist = input$fdistance,
method.link = input$flink,
pca.enable = input$pca.enable,
pca.center = pca.center(),
pca.scale = pca.scale())
parallel.expr <- function() {
return(find.minimal.clustering.genes.index(data = data,
reference.clustering = reference.clustering,
method.dist = input$fdistance,
method.link = input$flink,
pca.enable = input$pca.enable,
pca.center = pca.center(),
pca.scale = pca.scale(),
updateProgress = updateProgress))
}
withParallel(session, input,
expr = parallel.expr(),
exprsuccess = function(result) {
values$threshold <- result
},
exprfinally = function() {
progress$close()
shinyjs::enable("calculate")
})
})
return(reactive({ values$threshold }))
}
relevantGenesValue <- function(id, readcounts, pca.center, pca.scale) {
return(callModule(relevantGenesValue_,
id,
readcounts = readcounts,
pca.center = pca.center,
pca.scale = pca.scale))
}