From 7d6124f7e36a5f47983d31a827a15cb6ce378739 Mon Sep 17 00:00:00 2001 From: Giulio Benedetti Date: Fri, 25 Jul 2025 13:10:16 +0300 Subject: [PATCH] Make data import from MGnify smoother --- DESCRIPTION | 3 ++- NAMESPACE | 4 +++- NEWS | 4 ++++ R/constants.R | 3 ++- R/landing_page.R | 17 +++++++++++------ R/observers.R | 22 ++++++++++++++++------ R/utils.R | 21 +++++++++++++++++++++ README.md | 2 +- man/constants.Rd | 1 + man/utils.Rd | 6 ++++++ 10 files changed, 67 insertions(+), 16 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f63e1bb..b589bc7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: miaDash -Version: 1.1.3 +Version: 1.1.4 Authors@R: c(person(given = "Giulio", family = "Benedetti", role = c("aut", "cre"), email = "giulio.benedetti@utu.fi", @@ -33,6 +33,7 @@ Imports: scuttle, shinydashboard, shinyjs, + shinyWidgets, S4Vectors, SingleCellExperiment, SummarizedExperiment, diff --git a/NAMESPACE b/NAMESPACE index 0496495..5e53c62 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ importFrom(S4Vectors,DataFrame) importFrom(SummarizedExperiment,assay) importFrom(SummarizedExperiment,assayNames) importFrom(SummarizedExperiment,colData) +importFrom(SummarizedExperiment,rowData) importFrom(TreeSummarizedExperiment,TreeSummarizedExperiment) importFrom(TreeSummarizedExperiment,rowTree) importFrom(ape,read.tree) @@ -31,6 +32,7 @@ importFrom(mia,addPrevalence) importFrom(mia,addPrevalentAbundance) importFrom(mia,agglomerateByRank) importFrom(mia,getDissimilarity) +importFrom(mia,getTaxonomyLabels) importFrom(mia,importBIOM) importFrom(mia,importHUMAnN) importFrom(mia,importMetaPhlAn) @@ -46,6 +48,7 @@ importFrom(rintrojs,introjs) importFrom(scater,runMDS) importFrom(scater,runPCA) importFrom(scuttle,addPerCellQC) +importFrom(shinyWidgets,addSpinner) importFrom(shinydashboard,box) importFrom(shinydashboard,dashboardBody) importFrom(shinydashboard,dashboardHeader) @@ -56,6 +59,5 @@ importFrom(shinyjs,enable) importFrom(stats,as.formula) importFrom(utils,data) importFrom(utils,packageVersion) -importFrom(utils,read.csv) importFrom(utils,read.table) importFrom(vegan,vegdist) diff --git a/NEWS b/NEWS index a940602..8440115 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +Changes in version 1.1.4 +* Switch from csv to tsv support +* Improve interoperability with MGnify datasets + Changes in version 1.1.3 * Introduced tab for Quality Control diff --git a/R/constants.R b/R/constants.R index 5d70700..e6ed221 100644 --- a/R/constants.R +++ b/R/constants.R @@ -10,6 +10,7 @@ #' \item{\code{.alphaMetrics}}{List of alpha diversity metrics.} #' \item{\code{.betaMetrics}}{List of beta diversity metrics.} #' \item{\code{.betaMethods}}{List of beta diversity methods.} +#' \item{\code{.qualityMetrics}}{List of metrics for quality control.} #' } #' #' @author Giulio Benedetti @@ -17,7 +18,7 @@ #' @keywords internal #' @name constants #' @aliases .miaDashDefaultPanels .miaDashOtherPanels .transformMethods -#' .alphaMetrics .betaMetrics .betaMethods +#' .alphaMetrics .betaMetrics .betaMethods .qualityMetrics NULL #' @rdname constants diff --git a/R/landing_page.R b/R/landing_page.R index a344924..0bb1e05 100644 --- a/R/landing_page.R +++ b/R/landing_page.R @@ -14,6 +14,7 @@ #' dashboardBody box #' @importFrom htmltools HTML br tags div tagList #' @importFrom shinyjs disable +#' @importFrom shinyWidgets addSpinner #' @importFrom utils data .landing_page <- function(FUN, input, output, session) { @@ -49,16 +50,16 @@ tabPanel(title = "Raw Data", value = "raw", br(), fileInput(inputId = "assay", label = "Assays:", - accept = ".csv", multiple = TRUE, - placeholder = "assay.csv"), + accept = ".tsv", multiple = TRUE, + placeholder = "assay.tsv"), div(style = "margin-top: -20px"), fileInput(inputId = "coldata", label = "colData:", - accept = ".csv", placeholder = "coldata.csv"), + accept = ".tsv", placeholder = "coldata.tsv"), div(style = "margin-top: -20px"), fileInput(inputId = "rowdata", label = "rowData:", - accept = ".csv", placeholder = "rowdata.csv"), + accept = ".tsv", placeholder = "rowdata.tsv"), div(style = "margin-top: -20px"), fileInput(inputId = "row.tree", @@ -69,7 +70,10 @@ fileInput(inputId = "col.tree", label = "colTree:", placeholder = "col.tree", accept = c(".tree", ".tre")), - div(style = "margin-top: -20px")), + div(style = "margin-top: -20px"), + + checkboxInput(inputId = "taxa.from.rownames", + label = "Derive rowData from assay rownames")), tabPanel(title = "Foreign", value = "foreign", br(), @@ -237,7 +241,8 @@ box(id = "output.panel", title = "Output", width = 8, status = "primary", solidHeader = TRUE, collapsible = TRUE, - verbatimTextOutput(outputId = "object"), + addSpinner(verbatimTextOutput(outputId = "object"), + color = "#007bff"), downloadButton(outputId = "download", label = "Download", class = "btn-primary")))))}) diff --git a/R/observers.R b/R/observers.R index f360ab8..d4f4977 100644 --- a/R/observers.R +++ b/R/observers.R @@ -14,7 +14,7 @@ #' @keywords internal #' @rdname create_observers -#' @importFrom utils read.csv +#' @importFrom utils read.table #' @importFrom ape read.tree #' @importFrom S4Vectors DataFrame #' @importFrom mia importHUMAnN importMetaPhlAn importQIIME2 importMothur @@ -40,18 +40,20 @@ isolate({ req(input$assay) - + assay_list <- lapply(input$assay$datapath, - function(x) as.matrix(read.csv(x, row.names = 1))) + function(x) as.matrix(read.table(x, row.names = 1, + header = TRUE, sep = "\t"))) - names(assay_list) <- gsub(".csv", "", input$assay$name) + names(assay_list) <- gsub(".tsv", "", input$assay$name) coldata <- .set_optarg(input$coldata$datapath, alternative = DataFrame(row.names = colnames(assay_list[[1]])), - loader = read.csv, row.names = 1) + loader = read.table, row.names = 1, header = TRUE, sep = "\t") rowdata <- .set_optarg(input$rowdata$datapath, - loader = read.csv, row.names = 1) + loader = read.table, row.names = 1, + header = TRUE, sep = "\t") row.tree <- .set_optarg(input$row.tree$datapath, loader = read.tree) @@ -65,6 +67,14 @@ rObjects$tse <- .update_tse( rObjects$tse, TreeSummarizedExperiment, fun_args ) + print(input$taxa.from.rownames) + if( input$taxa.from.rownames ){ + + rObjects$tse <- .update_tse( + rObjects$tse, .rownames2taxa, list(x = rObjects$tse) + ) + + } }) diff --git a/R/utils.R b/R/utils.R index 5e4380b..ef1eb1a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -118,6 +118,7 @@ NULL return(cond) } +#' @rdname utils #' @importFrom mia importBIOM #' @importFrom SummarizedExperiment colData #' @importFrom TreeSummarizedExperiment rowTree @@ -139,4 +140,24 @@ NULL } return(tse) +} + +#' @rdname utils +#' @importFrom SummarizedExperiment rowData +#' @importFrom S4Vectors DataFrame +#' @importFrom mia getTaxonomyLabels +.rownames2taxa <- function(x){ + + tax_df <- data.frame(Taxonomy = rownames(x)) + + rowdata <- mia:::.parse_taxonomy( + tax_df, + col.name = "Taxonomy", + removeTaxaPrefixes = TRUE + ) + + rowData(x) <- DataFrame(rowdata) + rownames(x) <- getTaxonomyLabels(x, make.unique = TRUE) + + return(x) } \ No newline at end of file diff --git a/README.md b/README.md index 9ce55f5..d580f82 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ manipulate, analyse and visualise TreeSummarizedExperiment objects. miaDash is available online at [this address](https://miadash-microbiome.2.rahtiapp.fi/). While suitable for small and medium datasets, the online version may slow down -when larger datasets are analysed (> 1000 features). In this case, the app can +when larger datasets are analysed (> 500 samples). In this case, the app can be installed and run locally. Either way, functionality to subset and agglomerate the data is also provided in the app. diff --git a/man/constants.Rd b/man/constants.Rd index 0ff7237..ffb4fe2 100644 --- a/man/constants.Rd +++ b/man/constants.Rd @@ -53,6 +53,7 @@ Constant values used throughout the miaDash app. \item{\code{.alphaMetrics}}{List of alpha diversity metrics.} \item{\code{.betaMetrics}}{List of beta diversity metrics.} \item{\code{.betaMethods}}{List of beta diversity methods.} +\item{\code{.qualityMetrics}}{List of metrics for quality control.} } } diff --git a/man/utils.Rd b/man/utils.Rd index da4acd3..f3c17d5 100644 --- a/man/utils.Rd +++ b/man/utils.Rd @@ -7,6 +7,8 @@ \alias{.print_message} \alias{.set_optarg} \alias{.check_formula} +\alias{.importBIOM} +\alias{.rownames2taxa} \title{miaDash utilities} \usage{ .import_datasets(selection) @@ -18,6 +20,10 @@ .set_optarg(item, loader = NULL, alternative = NULL, ...) .check_formula(form, tse) + +.importBIOM(file, col.data = NULL, tree.file = NULL, ...) + +.rownames2taxa(x) } \arguments{ \item{selection}{\code{Numeric vector}. A list of indices for the mia