Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
migale
affiliationExplorer
Commits
b97e88bd
Commit
b97e88bd
authored
Feb 07, 2020
by
mahendra-mariadassou
Browse files
Replace affiliations upon confirmation
parent
14e88dca
Changes
1
Hide whitespace changes
Inline
Side-by-side
R/app_server.R
View file @
b97e88bd
...
...
@@ -30,22 +30,46 @@ app_server <- function(input, output, session) {
choices
=
ambiguous_otu
,
multiple
=
FALSE
)
)
old_affiliations
<-
phyloseq
::
tax_table
(
physeq
)[
ambiguous_otu
,
]
%>%
as
(
"matrix"
)
## Store cleaned affiliations as reactive values
affiliations
<-
reactiveValues
(
cleaned
=
old_affiliations
)
observeEvent
(
input
$
asv
,
{
# Extract Affiliation for a given OTU
data
<-
extract_affiliation
(
affi
,
input
$
asv
)
amb
<-
find_level
(
data
)
output
$
txt
<-
renderUI
({
paste
(
input
$
asv
,
"- "
,
nrow
(
data
)
,
" affiliation, ambiguity at rank "
,
amb
)})
output
$
table
<-
DT
::
renderDT
({
data
},
selection
=
'single'
)
#
If a column is selected, update affiliation
#
# Show considered replacement if one is selected
output
$
selection
<-
renderUI
({
s
=
input
$
table_rows_selected
if
(
length
(
s
))
{
paste
(
"These rows were selected: "
,
s
)
paste
(
"Current affiliation:"
,
paste
(
old_affiliations
[
input
$
asv
,
],
collapse
=
';'
),
"to be replaced with:"
,
paste
(
data
[
s
,
],
collapse
=
';'
),
sep
=
"\n"
)
}
})
## Replace affiliation upon confirmation
observeEvent
(
input
$
clean
,
{
s
=
input
$
table_rows_selected
if
(
length
(
s
))
{
## Update affiliations
affiliations
$
cleaned
[
input
$
asv
,
]
<-
unlist
(
data
[
s
,
])
## Update text (buggy, does not disappear when changing asv)
# output$selection <- renderUI({
# glue::glue("Updated affiliation of {input$asv} to\n",
# "{paste(affiliations$cleaned[input$asv, ], collapse = ';')}")
# })
}
})
})
## Reactive block to update ambiguous_otu, ambiguous_otu_affi and the list when clicking on the "Clean ASV" button
...
...
@@ -53,18 +77,20 @@ app_server <- function(input, output, session) {
## phyloseq::tax_table(physeq)[input$asv, ] <- cleaned_taxonomy
## ambiguous_otu <- setdiff(ambiguous_otu, input$asv)
## updateUI
output
$
download
<-
downloadHandler
(
filename
=
function
()
{
paste0
(
'cleaned_biom-'
,
Sys.Date
(),
'.biom'
)
},
content
=
function
(
con
)
{
## Update taxonomy of object phyloseq
phyloseq
::
tax_table
(
physeq
)[
rownames
(
affiliations
$
cleaned
),
]
<-
affiliations
$
cleaned
## TODO revert short OTU names back to original names
phyloseq.extended
::
write_phyloseq
(
physeq
=
physeq
,
biom_file
=
con
,
biom_format
=
"frogs"
)
## write.csv(data, con)
})
})
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment