Skip to content

Commit

Permalink
Added tree import and fixed unifrac and RDS bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
RiboRings committed Dec 1, 2024
1 parent 82b59a1 commit c109bd5
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 25 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: miaDash
Version: 0.99.2
Version: 0.99.3
Authors@R:
c(person(given = "Giulio", family = "Benedetti", role = c("aut", "cre"),
email = "[email protected]",
Expand All @@ -23,6 +23,7 @@ Depends:
R (>= 4.4.0),
iSEE
Imports:
ape,
biomformat,
htmltools,
iSEEtree,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ importFrom(TreeSummarizedExperiment,TreeSummarizedExperiment)
importFrom(TreeSummarizedExperiment,colLinks)
importFrom(TreeSummarizedExperiment,rowLinks)
importFrom(TreeSummarizedExperiment,rowTree)
importFrom(ape,read.tree)
importFrom(biomformat,read_biom)
importFrom(htmltools,HTML)
importFrom(htmltools,br)
importFrom(htmltools,div)
importFrom(htmltools,tags)
importFrom(iSEE,ColumnDataTable)
importFrom(iSEE,ComplexHeatmapPlot)
Expand Down
7 changes: 7 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ Changes in version 0.2.0
* Added estimate functionality
* Added panel layout customisation
* Added unit testing

Changes in version 0.99.2
* Moved to shinydashboard

Changes in version 0.99.3
* Added tree import option
* Fixed bugs with RDS and unifrac
26 changes: 21 additions & 5 deletions R/landing_page.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' conditionalPanel
#' @importFrom shinydashboard dashboardPage dashboardHeader dashboardSidebar
#' dashboardBody box
#' @importFrom htmltools HTML br tags
#' @importFrom htmltools HTML br tags div
#' @importFrom shinyjs disable
#' @importFrom utils data
.landing_page <- function(FUN, input, output, session) {
Expand Down Expand Up @@ -54,22 +54,36 @@

fileInput(inputId = "assay", label = "Assays:",
accept = ".csv", multiple = TRUE),
div(style = "margin-top: -25px"),

fileInput(inputId = "coldata", label = "colData:",
accept = ".csv"),

div(style = "margin-top: -25px"),

fileInput(inputId = "rowdata", label = "rowData:",
accept = ".csv")),
accept = ".csv"),
div(style = "margin-top: -25px"),

fileInput(inputId = "row.tree",
label = "rowTree:",
accept = c(".tree", ".tre")),
div(style = "margin-top: -25px"),

fileInput(inputId = "col.tree",
label = "colTree:",
accept = c(".tree", ".tre")),
div(style = "margin-top: -25px")),

tabPanel(title = "Foreign", value = "foreign", br(),

radioButtons(inputId = "ftype",
label = "Type:", choices = list("biom", "QZA",
"MetaPhlAn")),
"MetaPhlAn"), inline = TRUE),

fileInput(inputId = "main.file",
label = "Main file:", accept = c(".biom",
".QZA", ".txt")),
div(style = "margin-top: -25px"),

conditionalPanel(
condition = "input.ftype == 'biom'",
Expand All @@ -85,9 +99,11 @@

fileInput(inputId = "col.data",
label = "colData:", accept = ".tsv"),
div(style = "margin-top: -25px"),

fileInput(inputId = "tree.file",
label = "Tree:", accept = ".tree")))),
label = "Tree:",
accept = c(".tree", ".tre"))))),

actionButton("import", "Upload", class = "btn-primary")),

Expand Down
41 changes: 22 additions & 19 deletions R/observers.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#' @rdname create_observers
#' @importFrom utils read.csv
#' @importFrom ape read.tree
#' @importFrom S4Vectors DataFrame
#' @importFrom shiny isolate observeEvent req
#' @importFrom biomformat read_biom
Expand All @@ -33,8 +34,7 @@

isolate({
req(input$file)
load(file = input$file$datapath)
rObjects$tse <- readRDS(gsub(".rds", "", input$file$name))
rObjects$tse <- readRDS(input$file$datapath)
})

}else if( input$format == "raw" ){
Expand All @@ -45,23 +45,20 @@
assay_list <- lapply(input$assay$datapath,
function(x) as.matrix(read.csv(x, row.names = 1)))

if( !is.null(input$coldata) ){
coldata <- read.csv(input$coldata$datapath, row.names = 1)
} else {
coldata <- DataFrame(row.names = colnames(assay_list[[1]]))
}


if( !is.null(input$rowdata) ){
rowdata <- read.csv(input$rowdata$datapath, row.names = 1)
} else {
rowdata <- NULL
}

names(assay_list) <- gsub(".csv", "", input$assay$name)

coldata <- .set_optarg(input$coldata$datapath, read.csv,
alternative = DataFrame(row.names = colnames(assay_list[[1]])),
row.names = 1)

rowdata <- .set_optarg(input$rowdata$datapath, read.csv,
row.names = 1)

row.tree <- .set_optarg(input$row.tree$datapath, read.tree)
col.tree <- .set_optarg(input$col.tree$datapath, read.tree)

fun_args <- list(assays = assay_list, colData = coldata,
rowData = rowdata)
rowData = rowdata, rowTree = row.tree, colTree = col.tree)

rObjects$tse <- .update_tse(TreeSummarizedExperiment, fun_args)
})
Expand Down Expand Up @@ -250,9 +247,14 @@

if( input$beta.index == "unifrac" ){

if( is.null(rowTree(rObjects$tse)) ){
.print_message("Unifrac cannot be computed without a rowTree.")
return()
}

beta_args <- c(beta_args, FUN = getDissimilarity,
tree = rowTree(rObjects$tse), ntop = nrow(rObjects$tse),
method = input$beta.index)
tree = list(rowTree(rObjects$tse)),
ntop = nrow(rObjects$tse), method = input$beta.index)

} else if( input$bmethod %in% c("MDS", "NMDS") ){

Expand All @@ -276,8 +278,9 @@
formula = as.formula(input$rda.formula))

}

print(beta_args)
beta_fun <- eval(parse(text = paste0("run", input$bmethod)))
print(beta_fun)
rObjects$tse <- .update_tse(beta_fun, beta_args)

})
Expand Down
12 changes: 12 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
# nocov end
}

#' @rdname utils
.set_optarg <- function(item, loader, alternative = NULL, ...){

if( !is.null(item) ){
out <- loader(item, ...)
} else {
out <- alternative
}

return(out)
}

#' @rdname utils
#' @importFrom SummarizedExperiment colData
.check_formula <- function(form, se){
Expand Down
3 changes: 3 additions & 0 deletions man/utils.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c109bd5

Please sign in to comment.