Skip to content

Commit 6b11cd5

Browse files
authored
Merge pull request #27 from microbiome/cluster
Add Cluster tab
2 parents 22dcfd3 + 9644d5e commit 6b11cd5

File tree

7 files changed

+135
-17
lines changed

7 files changed

+135
-17
lines changed

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: miaDash
2-
Version: 1.1.4
2+
Version: 1.1.5
33
Authors@R:
44
c(person(given = "Giulio", family = "Benedetti", role = c("aut", "cre"),
55
email = "giulio.benedetti@utu.fi",
@@ -25,6 +25,7 @@ Depends:
2525
shiny
2626
Imports:
2727
ape,
28+
bluster,
2829
htmltools,
2930
iSEEtree (>= 1.1.4),
3031
mia,
@@ -50,6 +51,6 @@ Suggests:
5051
URL: https://github.com/microbiome/miaDash
5152
BugReports: https://github.com/microbiome/miaDash/issues
5253
Roxygen: list(markdown = TRUE)
53-
RoxygenNote: 7.3.2
54+
RoxygenNote: 7.3.3
5455
VignetteBuilder: knitr
5556
Config/testthat/edition: 3

NAMESPACE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ importFrom(SummarizedExperiment,rowData)
99
importFrom(TreeSummarizedExperiment,TreeSummarizedExperiment)
1010
importFrom(TreeSummarizedExperiment,rowTree)
1111
importFrom(ape,read.tree)
12+
importFrom(bluster,DmmParam)
13+
importFrom(bluster,HclustParam)
14+
importFrom(bluster,KmeansParam)
15+
importFrom(bluster,NNGraphParam)
1216
importFrom(htmltools,HTML)
1317
importFrom(htmltools,br)
1418
importFrom(htmltools,div)
@@ -27,6 +31,7 @@ importFrom(iSEEtree,RowGraphPlot)
2731
importFrom(iSEEtree,RowTreePlot)
2832
importFrom(iSEEtree,ScreePlot)
2933
importFrom(mia,addAlpha)
34+
importFrom(mia,addCluster)
3035
importFrom(mia,addHierarchyTree)
3136
importFrom(mia,addPrevalence)
3237
importFrom(mia,addPrevalentAbundance)

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
Changes in version 1.1.5
2+
* Added Cluster tab
3+
14
Changes in version 1.1.4
25
* Switch from csv to tsv support
36
* Improve interoperability with MGnify datasets

R/constants.R

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
#' @keywords internal
1919
#' @name constants
2020
#' @aliases .miaDashDefaultPanels .miaDashOtherPanels .transformMethods
21-
#' .alphaMetrics .betaMetrics .betaMethods .qualityMetrics
21+
#' .qualityMetrics .alphaMetrics .betaMetrics .betaMethods .clustMethods
22+
#' .DmmCriteria
2223
NULL
2324

2425
#' @rdname constants
@@ -36,6 +37,11 @@ NULL
3637
"hellinger", "log", "log10", "log2", "max", "normalize", "pa",# "philr",
3738
"range", "rank", "rclr", "relabundance", "rrank", "standardize", "total")
3839

40+
#' @rdname constants
41+
.qualityMetrics <- list("Library size" = "PerCellQC",
42+
"Prevalence" = "Prevalence", "Prevalent abundance" = "PrevalentAbundance",
43+
"Hierarchy tree" = "HierarchyTree")
44+
3945
#' @rdname constants
4046
.alphaMetrics <- c("coverage_diversity", "fisher_diversity", "faith_diversity",
4147
"gini_simpson_diversity", "inverse_simpson_diversity",
@@ -54,6 +60,7 @@ NULL
5460
#"TSNE", "UMAP")
5561

5662
#' @rdname constants
57-
.qualityMetrics <- list("Library size" = "PerCellQC",
58-
"Prevalence" = "Prevalence", "Prevalent abundance" = "PrevalentAbundance",
59-
"Hierarchy tree" = "HierarchyTree")
63+
.clustMethods <- c("Dmm", "Hclust", "Kmeans", "NNGraph")
64+
65+
#' @rdname constants
66+
.DmmCriteria <- c("laplace", "AIC", "BIC")

R/landing_page.R

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,26 @@
9393
div(style = "margin-top: -20px"),
9494

9595
conditionalPanel(
96-
condition = "input.ftype == 'Mothur' | input.ftype == 'QIIME2'",
96+
condition = paste0("input.ftype == 'Mothur' | ",
97+
"input.ftype == 'QIIME2'"),
9798

9899
fileInput(inputId = "f.rowdata",
99100
label = "rowData:", accept = c(".taxonomy",
100101
".qza"), placeholder = "taxonomy or qza"),
101102
div(style = "margin-top: -20px")),
102103

103104
conditionalPanel(
104-
condition = "input.ftype == 'biom' | input.ftype == 'MetaPhlAn'",
105+
condition = paste0("input.ftype == 'biom' | ",
106+
"input.ftype == 'MetaPhlAn'"),
105107

106108
fileInput(inputId = "tree.file",
107109
label = "rowTree:", placeholder = "tree.tree",
108110
accept = c(".tree", ".tre", ".qza")),
109111
div(style = "margin-top: -20px")),
110112

111113
conditionalPanel(
112-
condition = "input.ftype == 'biom' | input.ftype == 'HUMAnN'",
114+
condition = paste0("input.ftype == 'biom' | ",
115+
"input.ftype == 'HUMAnN'"),
113116

114117
checkboxInput(inputId = "rm.tax.pref",
115118
label = "Remove taxa prefixes")),
@@ -204,7 +207,7 @@
204207
inline = TRUE),
205208

206209
conditionalPanel(
207-
condition = paste("input.bmethod == 'MDS' || ",
210+
condition = paste0("input.bmethod == 'MDS' || ",
208211
"input.bmethod == 'NMDS' || ",
209212
"input.bmethod == 'RDA'"),
210213

@@ -222,6 +225,49 @@
222225
label = "Number of components:", min = 1,
223226
step = 1)),
224227

228+
tabPanel(title = "Cluster", value = "cluster",
229+
230+
radioButtons(inputId = "cmethod",
231+
label = "Method:", choices = .clustMethods,
232+
inline = TRUE),
233+
234+
conditionalPanel(
235+
condition = paste0("input.cmethod == 'Dmm' | ",
236+
"input.cmethod == 'Kmeans'"),
237+
238+
numericInput(inputId = "kclusters", value = 3,
239+
label = "Number of clusters:", min = 1,
240+
step = 1)),
241+
242+
conditionalPanel(
243+
condition = "input.cmethod == 'Dmm'",
244+
245+
selectInput(inputId = "dmm.type",
246+
label = "Criterion:",
247+
choices = .DmmCriteria,
248+
selected = .DmmCriteria[1]),
249+
250+
numericInput(inputId = "dmm.seed", value = 1L,
251+
label = "Seed:", min = 0, step = 1)),
252+
253+
conditionalPanel(
254+
condition = "input.cmethod == 'NNGraph'",
255+
256+
numericInput(inputId = "kneighbours",
257+
value = 10, label = "Number of neighbours:",
258+
min = 1, step = 1),
259+
260+
checkboxInput(inputId = "nn.shared",
261+
label = "Construct shared graph")),
262+
263+
checkboxInput(inputId = "clust.full",
264+
label = "Add to metadata"),
265+
266+
radioButtons(inputId = "clust.margin",
267+
label = "Margin:", inline = TRUE,
268+
choices = c("samples", "features"),
269+
selected = "features")),
270+
225271
footer = textInput(inputId = "estimate.name",
226272
label = "Name:")),
227273

R/observers.R

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
rObjects$tse <- .update_tse(
6868
rObjects$tse, TreeSummarizedExperiment, fun_args
6969
)
70-
print(input$taxa.from.rownames)
70+
7171
if( input$taxa.from.rownames ){
7272

7373
rObjects$tse <- .update_tse(
@@ -223,11 +223,12 @@
223223
#' @rdname create_observers
224224
#' @importFrom stats as.formula
225225
#' @importFrom mia addAlpha runNMDS runRDA getDissimilarity addHierarchyTree
226-
#' addPrevalence addPrevalentAbundance
226+
#' addPrevalence addPrevalentAbundance addCluster
227227
#' @importFrom TreeSummarizedExperiment rowTree
228228
#' @importFrom scater runMDS runPCA
229229
#' @importFrom scuttle addPerCellQC
230230
#' @importFrom vegan vegdist
231+
#' @importFrom bluster KmeansParam DmmParam HclustParam NNGraphParam
231232
.create_estimate_observers <- function(input, rObjects) {
232233

233234
# nocov start
@@ -295,7 +296,8 @@
295296
name <- input$bmethod
296297
}
297298

298-
beta_args <- list(x = rObjects$tse, assay.type = input$assay.type,
299+
beta_args <- list(x = rObjects$tse,
300+
assay.type = input$estimate.assay,
299301
ncomponents = input$ncomponents, name = name)
300302

301303
if( input$beta.index == "unifrac" ){
@@ -329,14 +331,58 @@
329331

330332
beta_args <- c(beta_args,
331333
formula = as.formula(input$rda.formula))
332-
333334
}
334335

335336
beta_fun <- eval(parse(text = paste0("run", input$bmethod)))
336337

337338
rObjects$tse <- .update_tse(rObjects$tse, beta_fun, beta_args)
338339
})
339340

341+
}else if( input$estimate == "cluster" ){
342+
343+
isolate({
344+
req(input$estimate.assay)
345+
346+
if( input$estimate.name != "" ){
347+
name <- input$estimate.name
348+
}else{
349+
name <- "clusters"
350+
}
351+
352+
if( input$cmethod == "Dmm" ){
353+
354+
blus_params <- list(k = input$kclusters,
355+
type = deparse(input$dmm.type))#, seed = input$dmm.seed)
356+
357+
}else if( input$cmethod == "Hclust" ){
358+
359+
blus_params <- list()
360+
361+
}else if( input$cmethod == "Kmeans" ){
362+
363+
blus_params <- list(centers = input$kclusters)
364+
365+
}else if( input$cmethod == "NNGraph" ){
366+
367+
blus_params <- list(shared = input$nn.shared,
368+
k = input$kneighbours)
369+
370+
}
371+
372+
blus_params <- sprintf("%s=%s", names(blus_params), blus_params)
373+
blus_params <- paste(blus_params, collapse = ", ")
374+
blus_fun <- sprintf("%sParam(%s)", input$cmethod, blus_params)
375+
376+
clust_args <- list(x = rObjects$tse,
377+
assay.type = input$estimate.assay,
378+
by = input$clust.margin, full = input$clust.full,
379+
BLUSPARAM = eval(parse(text = blus_fun)),
380+
name = name, clust.col = name)
381+
382+
rObjects$tse <- .update_tse(
383+
rObjects$tse, addCluster, clust_args)
384+
})
385+
340386
}
341387

342388
}, ignoreInit = TRUE, ignoreNULL = TRUE)

man/constants.Rd

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)