comparison 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
comparison
equal deleted inserted replaced
13:c18040b6e8b9 14:87ec0d3c2266
21 ## libraries 21 ## libraries
22 ##---------- 22 ##----------
23 23
24 suppressMessages(library(w4mclassfilter)) 24 suppressMessages(library(w4mclassfilter))
25 25
26 if(packageVersion("w4mclassfilter") < "0.98.12") 26 expected_version <- "0.98.18"
27 stop("Please use 'w4mclassfilter' versions of 0.98.12 and above") 27 actual_version <- packageVersion("w4mclassfilter")
28 if(packageVersion("w4mclassfilter") < expected_version) {
29 stop(
30 sprintf(
31 "Unrecoverable error: Version %s of the 'w4mclassfilter' R package was loaded instead of expected version %s",
32 actual_version, expected_version
33 )
34 )
35 }
28 36
29 ## constants 37 ## constants
30 ##---------- 38 ##----------
31 39
32 modNamC <- "w4mclassfilter" ## module name 40 modNamC <- "w4mclassfilter" ## module name
102 } 110 }
103 inclusive <- as.logical(argVc["inclusive"]) 111 inclusive <- as.logical(argVc["inclusive"])
104 classnameColumn <- as.character(argVc["classnameColumn"]) 112 classnameColumn <- as.character(argVc["classnameColumn"])
105 samplenameColumn <- as.character(argVc["samplenameColumn"]) 113 samplenameColumn <- as.character(argVc["samplenameColumn"])
106 114
107 order_smpl <- as.character(argVc["order_smpl"])
108 order_vrbl <- as.character(argVc["order_vrbl"]) 115 order_vrbl <- as.character(argVc["order_vrbl"])
116 centering <- as.character(argVc["centering"])
117 order_smpl <-
118 if (centering == 'centroid' || centering == 'median') {
119 "sampleMetadata"
120 } else {
121 as.character(argVc["order_smpl"])
122 }
109 123
110 variable_range_filter <- as.character(argVc["variable_range_filter"]) 124 variable_range_filter <- as.character(argVc["variable_range_filter"])
111 variable_range_filter <- strsplit(x = variable_range_filter, split = ",", fixed = TRUE)[[1]] 125 variable_range_filter <- strsplit(x = variable_range_filter, split = ",", fixed = TRUE)[[1]]
112 126
113 ## ----------------------------- 127 ## -----------------------------
114 ## Transformation and imputation 128 ## Transformation and imputation
115 ## ----------------------------- 129 ## -----------------------------
116 my_transformation_and_imputation <- if (transformation == "log10") { 130 my_transformation_and_imputation <- if (transformation == "log10") {
117 function(m) { 131 function(m) {
132 # convert negative intensities to missing values
133 m[m < 0] <- NA
118 if (!is.matrix(m)) 134 if (!is.matrix(m))
119 stop("Cannot transform and impute data - the supplied data is not in matrix form") 135 stop("Cannot transform and impute data - the supplied data is not in matrix form")
120 if (nrow(m) == 0) 136 if (nrow(m) == 0)
121 stop("Cannot transform and impute data - data matrix has no rows") 137 stop("Cannot transform and impute data - data matrix has no rows")
122 if (ncol(m) == 0) 138 if (ncol(m) == 0)
128 }) 144 })
129 return ( my_imputation_function(m) ) 145 return ( my_imputation_function(m) )
130 } 146 }
131 } else if (transformation == "log2") { 147 } else if (transformation == "log2") {
132 function(m) { 148 function(m) {
149 # convert negative intensities to missing values
150 m[m < 0] <- NA
133 if (!is.matrix(m)) 151 if (!is.matrix(m))
134 stop("Cannot transform and impute data - the supplied data is not in matrix form") 152 stop("Cannot transform and impute data - the supplied data is not in matrix form")
135 if (nrow(m) == 0) 153 if (nrow(m) == 0)
136 stop("Cannot transform and impute data - data matrix has no rows") 154 stop("Cannot transform and impute data - data matrix has no rows")
137 if (ncol(m) == 0) 155 if (ncol(m) == 0)
142 m[is.na(m)] <- NA 160 m[is.na(m)] <- NA
143 }) 161 })
144 return ( my_imputation_function(m) ) 162 return ( my_imputation_function(m) )
145 } 163 }
146 } else { 164 } else {
147 # use the method from the w4mclassfilter class 165 function(m) {
148 my_imputation_function 166 # convert negative intensities to missing values
167 m[m < 0] <- NA
168 if (!is.matrix(m))
169 stop("Cannot transform and impute data - the supplied data is not in matrix form")
170 if (nrow(m) == 0)
171 stop("Cannot transform and impute data - data matrix has no rows")
172 if (ncol(m) == 0)
173 stop("Cannot transform and impute data - data matrix has no columns")
174 suppressWarnings({
175 # suppress warnings here since non-positive values will produce NaN's that will be fixed in the next step
176 m[is.na(m)] <- NA
177 })
178 return ( my_imputation_function(m) )
179 }
149 } 180 }
150 181
151 ##------------------------------ 182 ##------------------------------
152 ## Computation 183 ## Computation
153 ##------------------------------ 184 ##------------------------------
163 , include = inclusive 194 , include = inclusive
164 , class_column = classnameColumn 195 , class_column = classnameColumn
165 , samplename_column = samplenameColumn 196 , samplename_column = samplenameColumn
166 , order_vrbl = order_vrbl 197 , order_vrbl = order_vrbl
167 , order_smpl = order_smpl 198 , order_smpl = order_smpl
199 , centering = centering
168 , variable_range_filter = variable_range_filter 200 , variable_range_filter = variable_range_filter
169 , failure_action = my_print 201 , failure_action = my_print
170 , data_imputation = my_transformation_and_imputation 202 , data_imputation = my_transformation_and_imputation
171 ) 203 )
172 204