Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
285 changes: 173 additions & 112 deletions components/board.upload/R/upload_module_preview_counts.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,33 @@ upload_table_preview_counts_ui <- function(id) {
}

upload_table_preview_counts_server <- function(
id,
create_raw_dir,
auth,
uploaded,
checked_matrix,
is_logscale,
checklist,
scrollY,
width,
height,
title,
info.text,
caption,
upload_datatype,
is.olink
) {
id,
create_raw_dir,
auth,
uploaded,
checked_matrix,
is_logscale,
checklist,
scrollY,
width,
height,
title,
info.text,
caption,
upload_datatype,
is.olink,
public_dataset_id
) {

moduleServer(id, function(input, output, session) {

ns <- session$ns

GEO_alert_shown <- reactiveVal(FALSE)

table_data <- shiny::reactive({
shiny::req(!is.null(uploaded$counts.csv))
dt <- uploaded$counts.csv
dt <- uploaded$counts.csv
nrow0 <- nrow(dt)
ncol0 <- ncol(dt)
MAXROW <- 1000
Expand All @@ -58,10 +62,8 @@ upload_table_preview_counts_server <- function(
table.RENDER <- function() {
dt <- table_data()
req(!is.null(dt))

is.integer <- is.integer(dt) || all(round(dt) == dt, na.rm = TRUE)
digits <- ifelse(is.integer, 0, 2)

DT::datatable(dt,
class = "compact hover",
rownames = TRUE,
Expand All @@ -82,6 +84,7 @@ upload_table_preview_counts_server <- function(
}

output$table_counts <- shiny::renderUI({

action_buttons <- div(
style = "display: flex; justify-content: left; margin: 8px;",
if (is.null(uploaded$counts.csv)) {
Expand Down Expand Up @@ -115,95 +118,31 @@ upload_table_preview_counts_server <- function(
)
)

div(
bslib::as_fill_carrier(),
style = "width: 100%; display: flex; ",
if (is.null(uploaded$counts.csv)) {
if (upload_datatype() == "proteomics") {
msg <- "The counts file (counts.csv) contains the gene counts for all samples. For proteomics data types other than Olink NPX, the file should be a tabular text file (.csv), where each row corresponds to a feature (i.e. genes) and each column corresponds to a sample. For Olink NPX, the uploaded file needs to be the standard Olink format."
} else {
msg <- "The counts file (counts.csv) contains the gene counts for all samples. The file should be a tabular text file (.csv), where each row corresponds to a feature (i.e. genes) and each column corresponds to a sample."
}
bslib::layout_columns(
col_widths = c(-3, 6, -3),
row_heights = list("auto", 8, 1, 2),
gap = "0.5rem",
bslib::as_fill_carrier(bs_alert(tspan(msg), closable = FALSE, translate_js = FALSE)),
bslib::card(
if (upload_datatype() == "multi-omics") {
shiny::radioButtons(
ns("data_source"),
label = "Select input files from:",
choices = c("multi-csv", "pgx", "single-csv"),
selected = "multi-csv",
inline = TRUE
)
},
if (upload_datatype() == "multi-omics") {
shiny::conditionalPanel(
condition = sprintf("input['%s'] == 'pgx'", ns("data_source")),
div(
div(
style = "margin-bottom: 15px;",
shiny::radioButtons(
ns("data_processing"),
label = "Select data processing level:",
choices = c("Raw" = "raw", "Normalized (also batch corrected if selected on computation)" = "normalized"),
selected = "raw",
inline = TRUE
)
),
div(
style = "display: flex; align-items: center; gap: 10px; margin-bottom: 10px;",
span("Selected:", style = "font-weight: bold;"),
textOutput(ns("selected_rows_text")),
),
div(
style = "height: 350px; overflow-y: auto;",
DT::DTOutput(ns("available_data_table"))
),
style = "width: 100%; max-height: 400px; overflow-y: auto;"
),
selection = "multiple",
options = list(pageLength = 5, dom = "tp", scrollY = TRUE)
)
},

if (upload_datatype() == "multi-omics") {
shiny::conditionalPanel(
condition = sprintf("input['%s'] == 'multi-csv'", ns("data_source")),
shiny::uiOutput(ns("dynamic_file_inputs"))#,
)
},
if (public_dataset_id() != "") {

if (upload_datatype() == "multi-omics") {
shiny::conditionalPanel(
condition = sprintf("input['%s'] == 'single-csv'", ns("data_source")),
fileInputArea(
ns("counts_csv"),
shiny::h4(tspan("Upload counts.csv", js = FALSE), class = "mb-0"),
multiple = FALSE,
accept = c(".csv"),
width = "100%"
)
)
},

if (upload_datatype() != "multi-omics") {
fileInputArea(
ns("counts_csv"),
shiny::h4(tspan("Upload counts.csv", js = FALSE), class = "mb-0"),
multiple = FALSE,
accept = c(".csv"),
width = "100%"
)
},
style = "background-color: aliceblue; border: 0.07rem dashed steelblue;"
),
action_buttons,
br()
)
},
ID <- public_dataset_id()
msg <- paste0("Retrieving ", ID, " from GEO, ReCount, or ArrayExpress...<br>", "Please wait. Most datasets take 2-3 mins.")

showModal(modalDialog(
div(id = "custom-progress-modal", HTML(msg),
div(id = "custom-progress-container",
div(id = "custom-progress-bar"))),
footer = NULL, fade = FALSE))
GEO <- tryCatch({ playbase::pgx.getGEOseries(accession = ID, archs.h5 = NULL, get.info = FALSE)},
error = function(w) { NULL })
removeModal()

if (!is.null(GEO)) {
if (!GEO_alert_shown()) {
msg <- paste0("Success! ", ID, " found in ", GEO[["source"]], ".\nWe're preparing it...")
GEO_alert_shown(TRUE)
}
uploaded$counts.csv <- GEO[["counts"]]
uploaded$samples.csv <- GEO[["samples"]]
cm <- intersect(colnames(GEO[["counts"]]), rownames(GEO[["samples"]]))
GEO <- NULL
}

if (!is.null(uploaded$counts.csv)) {
bslib::layout_columns(
col_widths = 12,
Expand All @@ -227,8 +166,129 @@ upload_table_preview_counts_server <- function(
),
bslib::layout_columns(action_buttons, br(), uiOutput(ns("error_summary")))
)
} ## end of if-else
) ## end of div
} else {
div("No counts data available for this public dataset.")
}

} else {

div(
bslib::as_fill_carrier(),
style = "width: 100%; display: flex; ",
if (is.null(uploaded$counts.csv)) {
if (upload_datatype() == "proteomics") {
msg <- "The counts file (counts.csv) contains the gene counts for all samples. For proteomics data types other than Olink NPX, the file should be a tabular text file (.csv), where each row corresponds to a feature (i.e. genes) and each column corresponds to a sample. For Olink NPX, the uploaded file needs to be the standard Olink format."
} else {
msg <- "The counts file (counts.csv) contains the gene counts for all samples. The file should be a tabular text file (.csv), where each row corresponds to a feature (i.e. genes) and each column corresponds to a sample."
}
bslib::layout_columns(
col_widths = c(-3, 6, -3),
row_heights = list("auto", 8, 1, 2),
gap = "0.5rem",
bslib::as_fill_carrier(bs_alert(tspan(msg), closable = FALSE, translate_js = FALSE)),
bslib::card(
if (upload_datatype() == "multi-omics") {
shiny::radioButtons(
ns("data_source"),
label = "Select input files from:",
choices = c("multi-csv", "pgx", "single-csv"),
selected = "multi-csv",
inline = TRUE
)
},
if (upload_datatype() == "multi-omics") {
shiny::conditionalPanel(
condition = sprintf("input['%s'] == 'pgx'", ns("data_source")),
div(
div(
style = "margin-bottom: 15px;",
shiny::radioButtons(
ns("data_processing"),
label = "Select data processing level:",
choices = c("Raw" = "raw", "Normalized (also batch corrected if selected on computation)" = "normalized"),
selected = "raw",
inline = TRUE
)
),
div(
style = "display: flex; align-items: center; gap: 10px; margin-bottom: 10px;",
span("Selected:", style = "font-weight: bold;"),
textOutput(ns("selected_rows_text")),
),
div(
style = "height: 350px; overflow-y: auto;",
DT::DTOutput(ns("available_data_table"))
),
style = "width: 100%; max-height: 400px; overflow-y: auto;"
),
selection = "multiple",
options = list(pageLength = 5, dom = "tp", scrollY = TRUE)
)
},

if (upload_datatype() == "multi-omics") {
shiny::conditionalPanel(
condition = sprintf("input['%s'] == 'multi-csv'", ns("data_source")),
shiny::uiOutput(ns("dynamic_file_inputs"))#,
)
},

if (upload_datatype() == "multi-omics") {
shiny::conditionalPanel(
condition = sprintf("input['%s'] == 'single-csv'", ns("data_source")),
fileInputArea(
ns("counts_csv"),
shiny::h4(tspan("Upload counts.csv", js = FALSE), class = "mb-0"),
multiple = FALSE,
accept = c(".csv"),
width = "100%"
)
)
},

if (upload_datatype() != "multi-omics") {
fileInputArea(
ns("counts_csv"),
shiny::h4(tspan("Upload counts.csv", js = FALSE), class = "mb-0"),
multiple = FALSE,
accept = c(".csv"),
width = "100%"
)
},

style = "background-color: aliceblue; border: 0.07rem dashed steelblue;"
),
action_buttons,
br()
)
},
if (!is.null(uploaded$counts.csv)) {
bslib::layout_columns(
col_widths = 12,
bslib::layout_columns(
col_widths = c(8, 4),
TableModuleUI(
ns("counts_datasets"),
width = width,
height = height,
title = title,
info.text = info.text,
caption = caption,
label = "",
show.maximize = FALSE,
translate_js = FALSE
),
bslib::navset_card_pill(
bslib::nav_panel(title = "Histogram", br(), plotOutput(ns("histogram"))),
bslib::nav_panel(title = "Box plots", br(), plotOutput(ns("boxplots")))
)
),
bslib::layout_columns(action_buttons, br(), uiOutput(ns("error_summary")))
)
} ## end of if-else
) ## end of div
}

})

output$selected_rows_text <- renderText({
Expand Down Expand Up @@ -485,7 +545,7 @@ upload_table_preview_counts_server <- function(
shinyalert::shinyalert(title = "Warning", text = err.html, html = TRUE)
}
})

# pass counts to uploaded when uploaded
observeEvent(input$counts_csv, {
# check if counts is csv (necessary due to drag and drop of any file)
Expand Down Expand Up @@ -526,7 +586,7 @@ upload_table_preview_counts_server <- function(
overwrite = TRUE
)
}

##---counts---##
sel <- grep("count|expression|abundance|concentration", tolower(input$counts_csv$name))
if (length(sel)) {
Expand Down Expand Up @@ -572,7 +632,7 @@ upload_table_preview_counts_server <- function(
if (upload_datatype() == "proteomics" && is.olink() && !is.null(df.samples)) {
uploaded$samples.csv <- df.samples
}

## ##---samples---##
## sel <- grep("samples", tolower(input$counts_csv$name))
## if (length(sel)) {
Expand Down Expand Up @@ -670,3 +730,4 @@ upload_table_preview_counts_server <- function(
)
}) ## end of moduleServer
} ## end of server

Loading