Skip to content

Commit

Permalink
modify valCutoff funtion in propr.R (#5995)
Browse files Browse the repository at this point in the history
Co-authored-by: Cristina Araiz <[email protected]>
  • Loading branch information
caraiz2001 and Cristina Araiz authored Jul 18, 2024
1 parent e2e6613 commit 132fa6c
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions modules/nf-core/propr/propr/templates/propr.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,33 +124,26 @@ seqCutoff <- function(object){
valCutoff <- function(object, metric, fdrVal = 0.05){
fdr_df <- object@fdr
print(fdr_df)
metric_up <- c("rho", "cor", "pcor", "pcor.shrink", "pcor.bshrink")
# metric_up <- c("rho", "cor", "pcor", "pcor.shrink", "pcor.bshrink")

if (prod(dim(fdr_df) == 0)){
warning("Please run updateCutoff on propr first")
}else{
fdr_vals <- fdr_df\$FDR
if (any(is.na(fdr_vals))){
stop("FDR not defined. This metric is not appropiate for the given dataset")
}
threshold <- any(fdr_vals <= fdrVal)
if (metric %in% metric_up){
if (threshold){
fdr_threshold <- fdr_vals[which.max(fdr_vals <= fdrVal)]
if(any(!is.na(fdr_vals))){ # if there is some defined value, continue, else out of range
if(any(fdr_vals <= fdrVal)){ # if there is some value that is belowe the FDR threshold,
fdr_threshold <- fdr_vals[which.max(fdr_vals <= fdrVal)] #choose the highest FDR that is lower than the threshold, else choose the lowest
}else{
warning("FDR is higher than the specified threshold for all proportionality values. Using the lowest fdr instead")
fdr_threshold <- fdr_vals[length(fdr_vals)]
fdr_threshold <- min(fdr_vals, na.rm = TRUE)
}
cutoff <- fdr_df\$cutoff[which(fdr_df\$FDR == fdr_threshold)] #select the corresponding cutoff value for the FDR
print(cutoff)
}else{
if (threshold){
fdr_threshold <- fdr_vals[which.min(fdr_vals <= fdrVal) - 1]
}else{
warning("FDR is higher than the specified threshold for all proportionality values. Using the lowest fdr instead")
fdr_threshold <- fdr_vals[1]
}
stop("FDR not defined. This metric is not appropiate for the given dataset")
}
cutoff <- fdr_df\$cutoff[fdr_df\$FDR == fdr_threshold]
}
return(cutoff)
}
}


Expand Down

0 comments on commit 132fa6c

Please sign in to comment.