Mercurial > repos > ecology > otb_band_math
annotate OTB_BandMath.R @ 0:0ed34e3202b9 draft
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
author | ecology |
---|---|
date | Tue, 12 Mar 2024 12:39:59 +0000 |
parents | |
children | d266345e510d |
rev | line source |
---|---|
0
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
1 #Run with Rscript ./OTB_BandMath.R --file otb_band_math_test_input.txt --processingMemory 256 --mathExpression im1b3,im1b2,im1b1 --outputType png --outputFormat download --outputImage float --outputData otb_band_math_test_output.png |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
2 |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
3 library("httr2") |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
4 library("jsonlite") |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
5 library("getopt") |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
6 |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
7 args <- commandArgs(trailingOnly = TRUE) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
8 option_specification <- matrix(c( |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
9 'file', 'i1', 1, 'character', |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
10 'processingMemory', 'i2', 2, 'integer', |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
11 'mathExpression', 'i3', 2, 'character', |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
12 'outputType', 'i4', 2, 'character', |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
13 'outputFormat', 'i5', 1, 'character', |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
14 'outputImage', 'i6', 1, 'character', |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
15 'outputData', 'o', 1, 'character' |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
16 ), byrow = TRUE, ncol = 4) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
17 options <- getopt(option_specification) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
18 |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
19 file <- options$file |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
20 processingMemory <- options$processingMemory |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
21 mathExpression <-options$mathExpression |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
22 outputType <- paste0("image/", options$outputType) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
23 outputFormat <- options$outputFormat |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
24 outputImage <- options$outputImage |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
25 outputData <- options$outputData |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
26 |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
27 cat("\n file: ", file) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
28 cat("\n ram: ", processingMemory) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
29 cat("\n exp: ", mathExpression) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
30 cat("\n outputType: ", outputType) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
31 cat("\n outputFormat: ", outputFormat) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
32 cat("\n outputImage: ", outputImage) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
33 |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
34 baseUrl <- "https://ospd.geolabs.fr:8300/ogc-api/" |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
35 execute <- "processes/OTB.BandMath/execution" |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
36 getStatus <- "jobs/" |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
37 getResult <- "/results" |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
38 |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
39 file_urls <- readLines(file, warn = FALSE) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
40 |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
41 il_list <- lapply(file_urls, function(url) { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
42 list("href" = url) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
43 }) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
44 |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
45 json_data <- list( |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
46 "inputs" = list( |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
47 "il" = il_list, |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
48 "out" = outputImage, |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
49 "exp" = mathExpression, |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
50 "ram" = processingMemory |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
51 ), |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
52 "outputs" = list( |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
53 "out" = list( |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
54 "format" = list( |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
55 "mediaType" = outputType |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
56 ), |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
57 "transmissionMode" = "reference" |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
58 ) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
59 ) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
60 ) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
61 |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
62 makeResponseBodyReadable <- function(body) { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
63 hex <- c(body) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
64 int_values <- as.integer(hex) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
65 raw_vector <- as.raw(int_values) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
66 readable_output <- rawToChar(raw_vector) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
67 json_object <- jsonlite::fromJSON(readable_output) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
68 return(json_object) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
69 } |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
70 |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
71 tryCatch({ |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
72 #Request 1 |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
73 resp1 <- request(paste0(baseUrl, execute)) %>% |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
74 req_headers( |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
75 'accept' = '/*', |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
76 'Prefer' = 'respond-async;return=representation', |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
77 'Content-Type' = 'application/json' |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
78 ) %>% |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
79 req_body_json(json_data) %>% |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
80 req_perform() |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
81 |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
82 response <- makeResponseBodyReadable(resp1$body) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
83 status_code1 <- resp1$status_code |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
84 |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
85 if (status_code1 == 201) { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
86 status <- "running" |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
87 attempt = 1 |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
88 while (status == "running") { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
89 #Request 2 |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
90 #cat("\n",response$jobID) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
91 resp2 <- request(paste0(baseUrl,getStatus,response$jobID)) %>% |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
92 req_headers( |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
93 'accept' = 'application/json' |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
94 ) %>% |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
95 req_perform() |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
96 status_code2 <- resp2$status_code |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
97 #cat("\n", status_code2) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
98 if (status_code2 == 200) { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
99 response2 <- makeResponseBodyReadable(resp2$body) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
100 cat("\n", response2$status) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
101 if (response2$status=="successful") { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
102 status <- "successful" |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
103 #Request 3 |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
104 resp3 <- request(paste0(baseUrl,getStatus, response2$jobID, getResult)) %>% |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
105 req_headers( |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
106 'accept' = 'application/json' |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
107 ) %>% |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
108 req_perform() |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
109 status_code3 <- resp3$status_code |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
110 if (status_code3 == 200) { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
111 response3 <- makeResponseBodyReadable(resp3$body) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
112 if (outputFormat == "download") { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
113 options(timeout=300) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
114 download.file(response3$out$href, destfile = outputData, mode = "wb") |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
115 } else if (outputFormat == "getUrl") { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
116 writeLines(response3$out$href, con = outputData) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
117 } |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
118 } else if (status_code3 == 404) { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
119 print("The requested URI was not found.") |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
120 } else if (status_code3 == 500) { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
121 print("A server error occurred.") |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
122 } else { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
123 print(paste("HTTP", status_code3, "Error:", resp3$status_message)) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
124 } |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
125 } else if (response2$status=="failed") { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
126 status <- "failed" |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
127 } |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
128 #else { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
129 # attempt <- attempt +1 |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
130 # if (attempt == 200) { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
131 # status <- "failed" |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
132 # } |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
133 #} |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
134 } else { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
135 status <- "failed" |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
136 print(paste("HTTP", status_code2, "Error:", resp2$status_message)) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
137 } |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
138 Sys.sleep(3) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
139 } |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
140 print(status) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
141 } else if (status_code1 == 400) { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
142 print("A query parameter has an invalid value.") |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
143 } else if (status_code1 == 404) { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
144 print("The requested URI was not found.") |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
145 } else if (status_code1 == 500) { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
146 print("The requested URI was not found.") |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
147 } else { |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
148 print(paste("HTTP", status_code1, "Error:", resp1$status_message)) |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
149 } |
0ed34e3202b9
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/OtbBandMath commit d85a00bfd9f603fd25ad0fc93736d0b1e395fe25
ecology
parents:
diff
changeset
|
150 }) |