-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpipeline.rb
103 lines (78 loc) · 3.08 KB
/
pipeline.rb
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
# frozen_string_literal: true
module Irida
# Class to store pipeline values
class Pipeline
attr_accessor :name, :description, :metadata, :type, :type_version,
:engine, :engine_version, :url, :version, :schema_loc, :schema_input_loc, :automatable, :executable
IGNORED_PARAMS = %w[outdir email].freeze
def initialize(entry, version, schema_loc, schema_input_loc)
@name = entry['name']
@description = entry['description']
@metadata = { workflow_name: name, workflow_version: version }
@type = 'NFL'
@type_version = 'DSL2'
@engine = 'nextflow'
@engine_version = '23.10.0'
@url = entry['url']
@version = version['name']
@schema_loc = schema_loc
@schema_input_loc = schema_input_loc
@automatable = version['automatable'] || false
@executable = true unless version['executable'] == false
@overrides = overrides_for_entry(entry)
end
def workflow_params
nextflow_schema = JSON.parse(schema_loc.read)
workflow_params = {}
definitions = nextflow_schema['definitions'].deep_merge(@overrides['definitions'] || {})
definitions.each do |key, definition|
next unless show_section?(definition['properties'])
key = key.to_sym
workflow_params[key] = { title: definition['title'], description: definition['description'], properties: {} }
workflow_params[key][:properties] = process_section(key, definition['properties'], definition['required'])
end
workflow_params
end
def samplesheet_headers
sample_sheet = process_samplesheet_schema
sample_sheet['items']['properties'].keys
end
def property_pattern(property_name)
sample_sheet = process_samplesheet_schema
sample_sheet['items']['properties'][property_name]['pattern']
end
private
def process_section(key, properties, required)
processed_section = {}
properties.each do |name, property|
next unless !property['hidden'] && IGNORED_PARAMS.exclude?(name)
name = name.to_sym
processed_section[name] = process_property(key, name, property, required.present? && required.include?(name))
end
processed_section
end
def process_property(key, name, property, required)
processed_property = property.clone.deep_symbolize_keys
processed_property[:required] = required
processed_property[:schema] = process_samplesheet_schema if key == :input_output_options && name == :input
processed_property
end
def process_samplesheet_schema
JSON.parse(schema_input_loc.read)
end
def show_section?(properties)
properties.values.any? { |property| !property.key?('hidden') }
end
def overrides_for_entry(entry)
return {} if entry['versions'].nil?
overrides = entry['overrides'] || {}
version_overrides = entry['versions'].find do |version|
version['name'] == @version
end || {}
overrides
.deep_merge(
version_overrides.key?('overrides') ? version_overrides['overrides'] : {}
)
end
end
end