Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try except for preprocess #177

Merged
merged 15 commits into from
May 21, 2024
Merged
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
2 changes: 1 addition & 1 deletion program/shinyApp/R/data_selection/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ data_selection_sidebar_panel <- sidebarPanel(
id = "sidebar_data_selection",
div(class = "omic_type",
selectInput(
inputId = "omic_type",
inputId = "omic_type",
label = "Omic Type that is uploaded",
choices = c("Transcriptomics", "Lipidomics", "Metabolomics"),
selected = ""
Expand Down
9 changes: 6 additions & 3 deletions program/shinyApp/R/enrichment_analysis/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -704,9 +704,12 @@ enrichment_analysis_Server <- function(id, data, params, updates){
error=function(e){
showModal(modalDialog(
title = HTML("<font color='red'>An Error occured</font>"),
footer = actionButton(
inputId = ns("translation_again"),
label = "Choose another annotation type"
footer = tagList(
actionButton(
inputId = ns("translation_again"),
label = "Choose another annotation type"
),
modalButton("Close")
),
HTML(paste0(
"<font color='red'>Error: ",e$message,"</font><br><br>",
Expand Down
34 changes: 22 additions & 12 deletions program/shinyApp/R/pre_processing/util.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
# preprocessing procedures

preprocessing <- function(data, omic_type, procedure){
if(procedure == "filterOnly"){
return(prefiltering(data, omic_type))
}
if(procedure == "simpleCenterScaling"){
return(simple_center_scaling(data, omic_type))
}
if(procedure %in% c("Scaling_0_1", "pareto_scaling")){
return(scaling_normalisation(data, omic_type, procedure))
}
if(procedure %in% c("log10", "ln")){
return(ln_normalisation(data, omic_type, procedure))
}
if(procedure == "none"){
return(data)
}
# if nothing is chosen, raise an error
stop("No valid Preprocessing procedure chosen")
}

prefiltering <- function(data, omic_type){
# Filter out low abundant entities for Metabol- and Transcriptomics.
# Filter out low abundant genes for Metabol- and Transcriptmics.
if(omic_type == "Transcriptomics"){
print("Remove anything of rowCount <=10")
return(data[which(rowSums(assay(data)) > 10),])
Expand All @@ -15,7 +35,6 @@ prefiltering <- function(data, omic_type){

simple_center_scaling <- function(data, omic_type){
# Center and scale the data
print("Do chosen Preprocessing: simpleCenterScaling")
# prefilter the data
data <- prefiltering(data, omic_type)
# center and scale the data
Expand All @@ -31,7 +50,6 @@ simple_center_scaling <- function(data, omic_type){

scaling_normalisation <- function(data, omic_type, scaling_procedure){
# Center and scale the data
print(paste0("Do chosen Preprocessing: ", scaling_procedure))
# prefilter the data
data <- prefiltering(data, omic_type)
# scaling functions
Expand All @@ -54,9 +72,9 @@ scaling_normalisation <- function(data, omic_type, scaling_procedure){

ln_normalisation <- function(data, omic_type, logarithm_procedure){
# Center and scale the data
print(paste0("Do chosen Preprocessing: ", logarithm_procedure))
logarithm <- ifelse(logarithm_procedure == "log10", log10, log)
# prefilter the data
browser()
data <- prefiltering(data, omic_type)
# log the data and always add 1 to avoid -Inf
processedData <- as.data.frame(logarithm(as.data.frame(assay(data)) + 1))
Expand All @@ -69,11 +87,9 @@ deseq_processing <- function(
data, omic_type, formula_main, formula_sub, session_token, advanced_formula = NULL
){
# Center and scale the data
print("Do chosen Preprocessing: vst_DESeq")
# prefilter the data
data <- prefiltering(data, omic_type)
# DESeq2
par_tmp[[session_token]]["DESeq_advanced"] <<- FALSE
if(omic_type == "Transcriptomics"){
design_formula <- paste("~", formula_main)
# only do this locally
Expand All @@ -98,12 +114,6 @@ deseq_processing <- function(
else{
par_tmp[[session_token]][["DESeq_factors"]] <<- c(formula_main)
}
# if advanced formula is used, overwrite the other formula
if(!(advanced_formula == "") & startsWith(advanced_formula, "~")){
print("Advanced formula used")
design_formula <- advanced_formula
par_tmp[[session_token]]["DESeq_advanced"] <<- TRUE
}
print(design_formula)
par_tmp[[session_token]]["DESeq_formula"] <<- design_formula
# on purpose local
Expand Down
Loading
Loading