From 5b1c663f99b04157f8b4fac1cc42343a49088128 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sun, 21 Mar 2021 16:10:14 +0530 Subject: Use both CWL arguments and inputs arrays. * ccwl/ccwl.scm (): New type. (command->cwl): Put string and expression arguments into the arguments array. Put arguments into the inputs array. --- ccwl/ccwl.scm | 79 +++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 61 insertions(+), 18 deletions(-) diff --git a/ccwl/ccwl.scm b/ccwl/ccwl.scm index be99eb6..8cc35b3 100644 --- a/ccwl/ccwl.scm +++ b/ccwl/ccwl.scm @@ -253,25 +253,68 @@ re-matched." (cons 'output-binding (output-binding output))))) ,@(output-other output))) +(define-immutable-record-type + (make-cli-element argument position) + cli-element? + (argument cli-element-argument) + (position cli-element-position)) + (define (command->cwl command) - `((cwl-version . ,%cwl-version) - (class . Command-line-tool) - ,@(command-other command) - (arguments . ,(list->vector (map (lambda (arg) - (if (input? arg) - (string-append "$(inputs." (input-id arg) ")") - arg)) - (command-args command)))) - (inputs . ,(map input->tree (append (command-inputs command) - (if (command-stdin command) - (list (command-stdin command)) - (list))))) - (outputs . ,(map output->cwl (command-outputs command))) - ,@(if (command-stdin command) - `((stdin . ,(string-append "$(inputs." - (input-id (command-stdin command)) - ".path)"))) - '()))) + (let ((elements + ;; Add a position to all arguments, converting them to + ;; objects. + (map (lambda (arg position) + (make-cli-element + ;; If duplicate input, convert it to an expression + ;; referring to the input. + (if (and (input? arg) + (not (= (list-index (lambda (x) + (and (input? x) + (input=? arg x))) + (command-args command)) + position))) + (string-append "$(inputs." (input-id arg) ")") + arg) + position)) + (command-args command) + (iota (length (command-args command)))))) + `((cwl-version . ,%cwl-version) + (class . Command-line-tool) + ,@(command-other command) + (arguments . ,(list->vector + ;; Put string arguments into the arguments array. + (filter-map (lambda (element) + (and (string? (cli-element-argument element)) + `((position . ,(cli-element-position element)) + (value-from . ,(cli-element-argument element))))) + elements))) + (inputs . ,(append + ;; Put arguments into the inputs array. + (filter-map (lambda (element) + (let ((input (cli-element-argument element))) + (and (input? input) + `(,(input-id input) + ,@(filter-alist + `((type . ,(input-type input)) + (label . ,(input-label input)) + (default . ,(and (not (unspecified-default? (input-default input))) + (input-default input))) + (input-binding . ,(filter-alist + `((position . ,(cli-element-position element)) + (prefix . ,(input-prefix input))))))) + ,@(input-other input))))) + elements) + (let ((stdin (command-stdin command))) + (if stdin + (list `(,(input-id stdin) + (type . ,(input-type stdin)))) + (list))))) + (outputs . ,(map output->cwl (command-outputs command))) + ,@(if (command-stdin command) + `((stdin . ,(string-append "$(inputs." + (input-id (command-stdin command)) + ".path)"))) + '())))) (define (write-cwl step file) (call-with-output-file file -- cgit v1.2.3