diff --git a/DESCRIPTION b/DESCRIPTION index 7ea0905..ae2bebc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: miaDash -Version: 1.1.1 +Version: 1.1.2 Authors@R: c(person(given = "Giulio", family = "Benedetti", role = c("aut", "cre"), email = "giulio.benedetti@utu.fi", @@ -25,7 +25,6 @@ Depends: shiny Imports: ape, - biomformat, htmltools, iSEEtree (>= 1.1.4), mia, diff --git a/NAMESPACE b/NAMESPACE index b4fc867..5662f41 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,7 +8,6 @@ importFrom(SummarizedExperiment,colData) importFrom(TreeSummarizedExperiment,TreeSummarizedExperiment) importFrom(TreeSummarizedExperiment,rowTree) importFrom(ape,read.tree) -importFrom(biomformat,read_biom) importFrom(htmltools,HTML) importFrom(htmltools,br) importFrom(htmltools,div) @@ -28,9 +27,12 @@ importFrom(iSEEtree,RowTreePlot) importFrom(iSEEtree,ScreePlot) importFrom(mia,addAlpha) importFrom(mia,agglomerateByRank) -importFrom(mia,convertFromBIOM) importFrom(mia,getDissimilarity) +importFrom(mia,importBIOM) +importFrom(mia,importHUMAnN) importFrom(mia,importMetaPhlAn) +importFrom(mia,importMothur) +importFrom(mia,importQIIME2) importFrom(mia,runNMDS) importFrom(mia,runRDA) importFrom(mia,subsetByPrevalent) @@ -51,4 +53,5 @@ 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 3f459b5..906a3fb 100644 --- a/NEWS +++ b/NEWS @@ -1,24 +1,28 @@ -Changes in version 0.1.0 -* Initialised app -* Added import functionality +Changes in version 1.1.2 +* Added importers for HUMAnN, QIIME2 and Mothur +* Improved biom importer -Changes in version 0.2.0 -* Added manipulate functionality -* Added estimate functionality -* Added panel layout customisation -* Added unit testing +Changes in version 0.99.12 +* Fixed tab title -Changes in version 0.99.2 -* Moved to shinydashboard +Changes in version 0.99.5 +* Implemented error check system +* Added mia logo Changes in version 0.99.3 * Added tree import option * Fixed bugs with RDS and unifrac * Added clickable title box -Changes in version 0.99.5 -* Implemented error check system -* Added mia logo +Changes in version 0.99.2 +* Moved to shinydashboard -Changes in version 0.99.12 -* Fixed tab title \ No newline at end of file +Changes in version 0.2.0 +* Added manipulate functionality +* Added estimate functionality +* Added panel layout customisation +* Added unit testing + +Changes in version 0.1.0 +* Initialised app +* Added import functionality diff --git a/R/landing_page.R b/R/landing_page.R index 02eaf71..bfb0af9 100644 --- a/R/landing_page.R +++ b/R/landing_page.R @@ -73,36 +73,54 @@ tabPanel(title = "Foreign", value = "foreign", br(), - radioButtons(inputId = "ftype", - label = "Type:", choices = list("biom", "QZA", - "MetaPhlAn"), inline = TRUE), + radioButtons(inputId = "ftype", label = "Type:", + choices = list("biom", "HUMAnN", "MetaPhlAn", + "Mothur", "QIIME2"), inline = TRUE), fileInput(inputId = "main.file", label = "Main file:", accept = c(".biom", - ".QZA", ".txt"), - placeholder = "biom, QZA or txt"), + ".tsv", ".shared", ".QZA", ".txt"), + placeholder = "biom, tsv, shared, QZA or txt"), div(style = "margin-top: -20px"), - + + fileInput(inputId = "col.data", label = "colData:", + accept = c(".tsv", ".design"), + placeholder = "tsv or design"), + div(style = "margin-top: -20px"), + conditionalPanel( - condition = "input.ftype == 'biom'", + condition = "input.ftype == 'Mothur' | input.ftype == 'QIIME2'", + fileInput(inputId = "f.rowdata", + label = "rowData:", accept = c(".taxonomy", + ".qza"), placeholder = "taxonomy or qza"), + div(style = "margin-top: -20px")), + + conditionalPanel( + condition = "input.ftype == 'biom' | input.ftype == 'MetaPhlAn'", + + fileInput(inputId = "tree.file", + label = "rowTree:", placeholder = "tree.tree", + accept = c(".tree", ".tre", ".qza")), + div(style = "margin-top: -20px")), + + conditionalPanel( + condition = "input.ftype == 'biom' | input.ftype == 'HUMAnN'", + checkboxInput(inputId = "rm.tax.pref", - label = "Remove taxa prefixes"), - + label = "Remove taxa prefixes")), + + conditionalPanel( + condition = "input.ftype == 'biom'", + checkboxInput(inputId = "rank.from.pref", label = "Derive taxa from prefixes")), - + conditionalPanel( - condition = "input.ftype == 'MetaPhlAn'", - - fileInput(inputId = "col.data", - label = "colData:", accept = ".tsv", - placeholder = "coldata.tsv"), - div(style = "margin-top: -20px"), - - fileInput(inputId = "tree.file", - label = "Tree:", placeholder = "tree.tree", - accept = c(".tree", ".tre"))))), + condition = "input.ftype == 'HUMAnN'", + + checkboxInput(inputId = "rm.hum.suf", + label = "Remove sample suffix")))), actionButton("import", "Upload", class = "btn-primary")), diff --git a/R/observers.R b/R/observers.R index 0eadd66..c4a8961 100644 --- a/R/observers.R +++ b/R/observers.R @@ -17,11 +17,11 @@ #' @importFrom utils read.csv #' @importFrom ape read.tree #' @importFrom S4Vectors DataFrame -#' @importFrom biomformat read_biom -#' @importFrom mia convertFromBIOM importMetaPhlAn +#' @importFrom mia importHUMAnN importMetaPhlAn importQIIME2 importMothur +#' addAlpha #' @importFrom TreeSummarizedExperiment TreeSummarizedExperiment .create_import_observers <- function(input, rObjects) { - + # nocov start observeEvent(input$import, { @@ -72,33 +72,58 @@ isolate({ req(input$main.file) - + + coldata <- .set_optarg(input$col.data$datapath, + alternative = input$col.data$datapath) + + treefile <- .set_optarg(input$tree.file$datapath, + alternative = input$tree.file$datapath) + if( input$ftype == "biom" ){ - biom_object <- read_biom(input$main.file$datapath) - - fun_args <- list(x = biom_object, + fun_args <- list(file = input$main.file$datapath, + col.data = coldata, tree.file = treefile, removeTaxaPrefixes = input$rm.tax.pref, rankFromPrefix = input$rank.from.pref) - + rObjects$tse <- .update_tse( - rObjects$tse, convertFromBIOM, fun_args + rObjects$tse, .importBIOM, fun_args ) - } else if( input$ftype == "MetaPhlAn" ){ - - coldata <- .set_optarg(input$col.data$datapath, - alternative = input$col.data$datapath) + }else if( input$ftype == "HUMAnN" ){ + + fun_args <- list(file = input$main.file$datapath, + col.data = coldata, + prefix.rm = input$rm.tax.pref, + remove.suffix = input$rm.hum.suf) - treefile <- .set_optarg(input$tree.file$datapath) - + rObjects$tse <- .update_tse( + rObjects$tse, importHUMAnN, fun_args + ) + + }else if( input$ftype == "MetaPhlAn" ){ + fun_args <- list(file = input$main.file$datapath, col.data = coldata, tree.file = treefile) rObjects$tse <- .update_tse( - rObjects$tse, importMetaPhlAn, fun_args - ) - + rObjects$tse, importMetaPhlAn, fun_args + ) + + }else if( input$ftype %in% c("Mothur", "QIIME2") ){ + + imp_fun <- eval(parse(text = paste0("import", input$ftype))) + + rowdata <- .set_optarg(input$f.rowdata$datapath, + alternative = input$f.rowdata$datapath) + + fun_args <- list(assay.file = input$main.file$datapath, + row.file = input, col.file = rowdata) + + rObjects$tse <- .update_tse( + rObjects$tse, imp_fun, fun_args + ) + } }) diff --git a/R/utils.R b/R/utils.R index 59b352a..419d023 100644 --- a/R/utils.R +++ b/R/utils.R @@ -116,4 +116,25 @@ NULL cond <- all(vars %in% names(colData(tse))) return(cond) +} + +#' @importFrom mia importBIOM +#' @importFrom S4Vectors DataFrame +#' @importFrom ape read.tree +#' @importFrom utils read.table +.importBIOM <- function(file, col.data = NULL, tree.file = NULL, ...){ + + tse <- importBIOM(file, ...) + + if( !is.null(col.data) ){ + coldata <- read.table(file = col.data, header = TRUE, sep = "\t") + rownames(coldata) <- colnames(tse) + colData(tse) <- DataFrame(coldata) + } + + if( !is.null(tree.file) ){ + rowTree(tse) <- read.tree(tree.file) + } + + return(tse) } \ No newline at end of file