Skip to content

Commit f2d53d6

Browse files
authored
Merge pull request #23 from microbiome/dbb
Improve and extend importers
2 parents 5d40986 + 60c3926 commit f2d53d6

File tree

6 files changed

+127
-57
lines changed

6 files changed

+127
-57
lines changed

DESCRIPTION

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: miaDash
2-
Version: 1.1.1
2+
Version: 1.1.2
33
Authors@R:
44
c(person(given = "Giulio", family = "Benedetti", role = c("aut", "cre"),
55
email = "giulio.benedetti@utu.fi",
@@ -25,7 +25,6 @@ Depends:
2525
shiny
2626
Imports:
2727
ape,
28-
biomformat,
2928
htmltools,
3029
iSEEtree (>= 1.1.4),
3130
mia,

NAMESPACE

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ importFrom(SummarizedExperiment,colData)
88
importFrom(TreeSummarizedExperiment,TreeSummarizedExperiment)
99
importFrom(TreeSummarizedExperiment,rowTree)
1010
importFrom(ape,read.tree)
11-
importFrom(biomformat,read_biom)
1211
importFrom(htmltools,HTML)
1312
importFrom(htmltools,br)
1413
importFrom(htmltools,div)
@@ -28,9 +27,12 @@ importFrom(iSEEtree,RowTreePlot)
2827
importFrom(iSEEtree,ScreePlot)
2928
importFrom(mia,addAlpha)
3029
importFrom(mia,agglomerateByRank)
31-
importFrom(mia,convertFromBIOM)
3230
importFrom(mia,getDissimilarity)
31+
importFrom(mia,importBIOM)
32+
importFrom(mia,importHUMAnN)
3333
importFrom(mia,importMetaPhlAn)
34+
importFrom(mia,importMothur)
35+
importFrom(mia,importQIIME2)
3436
importFrom(mia,runNMDS)
3537
importFrom(mia,runRDA)
3638
importFrom(mia,subsetByPrevalent)
@@ -51,4 +53,5 @@ importFrom(stats,as.formula)
5153
importFrom(utils,data)
5254
importFrom(utils,packageVersion)
5355
importFrom(utils,read.csv)
56+
importFrom(utils,read.table)
5457
importFrom(vegan,vegdist)

NEWS

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
Changes in version 0.1.0
2-
* Initialised app
3-
* Added import functionality
1+
Changes in version 1.1.2
2+
* Added importers for HUMAnN, QIIME2 and Mothur
3+
* Improved biom importer
44

5-
Changes in version 0.2.0
6-
* Added manipulate functionality
7-
* Added estimate functionality
8-
* Added panel layout customisation
9-
* Added unit testing
5+
Changes in version 0.99.12
6+
* Fixed tab title
107

11-
Changes in version 0.99.2
12-
* Moved to shinydashboard
8+
Changes in version 0.99.5
9+
* Implemented error check system
10+
* Added mia logo
1311

1412
Changes in version 0.99.3
1513
* Added tree import option
1614
* Fixed bugs with RDS and unifrac
1715
* Added clickable title box
1816

19-
Changes in version 0.99.5
20-
* Implemented error check system
21-
* Added mia logo
17+
Changes in version 0.99.2
18+
* Moved to shinydashboard
2219

23-
Changes in version 0.99.12
24-
* Fixed tab title
20+
Changes in version 0.2.0
21+
* Added manipulate functionality
22+
* Added estimate functionality
23+
* Added panel layout customisation
24+
* Added unit testing
25+
26+
Changes in version 0.1.0
27+
* Initialised app
28+
* Added import functionality

R/landing_page.R

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,36 +73,54 @@
7373

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

76-
radioButtons(inputId = "ftype",
77-
label = "Type:", choices = list("biom", "QZA",
78-
"MetaPhlAn"), inline = TRUE),
76+
radioButtons(inputId = "ftype", label = "Type:",
77+
choices = list("biom", "HUMAnN", "MetaPhlAn",
78+
"Mothur", "QIIME2"), inline = TRUE),
7979

8080
fileInput(inputId = "main.file",
8181
label = "Main file:", accept = c(".biom",
82-
".QZA", ".txt"),
83-
placeholder = "biom, QZA or txt"),
82+
".tsv", ".shared", ".QZA", ".txt"),
83+
placeholder = "biom, tsv, shared, QZA or txt"),
8484
div(style = "margin-top: -20px"),
85-
85+
86+
fileInput(inputId = "col.data", label = "colData:",
87+
accept = c(".tsv", ".design"),
88+
placeholder = "tsv or design"),
89+
div(style = "margin-top: -20px"),
90+
8691
conditionalPanel(
87-
condition = "input.ftype == 'biom'",
92+
condition = "input.ftype == 'Mothur' | input.ftype == 'QIIME2'",
8893

94+
fileInput(inputId = "f.rowdata",
95+
label = "rowData:", accept = c(".taxonomy",
96+
".qza"), placeholder = "taxonomy or qza"),
97+
div(style = "margin-top: -20px")),
98+
99+
conditionalPanel(
100+
condition = "input.ftype == 'biom' | input.ftype == 'MetaPhlAn'",
101+
102+
fileInput(inputId = "tree.file",
103+
label = "rowTree:", placeholder = "tree.tree",
104+
accept = c(".tree", ".tre", ".qza")),
105+
div(style = "margin-top: -20px")),
106+
107+
conditionalPanel(
108+
condition = "input.ftype == 'biom' | input.ftype == 'HUMAnN'",
109+
89110
checkboxInput(inputId = "rm.tax.pref",
90-
label = "Remove taxa prefixes"),
91-
111+
label = "Remove taxa prefixes")),
112+
113+
conditionalPanel(
114+
condition = "input.ftype == 'biom'",
115+
92116
checkboxInput(inputId = "rank.from.pref",
93117
label = "Derive taxa from prefixes")),
94-
118+
95119
conditionalPanel(
96-
condition = "input.ftype == 'MetaPhlAn'",
97-
98-
fileInput(inputId = "col.data",
99-
label = "colData:", accept = ".tsv",
100-
placeholder = "coldata.tsv"),
101-
div(style = "margin-top: -20px"),
102-
103-
fileInput(inputId = "tree.file",
104-
label = "Tree:", placeholder = "tree.tree",
105-
accept = c(".tree", ".tre"))))),
120+
condition = "input.ftype == 'HUMAnN'",
121+
122+
checkboxInput(inputId = "rm.hum.suf",
123+
label = "Remove sample suffix")))),
106124

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

R/observers.R

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
#' @importFrom utils read.csv
1818
#' @importFrom ape read.tree
1919
#' @importFrom S4Vectors DataFrame
20-
#' @importFrom biomformat read_biom
21-
#' @importFrom mia convertFromBIOM importMetaPhlAn
20+
#' @importFrom mia importHUMAnN importMetaPhlAn importQIIME2 importMothur
21+
#' addAlpha
2222
#' @importFrom TreeSummarizedExperiment TreeSummarizedExperiment
2323
.create_import_observers <- function(input, rObjects) {
24-
24+
2525
# nocov start
2626
observeEvent(input$import, {
2727

@@ -72,33 +72,58 @@
7272

7373
isolate({
7474
req(input$main.file)
75-
75+
76+
coldata <- .set_optarg(input$col.data$datapath,
77+
alternative = input$col.data$datapath)
78+
79+
treefile <- .set_optarg(input$tree.file$datapath,
80+
alternative = input$tree.file$datapath)
81+
7682
if( input$ftype == "biom" ){
7783

78-
biom_object <- read_biom(input$main.file$datapath)
79-
80-
fun_args <- list(x = biom_object,
84+
fun_args <- list(file = input$main.file$datapath,
85+
col.data = coldata, tree.file = treefile,
8186
removeTaxaPrefixes = input$rm.tax.pref,
8287
rankFromPrefix = input$rank.from.pref)
83-
88+
8489
rObjects$tse <- .update_tse(
85-
rObjects$tse, convertFromBIOM, fun_args
90+
rObjects$tse, .importBIOM, fun_args
8691
)
8792

88-
} else if( input$ftype == "MetaPhlAn" ){
89-
90-
coldata <- .set_optarg(input$col.data$datapath,
91-
alternative = input$col.data$datapath)
93+
}else if( input$ftype == "HUMAnN" ){
94+
95+
fun_args <- list(file = input$main.file$datapath,
96+
col.data = coldata,
97+
prefix.rm = input$rm.tax.pref,
98+
remove.suffix = input$rm.hum.suf)
9299

93-
treefile <- .set_optarg(input$tree.file$datapath)
94-
100+
rObjects$tse <- .update_tse(
101+
rObjects$tse, importHUMAnN, fun_args
102+
)
103+
104+
}else if( input$ftype == "MetaPhlAn" ){
105+
95106
fun_args <- list(file = input$main.file$datapath,
96107
col.data = coldata, tree.file = treefile)
97108

98109
rObjects$tse <- .update_tse(
99-
rObjects$tse, importMetaPhlAn, fun_args
100-
)
101-
110+
rObjects$tse, importMetaPhlAn, fun_args
111+
)
112+
113+
}else if( input$ftype %in% c("Mothur", "QIIME2") ){
114+
115+
imp_fun <- eval(parse(text = paste0("import", input$ftype)))
116+
117+
rowdata <- .set_optarg(input$f.rowdata$datapath,
118+
alternative = input$f.rowdata$datapath)
119+
120+
fun_args <- list(assay.file = input$main.file$datapath,
121+
row.file = input, col.file = rowdata)
122+
123+
rObjects$tse <- .update_tse(
124+
rObjects$tse, imp_fun, fun_args
125+
)
126+
102127
}
103128

104129
})

R/utils.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,25 @@ NULL
116116

117117
cond <- all(vars %in% names(colData(tse)))
118118
return(cond)
119+
}
120+
121+
#' @importFrom mia importBIOM
122+
#' @importFrom S4Vectors DataFrame
123+
#' @importFrom ape read.tree
124+
#' @importFrom utils read.table
125+
.importBIOM <- function(file, col.data = NULL, tree.file = NULL, ...){
126+
127+
tse <- importBIOM(file, ...)
128+
129+
if( !is.null(col.data) ){
130+
coldata <- read.table(file = col.data, header = TRUE, sep = "\t")
131+
rownames(coldata) <- colnames(tse)
132+
colData(tse) <- DataFrame(coldata)
133+
}
134+
135+
if( !is.null(tree.file) ){
136+
rowTree(tse) <- read.tree(tree.file)
137+
}
138+
139+
return(tse)
119140
}

0 commit comments

Comments
 (0)