Skip to content

Commit

Permalink
Moved CheckInputs_ORA() to HelperChecks.R
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristinaSchmidt1 committed Nov 5, 2024
1 parent 849586e commit 7c6fcce
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 137 deletions.
139 changes: 139 additions & 0 deletions R/HelperChecks.R
Original file line number Diff line number Diff line change
Expand Up @@ -495,3 +495,142 @@ CheckInput_DMA <- function(InputData,
return(invisible(Settings))
}


################################################################################################
### ### ### ORA helper function: Internal Function to check function input ### ### ###
################################################################################################

#' Check input parameters
#'
#' @param InputData Passed to main function PreProcessing()
#' @param SettingsInfo Passed to main function PreProcessing()
#'
#' @keywords Input check
#' @noRd
#'
#'

CheckInput_ORA <- function(InputData,
SettingsInfo,
RemoveBackground,
PathwayFile,
PathwayName,
minGSSize,
maxGSSize,
SaveAs_Table,
pCutoff,
PercentageCutoff
){
# 1. The input data:
if(class(InputData) != "data.frame"){
stop("InputData should be a data.frame. It's currently a ", paste(class(InputData), ".",sep = ""))
}
if(any(duplicated(row.names(InputData)))==TRUE){
stop("Duplicated row.names of InputData, whilst row.names must be unique")
}

# 2. Settings Columns:
if(is.vector(SettingsInfo)==FALSE & is.null(SettingsInfo)==FALSE){
stop("SettingsInfo should be NULL or a vector. It's currently a ", paste(class(SettingsInfo), ".", sep = ""))
}

if(is.null(SettingsInfo)==FALSE){
#"ClusterColumn"
if("ClusterColumn" %in% names(SettingsInfo)){
if(SettingsInfo[["ClusterColumn"]] %in% colnames(InputData)== FALSE){
stop("The ", SettingsInfo[["ClusterColumn"]], " column selected as ClusterColumn in SettingsInfo was not found in InputData. Please check your input.")
}
}

#"BackgroundColumn"
if("BackgroundColumn" %in% names(SettingsInfo)){
if(SettingsInfo[["BackgroundColumn"]] %in% colnames(InputData)== FALSE){
stop("The ", SettingsInfo[["BackgroundColumn"]], " column selected as BackgroundColumn in SettingsInfo was not found in InputData. Please check your input.")
}
}

#"pvalColumn"
if("pvalColumn" %in% names(SettingsInfo)){
if(SettingsInfo[["pvalColumn"]] %in% colnames(InputData)== FALSE){
stop("The ", SettingsInfo[["pvalColumn"]], " column selected as pvalColumn in SettingsInfo was not found in InputData. Please check your input.")
}
}

#"PercentageColumn"
if("PercentageColumn" %in% names(SettingsInfo)){
if(SettingsInfo[["PercentageColumn"]] %in% colnames(InputData)== FALSE){
stop("The ", SettingsInfo[["PercentageColumn"]], " column selected as PercentageColumn in SettingsInfo was not found in InputData. Please check your input.")
}
}


#"PathwayTerm"
if("PathwayTerm" %in% names(SettingsInfo)){
if(SettingsInfo[["PathwayTerm"]] %in% colnames(PathwayFile)== FALSE){
stop("The ", SettingsInfo[["PathwayTerm"]], " column selected as PathwayTerm in SettingsInfo was not found in PathwayFile. Please check your input.")
}else{
PathwayFile <- PathwayFile%>%
dplyr::rename("term"=SettingsInfo[["PathwayTerm"]])
PathwayFile$Description <- PathwayFile$term
}
}else{
stop("SettingsInfo must provide the column name for PathwayTerm in PathwayFile")
}

# PathwayFeature
if("PathwayFeature" %in% names(SettingsInfo)){
if(SettingsInfo[["PathwayFeature"]] %in% colnames(PathwayFile)== FALSE){
stop("The ", SettingsInfo[["PathwayFeature"]], " column selected as PathwayFeature in SettingsInfo was not found in PathwayFile. Please check your input.")
}else{
PathwayFile <- PathwayFile%>%
dplyr::rename("gene"=SettingsInfo[["PathwayFeature"]])
}
}else{
stop("SettingsInfo must provide the column name for PathwayFeature in PathwayFile")
}

}else{
stop("you must provide SettingsInfo.")
}

# 3. General Settings
if(is.character(PathwayName)==FALSE){
stop("Check input. PathwayName must be a character of syntax 'example'.")
}

if(is.logical(RemoveBackground) == FALSE){
stop("Check input. RemoveBackground value should be either =TRUE or = FALSE.")
}

if(is.numeric(minGSSize)== FALSE){
stop("Check input. The selected minGSSize value should be numeric.")
}

if(is.numeric(maxGSSize)== FALSE){
stop("Check input. The selected maxGSSize value should be numeric.")
}

SaveAs_Table_options <- c("txt","csv", "xlsx", "RData")#RData = SummarizedExperiment (?)
if(is.null(SaveAs_Table)==FALSE){
if((SaveAs_Table %in% SaveAs_Table_options == FALSE)| (is.null(SaveAs_Table)==TRUE)){
stop("Check input. The selected SaveAs_Table option is not valid. Please select one of the folowwing: ",paste(SaveAs_Table_options,collapse = ", "),"." )
}
}

if(is.null(pCutoff)== FALSE){
if(is.numeric(pCutoff)== FALSE | pCutoff > 1 | pCutoff < 0){
stop("Check input. The selected Plot_pCutoff value should be numeric and between 0 and 1.")
}
}

if(is.null(PercentageCutoff)== FALSE){
if( is.numeric(PercentageCutoff)== FALSE | PercentageCutoff > 100 | PercentageCutoff < 0){
stop("Check input. The selected PercentageCutoff value should be numeric and between 0 and 100.")
}
}


## -------- Return Pathways ---------##
return(invisible(PathwayFile))
}

137 changes: 0 additions & 137 deletions R/OverRepresentationAnalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -301,140 +301,3 @@ StandardORA <- function(InputData,
}


################################################################################################
### ### ### ORA helper function: Internal Function to check function input ### ### ###
################################################################################################

#' Check input parameters
#'
#' @param InputData Passed to main function PreProcessing()
#' @param SettingsInfo Passed to main function PreProcessing()
#'
#' @keywords Input check
#' @noRd
#'
#'

CheckInput_ORA <- function(InputData,
SettingsInfo,
RemoveBackground,
PathwayFile,
PathwayName,
minGSSize,
maxGSSize,
SaveAs_Table,
pCutoff,
PercentageCutoff
){
# 1. The input data:
if(class(InputData) != "data.frame"){
stop("InputData should be a data.frame. It's currently a ", paste(class(InputData), ".",sep = ""))
}
if(any(duplicated(row.names(InputData)))==TRUE){
stop("Duplicated row.names of InputData, whilst row.names must be unique")
}

# 2. Settings Columns:
if(is.vector(SettingsInfo)==FALSE & is.null(SettingsInfo)==FALSE){
stop("SettingsInfo should be NULL or a vector. It's currently a ", paste(class(SettingsInfo), ".", sep = ""))
}

if(is.null(SettingsInfo)==FALSE){
#"ClusterColumn"
if("ClusterColumn" %in% names(SettingsInfo)){
if(SettingsInfo[["ClusterColumn"]] %in% colnames(InputData)== FALSE){
stop("The ", SettingsInfo[["ClusterColumn"]], " column selected as ClusterColumn in SettingsInfo was not found in InputData. Please check your input.")
}
}

#"BackgroundColumn"
if("BackgroundColumn" %in% names(SettingsInfo)){
if(SettingsInfo[["BackgroundColumn"]] %in% colnames(InputData)== FALSE){
stop("The ", SettingsInfo[["BackgroundColumn"]], " column selected as BackgroundColumn in SettingsInfo was not found in InputData. Please check your input.")
}
}

#"pvalColumn"
if("pvalColumn" %in% names(SettingsInfo)){
if(SettingsInfo[["pvalColumn"]] %in% colnames(InputData)== FALSE){
stop("The ", SettingsInfo[["pvalColumn"]], " column selected as pvalColumn in SettingsInfo was not found in InputData. Please check your input.")
}
}

#"PercentageColumn"
if("PercentageColumn" %in% names(SettingsInfo)){
if(SettingsInfo[["PercentageColumn"]] %in% colnames(InputData)== FALSE){
stop("The ", SettingsInfo[["PercentageColumn"]], " column selected as PercentageColumn in SettingsInfo was not found in InputData. Please check your input.")
}
}


#"PathwayTerm"
if("PathwayTerm" %in% names(SettingsInfo)){
if(SettingsInfo[["PathwayTerm"]] %in% colnames(PathwayFile)== FALSE){
stop("The ", SettingsInfo[["PathwayTerm"]], " column selected as PathwayTerm in SettingsInfo was not found in PathwayFile. Please check your input.")
}else{
PathwayFile <- PathwayFile%>%
dplyr::rename("term"=SettingsInfo[["PathwayTerm"]])
PathwayFile$Description <- PathwayFile$term
}
}else{
stop("SettingsInfo must provide the column name for PathwayTerm in PathwayFile")
}

# PathwayFeature
if("PathwayFeature" %in% names(SettingsInfo)){
if(SettingsInfo[["PathwayFeature"]] %in% colnames(PathwayFile)== FALSE){
stop("The ", SettingsInfo[["PathwayFeature"]], " column selected as PathwayFeature in SettingsInfo was not found in PathwayFile. Please check your input.")
}else{
PathwayFile <- PathwayFile%>%
dplyr::rename("gene"=SettingsInfo[["PathwayFeature"]])
}
}else{
stop("SettingsInfo must provide the column name for PathwayFeature in PathwayFile")
}

}else{
stop("you must provide SettingsInfo.")
}

# 3. General Settings
if(is.character(PathwayName)==FALSE){
stop("Check input. PathwayName must be a character of syntax 'example'.")
}

if(is.logical(RemoveBackground) == FALSE){
stop("Check input. RemoveBackground value should be either =TRUE or = FALSE.")
}

if(is.numeric(minGSSize)== FALSE){
stop("Check input. The selected minGSSize value should be numeric.")
}

if(is.numeric(maxGSSize)== FALSE){
stop("Check input. The selected maxGSSize value should be numeric.")
}

SaveAs_Table_options <- c("txt","csv", "xlsx", "RData")#RData = SummarizedExperiment (?)
if(is.null(SaveAs_Table)==FALSE){
if((SaveAs_Table %in% SaveAs_Table_options == FALSE)| (is.null(SaveAs_Table)==TRUE)){
stop("Check input. The selected SaveAs_Table option is not valid. Please select one of the folowwing: ",paste(SaveAs_Table_options,collapse = ", "),"." )
}
}

if(is.null(pCutoff)== FALSE){
if(is.numeric(pCutoff)== FALSE | pCutoff > 1 | pCutoff < 0){
stop("Check input. The selected Plot_pCutoff value should be numeric and between 0 and 1.")
}
}

if(is.null(PercentageCutoff)== FALSE){
if( is.numeric(PercentageCutoff)== FALSE | PercentageCutoff > 100 | PercentageCutoff < 0){
stop("Check input. The selected PercentageCutoff value should be numeric and between 0 and 100.")
}
}


## -------- Return Pathways ---------##
return(invisible(PathwayFile))
}

0 comments on commit 7c6fcce

Please sign in to comment.