Mercurial > repos > eschen42 > w4mkmeans
annotate w4mkmeans_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 | 6817b036b06e | 
| children | 
| rev | line source | 
|---|---|
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 1 ##------------------------------------------------------------------------------------------------------ | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 2 ## these are the batch-independent and file-structure-independent routines to support the w4mkmeans tool | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 3 ##------------------------------------------------------------------------------------------------------ | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 4 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 5 library(parallel) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 6 | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 7 w4mkmeans_usage <- function() { | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 8 return ( | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 9 c( | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 10 "w4mkmeans: bad input.", | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 11 " contract:", | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 12 " required - caller will provide an environment comprising:", | 
| 4 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 13 " log_print - a logging function with the signature function(x, ...) expecting strings as x and ...", | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 14 " variableMetadata - the corresponding W4M data.frame having feature metadata", | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 15 " sampleMetdata - the corresponding W4M data.frame having sample metadata", | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 16 " dataMatrix - the corresponding W4M matrix", | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 17 " slots - the number of parallel slots for calculating kmeans", | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 18 " optional - environment may comprise:", | 
| 4 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 19 " kfeatures - an array of integers, the k's to apply for clustering by feature (default, empty array)", | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 20 " ksamples - an array of integers, the k's to apply for clustering by sample (default, empty array)", | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 21 " iter_max - the maximum number of iterations when calculating a cluster (default = 20)", | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 22 " nstart - how many random sets of centers should be chosen (default = 20)", | 
| 4 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 23 " algorithm - string from c('Hartigan-Wong', 'Lloyd', 'Forgy', 'MacQueen') (default = Hartigan-Wong)", | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 24 " categorical_prefix - string from c('Hartigan-Wong', 'Lloyd', 'Forgy', 'MacQueen') (default = Hartigan-Wong)", | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 25 " ", | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 26 " this routine will return a list comprising:", | 
| 4 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 27 " variableMetadata - the input variableMetadata data.frame with updates, if any", | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 28 " sampleMetadata - the input sampleMetadata data.frame with updates, if any", | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 29 " scores - an array of strings, each representing a line of a tsv having the following header:", | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 30 " clusterOn TAB k TAB totalSS TAB betweenSS TAB proportion" | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 31 ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 32 ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 33 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 34 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 35 w4mkmeans <- function(env) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 36 # abort if 'env' is null or is not an environment | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 37 if ( is.null(env) || ! is.environment(env) ) { | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 38 lapply(w4mkmeans_usage(),print) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 39 } | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 40 # extract parameters from 'env' | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 41 log_action <- env$log_print | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 42 # supply default arguments | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 43 if ( ! exists("iter_max" , env) ) env$iter_max <- 20 | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 44 if ( ! exists("nstart" , env) ) env$nstart <- 20 | 
| 4 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 45 if ( ! exists("algorithm" , env) ) env$algorithm <- 'Hartigan-Wong' | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 46 if ( ! exists("categorical_prefix", env) ) env$categorical_prefix <- 'c' | 
| 4 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 47 if ( ! exists("ksamples" , env) ) env$ksamples <- c() | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 48 if ( ! exists("kfeatures" , env) ) env$kfeatures <- c() | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 49 # check mandatory arguments | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 50 expected <- c( | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 51 "log_print" | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 52 , "variableMetadata" | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 53 , "sampleMetadata" | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 54 , "dataMatrix" | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 55 , "slots" | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 56 ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 57 missing_from_env <- setdiff(expected, (ls(env))) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 58 if ( length(missing_from_env) > 0 ) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 59 print(paste(c('expected environment members not found: ', as.character(missing_from_env)), collapse = ", ")) | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 60 lapply(w4mkmeans_usage(),log_action) | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 61 stop("w4mkmeans: contract has been broken") | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 62 } | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 63 # extract parameters from 'env' | 
| 5 
6817b036b06e
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 511f1d2602aac662d3513701a38b5405766face6
 eschen42 parents: 
4diff
changeset | 64 log_action <- env$log_print | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 65 scores <- c( "clusterOn\tk\ttotalSS\tbetweenSS\tproportion" ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 66 sampleMetadata <- env$sampleMetadata | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 67 featureMetadata <- env$variableMetadata | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 68 slots <- env$slots | 
| 4 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 69 positive_ints <- function(a, what) { | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 70 i <- as.integer(a) # may introduce NAs by coercion | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 71 i <- i[!is.na(i)] # eliminate NAs | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 72 i <- i[i > 0] # eliminate non-positive integers | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 73 i <- unique(sort(i)) # eliminate redundancy and disorder | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 74 if (length(a)!=length(i)) { | 
| 5 
6817b036b06e
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 511f1d2602aac662d3513701a38b5405766face6
 eschen42 parents: 
4diff
changeset | 75 log_action("Some values for '", what, "' were skipped where not unique, not positive, or not convertible to an integer.") | 
| 4 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 76 } | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 77 return (i) # return results, if any | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 78 } | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 79 ksamples <- positive_ints(env$ksamples , "ksamples") | 
| 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 80 kfeatures <- positive_ints(env$kfeatures, "kfeatures") | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 81 | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 82 log_action("w4mkmeans: preparing data matrix") | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 83 # prepare data matrix (normalize, eliminate zero-variance rows, etc.; no transformation) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 84 dm_en <- new.env() | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 85 dm_en$log <- c() | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 86 preparation_result <- tryCatchFunc(function(){ | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 87 dm <- prepare.data.matrix( | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 88 x.matrix = env$dataMatrix | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 89 , data.transformation = function(x) { x } | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 90 , en = dm_en | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 91 ) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 92 my_log <- dm_en$log | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 93 for ( i in 1:length(my_log) ) { | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 94 log_action(my_log[i]) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 95 } | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 96 dm | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 97 }) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 98 if ( !preparation_result$success ) { | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 99 postmortem <- paste("prepare.data.matrix failed:", preparation_result$msg) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 100 log_action(postmortem) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 101 stop(postmortem) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 102 } | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 103 | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 104 env$preparedDataMatrix <- preparation_result$value | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 105 | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 106 log_action("w4mkmeans: determining evaluation mode") | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 107 | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 108 myLapply <- parLapply | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 109 cl <- NULL | 
| 5 
6817b036b06e
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 511f1d2602aac662d3513701a38b5405766face6
 eschen42 parents: 
4diff
changeset | 110 tryCatch( | 
| 
6817b036b06e
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 511f1d2602aac662d3513701a38b5405766face6
 eschen42 parents: 
4diff
changeset | 111 expr = { | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 112 outfile <- "" | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 113 # outfile: Where to direct the stdout and stderr connection output from the workers. | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 114 # - "" indicates no redirection (which may only be useful for workers on the local machine). | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 115 # - Defaults to ‘/dev/null’ (‘nul:’ on Windows). | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 116 # - The other possibility is a file path on the worker's host. | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 117 # - Files will be opened in append mode, as all workers log to the same file. | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 118 cl <- makePSOCKcluster( names = slots, outfile = outfile ) | 
| 5 
6817b036b06e
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 511f1d2602aac662d3513701a38b5405766face6
 eschen42 parents: 
4diff
changeset | 119 } | 
| 
6817b036b06e
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 511f1d2602aac662d3513701a38b5405766face6
 eschen42 parents: 
4diff
changeset | 120 , error = function(e) { | 
| 
6817b036b06e
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 511f1d2602aac662d3513701a38b5405766face6
 eschen42 parents: 
4diff
changeset | 121 log_action(sprintf("w4kmeans: falling back to serial evaluation because makePSOCKcluster(names = %d) threw an exception", slots)) | 
| 
6817b036b06e
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 511f1d2602aac662d3513701a38b5405766face6
 eschen42 parents: 
4diff
changeset | 122 # mimic parLapply, but without parallelization (as a last resort) | 
| 
6817b036b06e
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 511f1d2602aac662d3513701a38b5405766face6
 eschen42 parents: 
4diff
changeset | 123 myLapply <<- function(cl, ...) lapply(...) | 
| 
6817b036b06e
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 511f1d2602aac662d3513701a38b5405766face6
 eschen42 parents: 
4diff
changeset | 124 } | 
| 
6817b036b06e
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 511f1d2602aac662d3513701a38b5405766face6
 eschen42 parents: 
4diff
changeset | 125 ) | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 126 if ( identical(myLapply, parLapply) ) { | 
| 5 
6817b036b06e
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 511f1d2602aac662d3513701a38b5405766face6
 eschen42 parents: 
4diff
changeset | 127 log_action(sprintf("w4mkmeans: using parallel evaluation with %d slots", slots)) | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 128 # from ?makePSOCKcluster: "It is good practice to shut down the workers by calling stopCluster." | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 129 # note varlist: names of references must be passed to the cluster so that they can be resolved | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 130 clusterExport( | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 131 cl = cl | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 132 , varlist = c( | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 133 "tryCatchFunc" # required by calc_kmeans_one_dimension_one_k | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 134 , "format_error" # required by tryCatchFunc when errors are caught | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 135 , "iso_date" # required by log_print | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 136 , "log_print" # required by calc_kmeans_one_dimension_one_k | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 137 ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 138 ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 139 final <- function(cl) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 140 # from ?makePSOCKcluster: "It is good practice to shut down the workers by calling stopCluster." | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 141 if ( !is.null(cl) ) { | 
| 5 
6817b036b06e
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 511f1d2602aac662d3513701a38b5405766face6
 eschen42 parents: 
4diff
changeset | 142 log_action("w4mkmeans: stopping cluster used for parallel evaluation") | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 143 stopCluster(cl) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 144 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 145 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 146 } else { | 
| 5 
6817b036b06e
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 511f1d2602aac662d3513701a38b5405766face6
 eschen42 parents: 
4diff
changeset | 147 log_action("w4mkmeans: using sequential evaluation (one slot)") | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 148 final <- function(cl) { } | 
| 
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 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 151 tryCatch( | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 152 expr = { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 153 # These myLapply calls produce lists of lists of results: | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 154 # - The outer list has no keys and its members are accessed by index | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 155 # - The inner list has keys "clusters" and "scores" | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 156 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 157 # for each $i in ksamples, append column 'k$i' to data frame sampleMetadata | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 158 ksamples_length <- length(ksamples) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 159 if ( ksamples_length > 0 ) { | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 160 smpl_result_list <- myLapply( | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 161 cl = cl | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 162 , ksamples | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 163 , calc_kmeans_one_dimension_one_k | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 164 , env = env | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 165 , dimension = "samples" | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 166 ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 167 for ( i in 1:ksamples_length ) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 168 result <- smpl_result_list[[i]] | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 169 if (result$success) { | 
| 4 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 170 sampleMetadata[sprintf("k%d",ksamples[i])] <- sprintf("%s%d", env$categorical_prefix, result$value$clusters) | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 171 scores <- c(scores, result$value$scores) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 172 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 173 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 174 } | 
| 
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 # for each $i in kfeatures, append column 'k$i' to data frame featureMetadata | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 177 kfeatures_length <- length(kfeatures) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 178 if ( kfeatures_length > 0 ) { | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 179 feat_result_list <- myLapply( | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 180 cl = cl | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 181 , kfeatures | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 182 , calc_kmeans_one_dimension_one_k | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 183 , env = env | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 184 , dimension = "features" | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 185 ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 186 for ( i in 1:kfeatures_length ) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 187 result <- feat_result_list[[i]] | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 188 if (result$success) { | 
| 4 
06385448ff7f
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit f600ce8a783df16e49272341dce0fc6bbc299b0a
 eschen42 parents: 
0diff
changeset | 189 featureMetadata[sprintf("k%d",kfeatures[i])] <- sprintf("%s%d", env$categorical_prefix, result$value$clusters) | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 190 scores <- c(scores, result$value$scores) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 191 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 192 } | 
| 
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 | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 195 return ( | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 196 list( | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 197 variableMetadata = featureMetadata | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 198 , sampleMetadata = sampleMetadata | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 199 , scores = scores | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 200 ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 201 ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 202 } | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 203 , finally = { | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 204 final(cl) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 205 } | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 206 ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 207 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 208 | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 209 # calculate k-means for features or samples | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 210 # - recall that the dataMatrix has features in rows and samples in columns | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 211 # return value: | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 212 # list(clusters = km$cluster, scores = scores) | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 213 # arguments: | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 214 # env: | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 215 # environment having dataMatrix | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 216 # dimension: | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 217 # - "samples": produce clusters column to add to the sampleMetadata table | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 218 # - this is the default case | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 219 # - "variables": produce clusters column to add to the variableMetadata table | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 220 # k: | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 221 # integer, the number of clusters to make | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 222 calc_kmeans_one_dimension_one_k <- function(k, env, dimension = "samples") { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 223 # abort if environment is not as expected | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 224 if ( is.null(env) || ! is.environment(env) ) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 225 stop("calc_kmeans_one_dimension_one_k - argument 'env' is not an environment") | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 226 } | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 227 if ( ! exists("log_print", env) || ! is.function(env$log_print) ) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 228 stop("calc_kmeans_one_dimension_one_k - argument 'env' - environment does not include log_print or it is not a function") | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 229 } | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 230 log_action <- env$log_print | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 231 # abort if k is not as expected | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 232 if ( ! is.numeric(k) ) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 233 stop(sprintf("calc_kmeans_one_dimension_one_k - expected numeric argument 'k' but type is %s", typeof(k))) | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 234 } | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 235 k <- as.integer(k) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 236 # abort if dimension is not as expected | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 237 if ( ! is.character(dimension) | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 238 || ! Reduce( f =`|`, x = sapply(X = c("features","samples"), FUN = `==`, dimension), init = FALSE) ) { | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 239 stop("calc_kmeans_one_dimension_one_k - argument 'dimension' is neither 'features' nor 'samples'") | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 240 } | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 241 dm <- env$preparedDataMatrix | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 242 iter_max <- env$iter_max | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 243 nstart <- env$nstart | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 244 algorithm <- env$algorithm | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 245 dim_features <- dimension == "features" | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 246 | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 247 # tryCatchFunc produces a list | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 248 # On success of func(), tryCatchFunc produces | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 249 # list(success = TRUE, value = func(), msg = "") | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 250 # On failure of func(), tryCatchFunc produces | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 251 # list(success = FALSE, value = NA, msg = "the error message") | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 252 result_list <- tryCatchFunc( func = function() { | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 253 # kmeans clusters the rows; features are the columns of args_env$dataMatrix; samples, the rows | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 254 # - to calculate sample-clusters, no transposition is needed because samples are rows | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 255 # - to calculate feature-clusters, transposition is needed so that features will be the rows | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 256 if ( ! dim_features ) { | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 257 dm <- t(dm) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 258 } | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 259 | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 260 # need to set.seed to get reproducible results from kmeans | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 261 set.seed(4567) | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 262 | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 263 # do the k-means clustering | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 264 withCallingHandlers( | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 265 { | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 266 km <<- kmeans( x = dm, centers = k, iter.max = iter_max, nstart = nstart, algorithm = algorithm ) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 267 } | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 268 , warning = function(w) { | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 269 lw <- list(w) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 270 smplwrn <- as.character(w[[1]]) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 271 log_print( | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 272 sprintf( "Warning for %s: center = %d, nstart = %d, iter_max = %d: %s" | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 273 , if (dim_features) "features" else "samples" | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 274 , k | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 275 , nstart | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 276 , iter_max | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 277 , smplwrn | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 278 ) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 279 ) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 280 } | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 281 ) | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 282 | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 283 # collect the scores | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 284 scores <- | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 285 sprintf("%s\t%d\t%0.5e\t%0.5e\t%0.5f" | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 286 , dimension | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 287 , k | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 288 , km$totss | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 289 , km$betweenss | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 290 , km$betweenss/km$totss | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 291 ) | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 292 | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 293 # return list of results | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 294 list(clusters = km$cluster, scores = scores) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 295 }) | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 296 | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 297 # return either | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 298 # list(success = TRUE, value = func(), msg = "") | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 299 # or | 
| 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 300 # list(success = FALSE, value = NA, msg = "the error message") | 
| 0 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 301 return ( result_list ) | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 302 } | 
| 
330ee1d840db
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit ae8ee04dc44eedf9121644ce8577c622da2a5f8c-dirty
 eschen42 parents: diff
changeset | 303 | 
| 6 
3f72a635a075
planemo upload for repository https://github.com/HegemanLab/w4mkmeans_galaxy_wrapper/tree/master commit 2799299a221358b648334c3f890c4024155af73b
 eschen42 parents: 
5diff
changeset | 304 # vim: sw=2 ts=2 et : | 
