Mercurial > repos > eschen42 > w4mclassfilter
annotate w4mclassfilter_wrapper.R @ 8:22a08e1dc675 draft
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7-dirty
| author | eschen42 |
|---|---|
| date | Fri, 12 Jan 2018 04:09:38 -0500 |
| parents | f1eabb5973b1 |
| children | 518cc205f289 |
| rev | line source |
|---|---|
| 0 | 1 #!/usr/bin/env Rscript |
| 2 | |
| 3 library(batch) ## parseCommandArgs | |
| 4 | |
| 5 ######## | |
| 6 # MAIN # | |
| 7 ######## | |
| 8 | |
| 9 argVc <- unlist(parseCommandArgs(evaluate=FALSE)) | |
| 10 | |
| 11 ##------------------------------ | |
| 12 ## Initializing | |
| 13 ##------------------------------ | |
| 14 | |
| 15 ## options | |
| 16 ##-------- | |
| 17 | |
| 18 strAsFacL <- options()$stringsAsFactors | |
| 19 options(stringsAsFactors = FALSE) | |
| 20 | |
| 21 ## libraries | |
| 22 ##---------- | |
| 23 | |
| 24 suppressMessages(library(w4mclassfilter)) | |
| 25 | |
| 26 if(packageVersion("w4mclassfilter") < "0.98.0") | |
| 27 stop("Please use 'w4mclassfilter' versions of 0.98.0 and above") | |
| 28 | |
| 29 ## constants | |
| 30 ##---------- | |
| 31 | |
| 32 modNamC <- "w4mclassfilter" ## module name | |
| 33 | |
| 34 topEnvC <- environment() | |
| 35 flgC <- "\n" | |
| 36 | |
| 37 ## functions | |
| 38 ##---------- | |
| 39 | |
| 40 flgF <- function(tesC, | |
| 41 envC = topEnvC, | |
| 42 txtC = NA) { ## management of warning and error messages | |
| 43 | |
| 44 tesL <- eval(parse(text = tesC), envir = envC) | |
| 45 | |
| 46 if(!tesL) { | |
| 47 | |
| 48 #sink(NULL) | |
| 49 stpTxtC <- ifelse(is.na(txtC), | |
| 50 paste0(tesC, " is FALSE"), | |
| 51 txtC) | |
| 52 | |
| 53 stop(stpTxtC, | |
| 54 call. = FALSE) | |
| 55 | |
| 56 } | |
| 57 | |
| 58 } ## flgF | |
| 59 | |
| 60 | |
| 61 ## log file | |
| 62 ##--------- | |
| 63 | |
| 64 my_print <- function(x, ...) { cat(c(x, ...))} | |
| 65 | |
| 66 my_print("\nStart of the '", modNamC, "' Galaxy module call: ", | |
| 67 format(Sys.time(), "%a %d %b %Y %X"), "\n", sep="") | |
| 68 | |
| 69 ## arguments | |
| 70 ##---------- | |
| 71 | |
| 72 # files | |
| 73 | |
| 74 dataMatrix_in <- as.character(argVc["dataMatrix_in"]) | |
| 75 dataMatrix_out <- as.character(argVc["dataMatrix_out"]) | |
| 76 | |
| 77 sampleMetadata_in <- as.character(argVc["sampleMetadata_in"]) | |
| 78 sampleMetadata_out <- as.character(argVc["sampleMetadata_out"]) | |
| 79 | |
| 80 variableMetadata_in <- as.character(argVc["variableMetadata_in"]) | |
| 81 variableMetadata_out <- as.character(argVc["variableMetadata_out"]) | |
| 82 | |
| 83 # other parameters | |
| 84 | |
|
6
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
85 wildcards <- as.logical(argVc["wildcards"]) |
| 0 | 86 sampleclassNames <- as.character(argVc["sampleclassNames"]) |
| 87 sampleclassNames <- strsplit(x = sampleclassNames, split = ",", fixed = TRUE)[[1]] | |
|
5
ae791fe4fbe9
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit a2d17eac4a1343a34cf2908d9ab31b3202a21f64
eschen42
parents:
1
diff
changeset
|
88 if (wildcards) { |
|
ae791fe4fbe9
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit a2d17eac4a1343a34cf2908d9ab31b3202a21f64
eschen42
parents:
1
diff
changeset
|
89 sampleclassNames <- gsub("[.]", "[.]", sampleclassNames) |
|
ae791fe4fbe9
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit a2d17eac4a1343a34cf2908d9ab31b3202a21f64
eschen42
parents:
1
diff
changeset
|
90 sampleclassNames <- utils::glob2rx(sampleclassNames, trim.tail = FALSE) |
|
ae791fe4fbe9
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit a2d17eac4a1343a34cf2908d9ab31b3202a21f64
eschen42
parents:
1
diff
changeset
|
91 } |
| 0 | 92 inclusive <- as.logical(argVc["inclusive"]) |
| 93 classnameColumn <- as.character(argVc["classnameColumn"]) | |
| 94 samplenameColumn <- as.character(argVc["samplenameColumn"]) | |
| 95 | |
|
6
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
96 variable_range_filter <- as.character(argVc["variable_range_filter"]) |
|
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
97 variable_range_filter <- strsplit(x = variable_range_filter, split = ",", fixed = TRUE)[[1]] |
|
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
98 |
| 0 | 99 ##------------------------------ |
| 100 ## Computation | |
| 101 ##------------------------------ | |
| 102 | |
| 103 result <- w4m_filter_by_sample_class( | |
|
6
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
104 dataMatrix_in = dataMatrix_in |
|
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
105 , sampleMetadata_in = sampleMetadata_in |
|
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
106 , variableMetadata_in = variableMetadata_in |
|
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
107 , dataMatrix_out = dataMatrix_out |
|
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
108 , sampleMetadata_out = sampleMetadata_out |
|
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
109 , variableMetadata_out = variableMetadata_out |
|
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
110 , classes = sampleclassNames |
|
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
111 , include = inclusive |
|
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
112 , class_column = classnameColumn |
|
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
113 , samplename_column = samplenameColumn |
|
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
114 , variable_range_filter = variable_range_filter |
|
f1eabb5973b1
planemo upload for repository https://github.com/HegemanLab/w4mclassfilter_galaxy_wrapper/tree/master commit 08a878ac05ac0c05eafac27b9ebaadb88ae21eb7
eschen42
parents:
5
diff
changeset
|
115 , failure_action = my_print |
| 0 | 116 ) |
| 117 | |
| 118 my_print("\nResult of '", modNamC, "' Galaxy module call to 'w4mclassfilter::w4m_filter_by_sample_class' R function: ", | |
| 119 as.character(result), "\n", sep = "") | |
| 120 | |
| 121 ##-------- | |
| 122 ## Closing | |
| 123 ##-------- | |
| 124 | |
| 125 my_print("\nEnd of '", modNamC, "' Galaxy module call: ", | |
| 126 as.character(Sys.time()), "\n", sep = "") | |
| 127 | |
| 128 #sink() | |
| 129 | |
| 130 if (!file.exists(dataMatrix_out)) { | |
| 131 print(sprintf("ERROR %s::w4m_filter_by_sample_class - file '%s' was not created", modNamC, dataMatrix_out)) | |
| 132 }# else { print(sprintf("INFO %s::w4m_filter_by_sample_class - file '%s' was exists", modNamC, dataMatrix_out)) } | |
| 133 | |
| 134 if (!file.exists(variableMetadata_out)) { | |
| 135 print(sprintf("ERROR %s::w4m_filter_by_sample_class - file '%s' was not created", modNamC, variableMetadata_out)) | |
| 136 } # else { print(sprintf("INFO %s::w4m_filter_by_sample_class - file '%s' was exists", modNamC, variableMetadata_out)) } | |
| 137 | |
| 138 if (!file.exists(sampleMetadata_out)) { | |
| 139 print(sprintf("ERROR %s::w4m_filter_by_sample_class - file '%s' was not created", modNamC, sampleMetadata_out)) | |
| 140 } # else { print(sprintf("INFO %s::w4m_filter_by_sample_class - file '%s' was exists", modNamC, sampleMetadata_out)) } | |
| 141 | |
| 142 if( !result ) { | |
| 143 stop(sprintf("ERROR %s::w4m_filter_by_sample_class - method failed", modNamC)) | |
| 144 } | |
| 145 | |
| 146 rm(list = ls()) |
