-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcwl.js
92 lines (81 loc) · 2.42 KB
/
cwl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* Created by porter on 11/15/15.
*/
var YAML = require('js-yaml');
var TYPE_FLOAT = /\bfloat\b/gi;
var TYPE_INT = /\binteger\b|\bint\b/gi;
var TYPE_STRING = /\bstring\b|\bstr\b|\btext\b/gi;
var TYPE_FILE = /\bFILE\b|\(file\)|\<file\>/g;
function input(arg) {
var type = "boolean";
var isOptional = true;
var position = 1;
if (arg.isOptional !== undefined)
isOptional = arg.isOptional;
if (arg.position !== undefined)
position = arg.position;
if (arg.type !== undefined) {
type = arg.type;
} else {
if (TYPE_FLOAT.test(arg.descr))
type = "float";
else if (TYPE_INT.test(arg.descr))
type = "int";
else if (TYPE_STRING.test(arg.descr))
type = "string";
else if (TYPE_FILE.test(arg.descr))
type = "File";
}
TYPE_INT.lastIndex = 0;
TYPE_FLOAT.lastIndex = 0;
TYPE_STRING.lastIndex = 0;
var inp = {
"id": "" + arg.arg.replace(/^[-]{1,2}/g, ''),
"type": isOptional ? ["null", type] : type,
"description": arg.descr
};
if(arg.inputB === undefined || arg.inputB ) {
inp["inputBinding"]= {
"position": position
};
if(arg.prefix === undefined || arg.prefix ) {
inp["inputBinding"]["prefix"] = arg.arg;
}
}
return inp;
}
function CWL(parsed) {
var cwl = {
"cwlVersion": "cwl:draft-3.dev3",
"class": "CommandLineTool",
"requirements": [
{"$import": "envvar-global.cwl" },
{"$import": parsed.command + "-docker.cwl" },
{"class": "InlineJavascriptRequirement" }
],
"inputs": [
{"id": "#stdoutfilename", "type": "string"}
],
"outputs": [
{
"id": "#stdoutfile",
"type": "File",
"outputBinding": {
"glob": "$(inputs.stdoutfilename)"
}
}],
"stdout": "$(inputs.stdoutfilename)",
"baseCommand": [parsed.command].concat(parsed.c_args.filter(function (v) {
return !(/(^[\-]{0,2}[Hh]$)|(^[\-]{0,2}[Hh]elp$)/g).test(v);
})),
"description": parsed.help.trim()
};
var i = 0;
while (parsed.args && parsed.args.length > i) {
var arg = parsed.args[i];
cwl['inputs'].push(input(arg));
i++;
}
return YAML.dump(cwl, 2);
}
module.exports = CWL;