Mercurial > repos > eschen42 > w4mkmeans
annotate w4m_general_purpose_routines.R @ 6:3f72a635a075 draft default tip
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
| author | eschen42 | 
|---|---|
| date | Fri, 02 Mar 2018 08:32:17 -0500 | 
| parents | 330ee1d840db | 
| children | 
| rev | line source | 
|---|---|
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 1 ##----------------------------------------------- | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 2 ## helper functions for error detection/reporting | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 3 ##----------------------------------------------- | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 4 | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 5 # ISO 8601 date ref: https://en.wikipedia.org/wiki/ISO_8601 | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 6 iso_date <- function() { | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 7 format(Sys.time(), "%Y-%m-%dT%H:%M:%S%z") | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 8 } | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 9 | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 10 # log-printing to stderr | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 11 log_print <- function(x, ...) { | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 12 cat( | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 13 sep="" | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 14 , file=stderr() | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 15 , iso_date() | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 16 , " " | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 17 , c(x, ...) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 18 , "\n" | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 19 ) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 20 } | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 21 | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 22 # format error for logging | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 23 format_error <- function(e) { | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 24 paste(c("Error { message:", e$message, ", call:", e$call, "}"), collapse = " ") | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 25 } | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 26 | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 27 # tryCatchFunc produces a list | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 28 # func - a function that takes no arguments | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 29 # On success of func(), tryCatchFunc produces | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 30 # list(success = TRUE, value = func(), msg = "") | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 31 # On failure of func(), tryCatchFunc produces | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 32 # list(success = FALSE, value = NA, msg = "the error message") | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 33 tryCatchFunc <- function(func) { | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 34 retval <- NULL | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 35 tryCatch( | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 36 expr = { | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 37 retval <- ( list( success = TRUE, value = func(), msg = "" ) ) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 38 } | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 39 , error = function(e) { | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 40 retval <<- list( success = FALSE, value = NA, msg = format_error(e) ) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 41 } | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 42 ) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 43 return (retval) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 44 } | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 45 | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 46 # prepare.data.matrix - Prepare x.datamatrix for multivariate statistical analaysis (MVA) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 47 # - Motivation: | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 48 # - Selection: | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 49 # - You may want to exclude several samples from your analysis: | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 50 # - If so, set the argument 'exclude.samples' to a vector of sample names | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 51 # - You may want to exclude several features or features from your analysis: | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 52 # - If so, set the argument 'exclude.features' to a vector of feature names | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 53 # - Renaming samples: | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 54 # - You may want to rename several samples from your analysis: | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 55 # - If so, set the argument 'sample.rename.function' to a function accepting a vector | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 56 # of sample names and producing a vector of strings of equivalent length | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 57 # - MVA is confounded by missing values. | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 58 # - By default, this function imputes missing values as zero. | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 59 # - For a different imputation, set the 'data.imputation' argument to a function | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 60 # accepting a single matrix argument and returning a matrix of the same | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 61 # dimensions as the argument. | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 62 # - Transformation | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 63 # - It may be desirable to transform the intensity data to reduce the range. | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 64 # - By default, this function performs an eigth-root transformation: | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 65 # - Any root-tranformation has the advantage of never being negative. | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 66 # - Calculation of the eight-root is four times faster in my hands than log10. | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 67 # - However, it has the disadvantage that calculation of fold-differences | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 68 # is not additive as with log-transformation. | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 69 # - Rather, you must divide the values and raise to the eighth power. | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 70 # - For a different transformation, set the 'data.transformation' argument | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 71 # to a function accepting a single matrix argument. | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 72 # - The function should be written to return a matrix of the same dimensions | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 73 # as the argument. | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 74 # arguments: | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 75 # - x.matrix - matrix of intensities (or data.frame of sample metadata) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 76 # - one row per sample | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 77 # - one column per feature or metadata attribute | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 78 # - exclude.samples - vector of labels of matrix rows (samples) to omit from analysis | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 79 # - exclude.features - vector of labels of matrix columnss (features) to omit from analysis | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 80 # - sample.rename.function - function to be used to rename rows if necessary, or NULL | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 81 # - e.g., sample.rename.function = function(x) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 82 # sub("(.*)_.*","\\1", row.names(x)) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 83 # } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 84 # - data.imputation - function applied to matrix to impute missing values | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 85 # - e.g., data.imputation = function(m) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 86 # m[is.na(m)] <- min(m, na.rm = TRUE) / 100 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 87 # return (m) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 88 # } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 89 # - data.transformation - function applied to matrix cells | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 90 # - e.g., data.transformation = function(x) { return( log10(x) ) } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 91 # or, data.transformation = log10 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 92 # result value: | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 93 # transformed, imputed x.datamatrix with renamed rows and with neither excluded values nor features | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 94 # | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 95 ################################ | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 96 ## | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 97 ## Notes regarding the effectiveness and performance of the data transformation method. | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 98 ## | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 99 ## The two transformations that I tried (log10 and 8th root) required different imputation methods. | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 100 ## | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 101 ## For the LCMS resin data set that I was working with, separation in MVA was nearly equivalent for: | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 102 ## data.imputation <- function(x.matrix) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 103 ## x.matrix[is.na(x.matrix)] <- 0 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 104 ## return (x.matrix) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 105 ## } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 106 ## data.transformation <- function(x) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 107 ## sqrt( sqrt( sqrt(x) ) ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 108 ## } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 109 ## and | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 110 ## data.imputation <- function(x.matrix) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 111 ## x.matrix[is.na(x.matrix)] <- min(x.matrix, na.rm = TRUE) / 100 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 112 ## return (x.matrix) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 113 ## } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 114 ## data.transformation <- function(x) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 115 ## log10(x) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 116 ## } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 117 ## | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 118 ## Note further that triple application of the square root: | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 119 ## - may be four times faster than log10: | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 120 ## - may be three times faster than log2: | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 121 ## | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 122 ## system.time( junk <- sqrt( sqrt( sqrt(1:100000000) ) ) ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 123 ## user system elapsed | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 124 ## 0.832 0.236 1.069 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 125 ## system.time( junk <- log10(1:100000000) ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 126 ## user system elapsed | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 127 ## 3.936 0.400 4.337 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 128 ## system.time( junk <- log2(1:100000000) ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 129 ## user system elapsed | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 130 ## 2.784 0.320 3.101 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 131 ## | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 132 ################################ | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 133 # | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 134 prepare.data.matrix <- function( | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 135 x.matrix | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 136 , exclude.samples = NULL | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 137 , exclude.features = NULL | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 138 , sample.rename.function = NULL | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 139 , data.imputation = | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 140 function(m) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 141 # replace NA values with zero | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 142 m[is.na(m)] <- 0 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 143 # replace negative values with zero, if applicable (It should never be applicable!) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 144 if (min(m < 0)) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 145 m <- matrix(lapply(X = m, FUN = function(z) {max(z,0)}), nrow = nrow(m) ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 146 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 147 # return matrix as the result | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 148 return (m) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 149 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 150 , data.transformation = function(x) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 151 sqrt( sqrt( sqrt(x) ) ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 152 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 153 , en = new.env() | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 154 ) { | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 155 # log to environment | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 156 if ( !exists("log", envir = en) ) { | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 157 en$log <- c() | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 158 } | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 159 enlog <- function(s) { en$log <- c(en$log, s); s } | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 160 #enlog("foo") | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 161 | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 162 # MatVar - Compute variance of rows or columns of a matrix | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 163 # ref: http://stackoverflow.com/a/25100036 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 164 # For row variance, dim == 1, for col variance, dim == 2 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 165 MatVar <- function(x, dim = 1) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 166 if (dim == 1) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 167 dim.x.2 <- dim(x)[2] | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 168 if ( dim.x.2 == 0 ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 169 stop("MatVar: there are zero columns") | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 170 if ( dim.x.2 == 1 ) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 171 stop("MatVar: a single column is insufficient to calculate a variance") | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 172 # return ( rep.int(x = 0, times = nrow(x)) ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 173 } else { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 174 return ( rowSums( (x - rowMeans(x))^2 ) / ( dim(x)[2] - 1 ) ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 175 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 176 } else if (dim == 2) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 177 dim.x.1 <- dim(x)[1] | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 178 if ( dim.x.1 == 0 ) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 179 stop("MatVar: there are zero rows") | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 180 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 181 if ( dim.x.1 == 1 ) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 182 stop("MatVar: a single row is insufficient to calculate a variance") | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 183 # return ( rep.int(x = 0, times = ncol(x)) ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 184 } else { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 185 return ( rowSums( (t(x) - colMeans(x))^2 ) / ( dim(x)[1] - 1 ) ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 186 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 187 } else stop("Please enter valid dimension, for rows, dim = 1; for colums, dim = 2") | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 188 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 189 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 190 nonzero.var <- function(x) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 191 if (nrow(x) == 0) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 192 stop("matrix has no rows") | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 193 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 194 if (ncol(x) == 0) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 195 stop("matrix has no columns") | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 196 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 197 if ( is.numeric(x) ) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 198 # exclude any rows with zero variance | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 199 row.vars <- MatVar(x, dim = 1) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 200 nonzero.row.vars <- row.vars > 0 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 201 nonzero.rows <- row.vars[nonzero.row.vars] | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 202 if ( length(rownames(x)) != length(rownames(nonzero.rows)) ) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 203 row.names <- attr(nonzero.rows,"names") | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 204 x <- x[ row.names, , drop = FALSE ] | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 205 } | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 206 | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 207 # exclude any columns with zero variance | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 208 column.vars <- MatVar(x, dim = 2) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 209 nonzero.column.vars <- column.vars > 0 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 210 nonzero.columns <- column.vars[nonzero.column.vars] | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 211 if ( length(colnames(x)) != length(colnames(nonzero.columns)) ) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 212 column.names <- attr(nonzero.columns,"names") | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 213 x <- x[ , column.names, drop = FALSE ] | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 214 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 215 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 216 return (x) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 217 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 218 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 219 if (is.null(x.matrix)) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 220 stop("FATAL ERROR - prepare.data.matrix was called with null x.matrix") | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 221 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 222 | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 223 enlog("prepare.data.matrix - get matrix") | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 224 | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 225 en$xpre <- x <- x.matrix | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 226 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 227 # exclude any samples as indicated | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 228 if ( !is.null(exclude.features) ) { | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 229 enlog("prepare.data.matrix - exclude any samples as indicated") | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 230 my.colnames <- colnames(x) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 231 my.col.diff <- setdiff(my.colnames, exclude.features) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 232 x <- x[ , my.col.diff , drop = FALSE ] | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 233 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 234 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 235 # exclude any features as indicated | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 236 if ( !is.null(exclude.samples) ) { | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 237 enlog("prepare.data.matrix - exclude any features as indicated") | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 238 my.rownames <- rownames(x) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 239 my.row.diff <- setdiff(my.rownames, exclude.samples) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 240 x <- x[ my.row.diff, , drop = FALSE ] | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 241 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 242 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 243 # rename rows if desired | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 244 if ( !is.null(sample.rename.function) ) { | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 245 enlog("prepare.data.matrix - rename rows if desired") | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 246 renamed <- sample.rename.function(x) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 247 rownames(x) <- renamed | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 248 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 249 | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 250 enlog("prepare.data.matrix - save redacted x.datamatrix to environment") | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 251 | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 252 # save redacted x.datamatrix to environment | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 253 en$redacted.data.matrix <- x | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 254 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 255 # impute values missing from the x.datamatrix | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 256 if ( !is.null(data.imputation) ) { | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 257 enlog("prepare.data.matrix - impute values missing from the x.datamatrix") | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 258 x <- data.imputation(x) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 259 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 260 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 261 # perform transformation if desired | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 262 if ( !is.null(data.transformation) ) { | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 263 enlog("prepare.data.matrix - perform transformation") | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 264 x <- data.transformation(x) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 265 } else { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 266 x <- x | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 267 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 268 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 269 # purge rows and columns that have zero variance | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 270 if ( is.numeric(x) ) { | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 271 enlog("prepare.data.matrix - purge rows and columns that have zero variance") | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 272 x <- nonzero.var(x) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 273 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 274 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 275 # save imputed, transformed x.datamatrix to environment | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 276 en$imputed.transformed.data.matrix <- x | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 277 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 278 return(x) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 279 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 280 | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
0diff
changeset | 281 # vim: sw=2 ts=2 et : | 
