Mercurial > repos > eschen42 > w4mclassfilter
diff w4mclassfilter_wrapper.R @ 14:87ec0d3c2266 draft
"planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit a9664e9a04e49d436ebbb643ba1755397ab759dc"
author | eschen42 |
---|---|
date | Fri, 03 Jan 2020 11:07:39 -0500 |
parents | c18040b6e8b9 |
children |
line wrap: on
line diff
--- a/w4mclassfilter_wrapper.R Thu Oct 24 10:21:23 2019 -0400 +++ b/w4mclassfilter_wrapper.R Fri Jan 03 11:07:39 2020 -0500 @@ -23,8 +23,16 @@ suppressMessages(library(w4mclassfilter)) -if(packageVersion("w4mclassfilter") < "0.98.12") - stop("Please use 'w4mclassfilter' versions of 0.98.12 and above") +expected_version <- "0.98.18" +actual_version <- packageVersion("w4mclassfilter") +if(packageVersion("w4mclassfilter") < expected_version) { + stop( + sprintf( + "Unrecoverable error: Version %s of the 'w4mclassfilter' R package was loaded instead of expected version %s", + actual_version, expected_version + ) + ) +} ## constants ##---------- @@ -104,8 +112,14 @@ classnameColumn <- as.character(argVc["classnameColumn"]) samplenameColumn <- as.character(argVc["samplenameColumn"]) -order_smpl <- as.character(argVc["order_smpl"]) order_vrbl <- as.character(argVc["order_vrbl"]) +centering <- as.character(argVc["centering"]) +order_smpl <- + if (centering == 'centroid' || centering == 'median') { + "sampleMetadata" + } else { + as.character(argVc["order_smpl"]) + } variable_range_filter <- as.character(argVc["variable_range_filter"]) variable_range_filter <- strsplit(x = variable_range_filter, split = ",", fixed = TRUE)[[1]] @@ -115,6 +129,8 @@ ## ----------------------------- my_transformation_and_imputation <- if (transformation == "log10") { function(m) { + # convert negative intensities to missing values + m[m < 0] <- NA if (!is.matrix(m)) stop("Cannot transform and impute data - the supplied data is not in matrix form") if (nrow(m) == 0) @@ -130,6 +146,8 @@ } } else if (transformation == "log2") { function(m) { + # convert negative intensities to missing values + m[m < 0] <- NA if (!is.matrix(m)) stop("Cannot transform and impute data - the supplied data is not in matrix form") if (nrow(m) == 0) @@ -144,8 +162,21 @@ return ( my_imputation_function(m) ) } } else { - # use the method from the w4mclassfilter class - my_imputation_function + function(m) { + # convert negative intensities to missing values + m[m < 0] <- NA + if (!is.matrix(m)) + stop("Cannot transform and impute data - the supplied data is not in matrix form") + if (nrow(m) == 0) + stop("Cannot transform and impute data - data matrix has no rows") + if (ncol(m) == 0) + stop("Cannot transform and impute data - data matrix has no columns") + suppressWarnings({ + # suppress warnings here since non-positive values will produce NaN's that will be fixed in the next step + m[is.na(m)] <- NA + }) + return ( my_imputation_function(m) ) + } } ##------------------------------ @@ -165,6 +196,7 @@ , samplename_column = samplenameColumn , order_vrbl = order_vrbl , order_smpl = order_smpl +, centering = centering , variable_range_filter = variable_range_filter , failure_action = my_print , data_imputation = my_transformation_and_imputation