Commit 128359db authored by mahendra-mariadassou's avatar mahendra-mariadassou
Browse files

Working version of additional columns.

parent ebf6797f
...@@ -49,6 +49,7 @@ app_server <- function(input, output, session) { ...@@ -49,6 +49,7 @@ app_server <- function(input, output, session) {
cleaned = phyloseq::tax_table(physeq) %>% as("matrix"), ## All current affiliations (not only those of ambiguous OTUs) cleaned = phyloseq::tax_table(physeq) %>% as("matrix"), ## All current affiliations (not only those of ambiguous OTUs)
affi = NULL, ## Placeholder for conflicting affiliations of current OTU affi = NULL, ## Placeholder for conflicting affiliations of current OTU
sequence = NULL ## Placeholder for current OTU sequence sequence = NULL ## Placeholder for current OTU sequence
# blast_result = NULL ## Placeholder for current OTU blast result
) )
## Sort `cleaned` by decreasing taxa abundances ## Sort `cleaned` by decreasing taxa abundances
data$cleaned <- data$cleaned[phyloseq::taxa_sums(physeq) %>% sort(decreasing = TRUE) %>% names(), ] data$cleaned <- data$cleaned[phyloseq::taxa_sums(physeq) %>% sort(decreasing = TRUE) %>% names(), ]
...@@ -76,12 +77,19 @@ app_server <- function(input, output, session) { ...@@ -76,12 +77,19 @@ app_server <- function(input, output, session) {
# Extract Affiliation for a given OTU # Extract Affiliation for a given OTU
data$affi <- extract_affiliation(affi, input$asv) data$affi <- extract_affiliation(affi, input$asv)
data$sequence <- extract_sequence(affi, input$asv) data$sequence <- extract_sequence(affi, input$asv)
# data$blast_result <- extract_blast(affi, input$asv)
amb <- find_level(data$affi) amb <- find_level(data$affi)
output$txt <- renderUI(HTML({paste("<p><b>", input$asv, "- ", nrow(data$affi) ,"conflicting affiliations, ambiguity at rank ", amb, "</b></p>")})) output$txt <- renderUI(HTML({paste("<p><b>", input$asv, "- ", nrow(data$affi) ,"conflicting affiliations, ambiguity at rank ", amb, "</b></p>")}))
output$help <- renderUI(HTML({paste("<cite>Select new affiliation by clicking on a row (double click on a cell to edit its content).<br/>", output$help <- renderUI(HTML({paste("<cite>Select new affiliation by clicking on a row (double click on a cell to edit its content).<br/>",
"Click \"Update OTU\" to update affiliation (with selected row) or \"Skip OTU\" to move to the next one.</cite>")})) "Click \"Update OTU\" to update affiliation (with selected row) or \"Skip OTU\" to move to the next one.</cite>")}))
## Show alignment information
output$aln_info <- renderUI({
HTML(glue::glue())
})
## Show conflicting affiliations
output$table <- DT::renderDT({data$affi}, output$table <- DT::renderDT({data$affi},
options = list(scrollX = TRUE), options = list(scrollX = TRUE),
selection = list(mode = 'single', selected = NULL, target = 'row'), selection = list(mode = 'single', selected = NULL, target = 'row'),
...@@ -95,7 +103,7 @@ app_server <- function(input, output, session) { ...@@ -95,7 +103,7 @@ app_server <- function(input, output, session) {
HTML(paste("<b>Current affiliation:</b><br/>&nbsp;&nbsp;&nbsp;"), HTML(paste("<b>Current affiliation:</b><br/>&nbsp;&nbsp;&nbsp;"),
paste(data$cleaned[input$asv, ], collapse = ' / '), paste(data$cleaned[input$asv, ], collapse = ' / '),
"<br/><b>to be replaced with:</b><br/>&nbsp;&nbsp;&nbsp;", "<br/><b>to be replaced with:</b><br/>&nbsp;&nbsp;&nbsp;",
paste(data$affi[s, ], collapse = ' / ') paste(remove_extra(data$affi)[s, ], collapse = ' / ')
) )
} }
}) })
...@@ -125,7 +133,7 @@ app_server <- function(input, output, session) { ...@@ -125,7 +133,7 @@ app_server <- function(input, output, session) {
s = input$table_rows_selected s = input$table_rows_selected
if (length(s)) { if (length(s)) {
## Update affiliations ## Update affiliations
data$cleaned[input$asv, ] <- unlist(data$affi[s, ]) data$cleaned[input$asv, ] <- unlist(remove_extra(data$affi)[s, ])
data$amb_otus <- setdiff(data$amb_otus, input$asv) data$amb_otus <- setdiff(data$amb_otus, input$asv)
updateSelectInput(session, "asv", updateSelectInput(session, "asv",
label = "Select OTU", label = "Select OTU",
......
...@@ -57,6 +57,7 @@ app_ui <- function() { ...@@ -57,6 +57,7 @@ app_ui <- function() {
htmlOutput("txt"), htmlOutput("txt"),
htmlOutput("help"), htmlOutput("help"),
HTML("<br/>"), HTML("<br/>"),
# htmlOutput("aln_info"),
DT::DTOutput("table"), DT::DTOutput("table"),
htmlOutput("sequence"), htmlOutput("sequence"),
htmlOutput("selection") htmlOutput("selection")
......
...@@ -90,11 +90,18 @@ sort_ambiguous_otu <- function(physeq, affi) { ...@@ -90,11 +90,18 @@ sort_ambiguous_otu <- function(physeq, affi) {
extract_affiliation <- function(affi, otu) { extract_affiliation <- function(affi, otu) {
affi %>% affi %>%
dplyr::filter(OTU == otu) %>% dplyr::filter(OTU == otu) %>%
dplyr::select(Kingdom:Species) %>% dplyr::distinct(dplyr::across(Kingdom:Species), .keep_all = TRUE) %>%
dplyr::distinct() dplyr::select(Kingdom:Species, blast_subject, blast_perc_identity, blast_perc_query_coverage) %>%
dplyr::rename(`Blast ID` = blast_subject,
`%id` = blast_perc_identity,
`%cov` = blast_perc_query_coverage)
} }
## Extract all affiliation for a given OTU remove_extra <- function(affi) {
affi %>% dplyr::select(-any_of(c("Blast ID", "%id", "%cov")))
}
## Extract sequence for a given OTU
extract_sequence <- function(affi, otu) { extract_sequence <- function(affi, otu) {
affi %>% affi %>%
dplyr::filter(OTU == otu) %>% dplyr::filter(OTU == otu) %>%
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment