From 8023efdf82382c3bca8710421a2df60e6bd6ea82 Mon Sep 17 00:00:00 2001 From: Giulio Benedetti Date: Tue, 9 Sep 2025 21:30:05 +0300 Subject: [PATCH 1/3] Initialise Cluster tab --- DESCRIPTION | 3 ++- NAMESPACE | 5 +++++ R/constants.R | 15 ++++++++++---- R/landing_page.R | 54 ++++++++++++++++++++++++++++++++++++++++++++---- R/observers.R | 54 ++++++++++++++++++++++++++++++++++++++++++++---- man/constants.Rd | 16 +++++++++++--- 6 files changed, 131 insertions(+), 16 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b589bc7..8cc1efa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,6 +25,7 @@ Depends: shiny Imports: ape, + bluster, htmltools, iSEEtree (>= 1.1.4), mia, @@ -50,6 +51,6 @@ Suggests: URL: https://github.com/microbiome/miaDash BugReports: https://github.com/microbiome/miaDash/issues Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.3 VignetteBuilder: knitr Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index 5e53c62..cc55bb5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,6 +9,10 @@ importFrom(SummarizedExperiment,rowData) importFrom(TreeSummarizedExperiment,TreeSummarizedExperiment) importFrom(TreeSummarizedExperiment,rowTree) importFrom(ape,read.tree) +importFrom(bluster,DmmParam) +importFrom(bluster,HclustParam) +importFrom(bluster,KmeansParam) +importFrom(bluster,NNGraphParam) importFrom(htmltools,HTML) importFrom(htmltools,br) importFrom(htmltools,div) @@ -27,6 +31,7 @@ importFrom(iSEEtree,RowGraphPlot) importFrom(iSEEtree,RowTreePlot) importFrom(iSEEtree,ScreePlot) importFrom(mia,addAlpha) +importFrom(mia,addCluster) importFrom(mia,addHierarchyTree) importFrom(mia,addPrevalence) importFrom(mia,addPrevalentAbundance) diff --git a/R/constants.R b/R/constants.R index e6ed221..528e32d 100644 --- a/R/constants.R +++ b/R/constants.R @@ -18,7 +18,8 @@ #' @keywords internal #' @name constants #' @aliases .miaDashDefaultPanels .miaDashOtherPanels .transformMethods -#' .alphaMetrics .betaMetrics .betaMethods .qualityMetrics +#' .qualityMetrics .alphaMetrics .betaMetrics .betaMethods .clustMethods +#' .DmmCriteria NULL #' @rdname constants @@ -36,6 +37,11 @@ NULL "hellinger", "log", "log10", "log2", "max", "normalize", "pa",# "philr", "range", "rank", "rclr", "relabundance", "rrank", "standardize", "total") +#' @rdname constants +.qualityMetrics <- list("Library size" = "PerCellQC", + "Prevalence" = "Prevalence", "Prevalent abundance" = "PrevalentAbundance", + "Hierarchy tree" = "HierarchyTree") + #' @rdname constants .alphaMetrics <- c("coverage_diversity", "fisher_diversity", "faith_diversity", "gini_simpson_diversity", "inverse_simpson_diversity", @@ -54,6 +60,7 @@ NULL #"TSNE", "UMAP") #' @rdname constants -.qualityMetrics <- list("Library size" = "PerCellQC", - "Prevalence" = "Prevalence", "Prevalent abundance" = "PrevalentAbundance", - "Hierarchy tree" = "HierarchyTree") +.clustMethods <- c("Dmm", "Hclust", "Kmeans", "NNGraph") + +#' @rdname constants +.DmmCriteria <- c("laplace", "AIC", "BIC") diff --git a/R/landing_page.R b/R/landing_page.R index 0bb1e05..c9a38b4 100644 --- a/R/landing_page.R +++ b/R/landing_page.R @@ -93,7 +93,8 @@ div(style = "margin-top: -20px"), conditionalPanel( - condition = "input.ftype == 'Mothur' | input.ftype == 'QIIME2'", + condition = paste0("input.ftype == 'Mothur' | ", + "input.ftype == 'QIIME2'"), fileInput(inputId = "f.rowdata", label = "rowData:", accept = c(".taxonomy", @@ -101,7 +102,8 @@ div(style = "margin-top: -20px")), conditionalPanel( - condition = "input.ftype == 'biom' | input.ftype == 'MetaPhlAn'", + condition = paste0("input.ftype == 'biom' | ", + "input.ftype == 'MetaPhlAn'"), fileInput(inputId = "tree.file", label = "rowTree:", placeholder = "tree.tree", @@ -109,7 +111,8 @@ div(style = "margin-top: -20px")), conditionalPanel( - condition = "input.ftype == 'biom' | input.ftype == 'HUMAnN'", + condition = paste0("input.ftype == 'biom' | ", + "input.ftype == 'HUMAnN'"), checkboxInput(inputId = "rm.tax.pref", label = "Remove taxa prefixes")), @@ -204,7 +207,7 @@ inline = TRUE), conditionalPanel( - condition = paste("input.bmethod == 'MDS' || ", + condition = paste0("input.bmethod == 'MDS' || ", "input.bmethod == 'NMDS' || ", "input.bmethod == 'RDA'"), @@ -222,6 +225,49 @@ label = "Number of components:", min = 1, step = 1)), + tabPanel(title = "Cluster", value = "cluster", + + radioButtons(inputId = "cmethod", + label = "Method:", choices = .clustMethods, + inline = TRUE), + + conditionalPanel( + condition = paste0("input.cmethod == 'Dmm' | ", + "input.cmethod == 'Kmeans'"), + + numericInput(inputId = "kclusters", value = 3, + label = "Number of clusters:", min = 1, + step = 1)), + + conditionalPanel( + condition = "input.cmethod == 'Dmm'", + + selectInput(inputId = "dmm.type", + label = "Criterion:", + choices = .DmmCriteria, + selected = .DmmCriteria[1]), + + numericInput(inputId = "dmm.seed", value = 1L, + label = "Seed:", min = 0, step = 1)), + + conditionalPanel( + condition = "input.cmethod == 'NNGraph'", + + numericInput(inputId = "kneighbours", + value = 10, label = "Number of neighbours:", + min = 1, step = 1), + + checkboxInput(inputId = "nn.shared", + label = "Construct shared graph")), + + checkboxInput(inputId = "clust.full", + label = "Add to metadata"), + + radioButtons(inputId = "clust.margin", + label = "Margin:", inline = TRUE, + choices = c("samples", "features"), + selected = "features")), + footer = textInput(inputId = "estimate.name", label = "Name:")), diff --git a/R/observers.R b/R/observers.R index d4f4977..80e49b6 100644 --- a/R/observers.R +++ b/R/observers.R @@ -67,7 +67,7 @@ rObjects$tse <- .update_tse( rObjects$tse, TreeSummarizedExperiment, fun_args ) - print(input$taxa.from.rownames) + if( input$taxa.from.rownames ){ rObjects$tse <- .update_tse( @@ -223,11 +223,12 @@ #' @rdname create_observers #' @importFrom stats as.formula #' @importFrom mia addAlpha runNMDS runRDA getDissimilarity addHierarchyTree -#' addPrevalence addPrevalentAbundance +#' addPrevalence addPrevalentAbundance addCluster #' @importFrom TreeSummarizedExperiment rowTree #' @importFrom scater runMDS runPCA #' @importFrom scuttle addPerCellQC #' @importFrom vegan vegdist +#' @importFrom bluster KmeansParam DmmParam HclustParam NNGraphParam .create_estimate_observers <- function(input, rObjects) { # nocov start @@ -295,7 +296,8 @@ name <- input$bmethod } - beta_args <- list(x = rObjects$tse, assay.type = input$assay.type, + beta_args <- list(x = rObjects$tse, + assay.type = input$estimate.assay, ncomponents = input$ncomponents, name = name) if( input$beta.index == "unifrac" ){ @@ -329,7 +331,6 @@ beta_args <- c(beta_args, formula = as.formula(input$rda.formula)) - } beta_fun <- eval(parse(text = paste0("run", input$bmethod))) @@ -337,6 +338,51 @@ rObjects$tse <- .update_tse(rObjects$tse, beta_fun, beta_args) }) + }else if( input$estimate == "cluster" ){ + + isolate({ + req(input$estimate.assay) + + if( input$estimate.name != "" ){ + name <- input$estimate.name + }else{ + name <- "clusters" + } + + if( input$cmethod == "Dmm" ){ + + blus_params <- list(k = input$kclusters, + type = deparse(input$dmm.type))#, seed = input$dmm.seed) + + }else if( input$cmethod == "Hclust" ){ + + blus_params <- list() + + }else if( input$cmethod == "Kmeans" ){ + + blus_params <- list(centers = input$kclusters) + + }else if( input$cmethod == "NNGraph" ){ + + blus_params <- list(shared = input$nn.shared, + k = input$kneighbours) + + } + + blus_params <- sprintf("%s=%s", names(blus_params), blus_params) + blus_params <- paste(blus_params, collapse = ", ") + blus_fun <- sprintf("%sParam(%s)", input$cmethod, blus_params) + + clust_args <- list(x = rObjects$tse, + assay.type = input$estimate.assay, + by = input$clust.margin, full = input$clust.full, + BLUSPARAM = eval(parse(text = blus_fun)), + name = name, clust.col = name) + + rObjects$tse <- .update_tse( + rObjects$tse, addCluster, clust_args) + }) + } }, ignoreInit = TRUE, ignoreNULL = TRUE) diff --git a/man/constants.Rd b/man/constants.Rd index ffb4fe2..d60b96a 100644 --- a/man/constants.Rd +++ b/man/constants.Rd @@ -6,10 +6,12 @@ \alias{.miaDashDefaultPanels} \alias{.miaDashOtherPanels} \alias{.transformMethods} +\alias{.qualityMetrics} \alias{.alphaMetrics} \alias{.betaMetrics} \alias{.betaMethods} -\alias{.qualityMetrics} +\alias{.clustMethods} +\alias{.DmmCriteria} \title{Constants} \format{ An object of class \code{character} of length 7. @@ -18,13 +20,17 @@ An object of class \code{character} of length 9. An object of class \code{character} of length 19. +An object of class \code{list} of length 4. + An object of class \code{character} of length 23. An object of class \code{character} of length 4. An object of class \code{character} of length 4. -An object of class \code{list} of length 4. +An object of class \code{character} of length 4. + +An object of class \code{character} of length 3. } \usage{ .miaDashDefaultPanels @@ -33,13 +39,17 @@ An object of class \code{list} of length 4. .transformMethods +.qualityMetrics + .alphaMetrics .betaMetrics .betaMethods -.qualityMetrics +.clustMethods + +.DmmCriteria } \description{ Constant values used throughout the miaDash app. From bc867cbc5b31aa4290e4e44fdfad19222918d749 Mon Sep 17 00:00:00 2001 From: Giulio Benedetti Date: Tue, 9 Sep 2025 21:31:41 +0300 Subject: [PATCH 2/3] Bump version --- NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS b/NEWS index 8440115..916d8e8 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +Changes in version 1.1.5 +* Added Cluster tab + Changes in version 1.1.4 * Switch from csv to tsv support * Improve interoperability with MGnify datasets From 9644d5e91675032f5de39d266949dff9189323e6 Mon Sep 17 00:00:00 2001 From: Giulio Benedetti Date: Tue, 9 Sep 2025 21:39:21 +0300 Subject: [PATCH 3/3] Bump version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8cc1efa..5622198 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: miaDash -Version: 1.1.4 +Version: 1.1.5 Authors@R: c(person(given = "Giulio", family = "Benedetti", role = c("aut", "cre"), email = "giulio.benedetti@utu.fi",