-
Notifications
You must be signed in to change notification settings - Fork 21
/
commandLineTool.go
180 lines (148 loc) · 5.92 KB
/
commandLineTool.go
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package cwl
import (
//"errors"
"fmt"
"github.com/davecgh/go-spew/spew"
"github.com/mitchellh/mapstructure"
)
type CommandLineTool struct {
Id string `yaml:"id"`
BaseCommand string `yaml:"baseCommand"` // TODO also allow []string
Inputs []CommandInputParameter `yaml:"inputs"`
Outputs []CommandOutputParameter `yaml:"outputs"`
Hints []Requirement `yaml:"hints"` // TODO Any
Label string `yaml:"label"`
Description string `yaml:"description"`
CwlVersion CWLVersion `yaml:"cwlVersion"`
Arguments []string `yaml:"arguments"` // TODO support CommandLineBinding
Stdin string `yaml:"stdin"` // TODO support Expression
Stdout string `yaml:"stdout"` // TODO support Expression
SuccessCodes []int `yaml:"successCodes"`
TemporaryFailCodes []int `yaml:"temporaryFailCodes"`
PermanentFailCodes []int `yaml:"permanentFailCodes"`
}
func (c *CommandLineTool) GetClass() string { return "CommandLineTool" }
func (c *CommandLineTool) GetId() string { return c.Id }
func (c *CommandLineTool) SetId(id string) { c.Id = id }
type CommandInputParameter struct {
Id string `yaml:"id"`
SecondaryFiles []string `yaml:"secondaryFiles"` // TODO string | Expression | array<string | Expression>
Format string `yaml:"format"`
Streamable bool `yaml:"streamable"`
Type string `yaml:"type"` // TODO CWLType | CommandInputRecordSchema | CommandInputEnumSchema | CommandInputArraySchema | string | array<CWLType | CommandInputRecordSchema | CommandInputEnumSchema | CommandInputArraySchema | string>
Label string `yaml:"label"`
Description string `yaml:"description"`
InputBinding CommandLineBinding `yaml:"inputBinding"`
Default Any `yaml:"default"`
}
type CommandOutputParameter struct {
Id string `yaml:"id"`
SecondaryFiles []Expression `yaml:"secondaryFiles"` // TODO string | Expression | array<string | Expression>
Format string `yaml:"format"`
Streamable bool `yaml:"streamable"`
Type string `yaml:"type"` // TODO CWLType | CommandInputRecordSchema | CommandInputEnumSchema | CommandInputArraySchema | string | array<CWLType | CommandInputRecordSchema | CommandInputEnumSchema | CommandInputArraySchema | string>
Label string `yaml:"label"`
Description string `yaml:"description"`
OutputBinding CommandOutputBinding `yaml:"outputBinding"`
}
// keyname will be converted into 'Id'-field
func CreateCommandInputArray(original interface{}) (err error, new_array []CommandInputParameter) {
for k, v := range original.(map[interface{}]interface{}) {
var input_parameter CommandInputParameter
mapstructure.Decode(v, &input_parameter)
input_parameter.Id = k.(string)
//fmt.Printf("C")
new_array = append(new_array, input_parameter)
//fmt.Printf("D")
}
//spew.Dump(new_array)
return
}
func getGlob(object interface{}) (expressions []Expression, err error) {
for key_if, value_if := range object.(map[interface{}]interface{}) {
key_str, ok := key_if.(string)
if ok {
fmt.Printf("key_str: %s\n", key_str)
if key_str == "glob" {
switch value_if.(type) {
case string:
expression_str := value_if.(string)
expression := Expression(expression_str)
expressions = []Expression{expression}
case []string:
expressions = value_if.([]Expression)
default:
err = fmt.Errorf("cannot parse glob")
}
return
}
}
}
return
}
func getCommandOutputBinding(object interface{}) (outputBinding CommandOutputBinding, err error) {
// find "outputBinding" in object
for key_if, value_if := range object.(map[interface{}]interface{}) {
key_str, ok := key_if.(string)
if ok {
fmt.Printf("key_str: %s\n", key_str)
if key_str == "outputBinding" {
//var outputBinding CommandOutputBinding
mapstructure.Decode(value_if, &outputBinding)
//output_parameter.OutputBinding = outputBinding
outputBinding.Glob, err = getGlob(value_if)
return
}
} else {
fmt.Printf("not ok\n")
}
}
return
}
// keyname will be converted into 'Id'-field
func CreateCommandOutputArray(original interface{}) (err error, new_array []CommandOutputParameter) {
for id_if, output_parameter_if := range original.(map[interface{}]interface{}) {
fmt.Printf("AAAAAAAAA")
spew.Dump(output_parameter_if)
var output_parameter CommandOutputParameter
mapstructure.Decode(output_parameter_if, &output_parameter)
outputBinding, xerr := getCommandOutputBinding(output_parameter_if)
if xerr != nil {
err = xerr
return
}
output_parameter.OutputBinding = outputBinding
output_parameter.Id = id_if.(string)
spew.Dump(output_parameter)
new_array = append(new_array, output_parameter)
//fmt.Printf("D")
}
//spew.Dump(new_array)
return
}
func getCommandLineTool(object CWL_object_generic) (commandLineTool *CommandLineTool, err error) {
commandLineTool = &CommandLineTool{}
switch object["inputs"].(type) {
case map[interface{}]interface{}:
// Convert map of inputs into array of inputs
err, object["inputs"] = CreateCommandInputArray(object["inputs"])
if err != nil {
return
}
}
switch object["outputs"].(type) {
case map[interface{}]interface{}:
// Convert map of outputs into array of outputs
err, object["outputs"] = CreateCommandOutputArray(object["outputs"])
if err != nil {
return
}
}
err = mapstructure.Decode(object, commandLineTool)
if err != nil {
err = fmt.Errorf("error parsing CommandLineTool class: %s", err.Error())
return
}
//spew.Dump(commandLineTool)
return
}