aboutsummaryrefslogtreecommitdiff
path: root/ccwl/cwl.scm
diff options
context:
space:
mode:
authorArun Isaac2021-10-11 14:40:42 +0530
committerArun Isaac2021-10-11 14:51:22 +0530
commit9a354d0b99da83f60ab68f0151d6f0d5488b7a93 (patch)
treeac2f78e964c2690f8924446dbd0c487b66df4ddb /ccwl/cwl.scm
parentb741170945ed35552524f809e1fe51a09e6f6b75 (diff)
downloadccwl-9a354d0b99da83f60ab68f0151d6f0d5488b7a93.tar.gz
ccwl-9a354d0b99da83f60ab68f0151d6f0d5488b7a93.tar.lz
ccwl-9a354d0b99da83f60ab68f0151d6f0d5488b7a93.zip
ccwl: Factorize out CWL generation code to separate file.
This factorization is required to support other compilation targets such as graphviz, bash, scheme, etc. * ccwl/cwl.scm: New file. * Makefile.am (SOURCES): Register it. * ccwl/ccwl.scm (ccwl): Export command?, command-inputs, command-outputs, command-args, command-stdin, command-other, workflow?, workflow-steps, workflow-inputs, workflow-outputs, workflow-other, input?, input-id, input-type, input-label, input-default, input-position, input-prefix, input-other, output?, output-id, output-type, output-binding, output-source, output-other, step?, step-id, step-run, step-in, step-out, unspecified-default?. (<workflow>): New type. (filter-alist): Move to cwl.scm. (make-workflow): Refactor into workflow->cwl-scm in cwl.scm. (output->cwl): Move to cwl.scm as output->cwl-scm. (command->cwl): Move to cwl.scm as command->cwl-scm. (workflow-steps): Rename to collect-steps. Clarify docstring. (workflow): Use collect-steps instead of workflow-steps. Explicitly pass empty list as other argument of make-workflow. Add TODO note to implement it properly. * scripts/ccwl.in: Import (ccwl cwl) instead of (ccwl yaml). Use workflow->cwl instead of scm->yaml. * tests/ccwl.scm ("stdin input should not have inputBinding"): Use command->cwl-scm from (ccwl cwl) instead of command->cwl from (ccwl ccwl).
Diffstat (limited to 'ccwl/cwl.scm')
-rw-r--r--ccwl/cwl.scm132
1 files changed, 132 insertions, 0 deletions
diff --git a/ccwl/cwl.scm b/ccwl/cwl.scm
new file mode 100644
index 0000000..47b30da
--- /dev/null
+++ b/ccwl/cwl.scm
@@ -0,0 +1,132 @@
+;;; ccwl --- Concise Common Workflow Language
+;;; Copyright © 2021 Arun Isaac <arunisaac@systemreboot.net>
+;;;
+;;; This file is part of ccwl.
+;;;
+;;; ccwl is free software: you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation, either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; ccwl is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;;; General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with ccwl. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This file implements conversion from ccwl objects (<workflow>,
+;; <command>, <input>, <output>, <step>) to CWL YAML.
+
+;;; Code:
+
+(define-module (ccwl cwl)
+ #:use-module (ice-9 match)
+ #:use-module (ccwl ccwl)
+ #:use-module (ccwl utils)
+ #:use-module (ccwl yaml)
+ #:export (workflow->cwl))
+
+(define %cwl-version "v1.2")
+
+(define (workflow->cwl workflow port)
+ "Render WORKFLOW, a <workflow> object, to PORT as a CWL YAML
+specification."
+ (scm->yaml (workflow->cwl-scm workflow)
+ port))
+
+(define (filter-alist alist)
+ "Filter ALIST removing entries with #f as the value. If the
+resulting association list is empty, return #f. Else, return that
+association list."
+ (match (filter (match-lambda
+ ((_ . #f) #f)
+ (_ #t))
+ alist)
+ (() #f)
+ (result result)))
+
+(define* (workflow->cwl-scm workflow)
+ "Render WORKFLOW, a <workflow> object, into a CWL tree."
+ `((cwlVersion . ,%cwl-version)
+ (class . Workflow)
+ (requirements (SubworkflowFeatureRequirement))
+ ,@(workflow-other workflow)
+ (inputs . ,(map (lambda (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-other input)))
+ (workflow-inputs workflow)))
+ (outputs . ,(map (lambda (output)
+ `(,(output-id output)
+ (type . ,(match (output-type output)
+ ('stdout 'File)
+ (some-other-type some-other-type)))
+ (outputSource . ,(match (output-source output)
+ ((? string? source) source)
+ ((? input? input) (input-id input))))))
+ (workflow-outputs workflow)))
+ (steps . ,(map (lambda (step)
+ `(,(step-id step)
+ (in . ,(map (lambda (in)
+ (match in
+ ((id . (? string? source))
+ in)
+ ((id . (? input? input))
+ (cons id (input-id input)))))
+ (step-in step)))
+ (out . ,(list->vector (map output-id (step-out step))))
+ (run . ,(match (step-run step)
+ ((? command? command)
+ (command->cwl-scm command))
+ (tree tree)))))
+ (workflow-steps workflow)))))
+
+(define (output->cwl-scm output)
+ "Render OUTPUT, a <output> object, into a CWL tree."
+ `(,(output-id output)
+ ,@(filter identity
+ (list (and (output-type output)
+ (cons 'type (output-type output)))
+ (and (output-binding output)
+ (cons 'outputBinding (output-binding output)))))
+ ,@(output-other output)))
+
+(define (command->cwl-scm command)
+ "Render COMMAND, a <command> object, into a CWL tree."
+ `((cwlVersion . ,%cwl-version)
+ (class . CommandLineTool)
+ ,@(command-other command)
+ (arguments . ,(list->vector
+ ;; Put string arguments into the arguments array.
+ (filter-mapi (lambda (arg index)
+ (and (string? arg)
+ `((position . ,index)
+ (valueFrom . ,arg))))
+ (command-args command))))
+ (inputs . ,(map (lambda (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)))
+ (inputBinding . ,(filter-alist
+ `((position . ,(input-position input))
+ (prefix . ,(input-prefix input)))))))
+ ,@(input-other input)))
+ (command-inputs command)))
+ (outputs . ,(map output->cwl-scm (command-outputs command)))
+ ,@(if (command-stdin command)
+ `((stdin . ,(string-append "$(inputs."
+ (symbol->string
+ (command-stdin command))
+ ".path)")))
+ '())))