-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsamplesheet_component.rb
70 lines (51 loc) · 2.22 KB
/
samplesheet_component.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
# frozen_string_literal: true
module Nextflow
# Render the contents of a Nextflow samplesheet to a table
class SamplesheetComponent < Component
attr_reader :properties, :samples, :required_properties, :metadata_fields, :namespace_id, :workflow_params
FILE_CELL_TYPES = %w[fastq_cell file_cell].freeze
def initialize(schema:, samples:, fields:, namespace_id:, workflow_params:)
@samples = samples
@namespace_id = namespace_id
@metadata_fields = fields
@required_properties = schema['items']['required'] || []
@workflow_params = workflow_params
extract_properties(schema)
end
private
def extract_properties(schema)
@properties = schema['items']['properties']
@properties.each do |property, entry|
@properties[property]['required'] = schema['items']['required'].include?(property)
@properties[property]['cell_type'] = identify_cell_type(property, entry)
end
if @required_properties.include?('fastq_1') && @required_properties.include?('fastq_2')
@properties['fastq_1']['pe_only'] = true
end
identify_autopopulated_file_properties
end
def identify_cell_type(property, entry)
return 'sample_cell' if property == 'sample'
return 'sample_name_cell' if property == 'sample_name'
return 'fastq_cell' if property.match(/fastq_\d+/)
return 'file_cell' if check_for_file(entry)
return 'metadata_cell' if entry['meta'].present?
return 'dropdown_cell' if entry['enum'].present?
'input_cell'
end
def check_for_file(entry)
entry['format'] == 'file-path' || (entry.key?('anyOf') && entry['anyOf'].any? do |e|
e['format'] == 'file-path'
end)
end
def identify_autopopulated_file_properties
file_properties = @properties.select { |_property, entry| FILE_CELL_TYPES.include?(entry['cell_type']) }
required_file_properties = file_properties.select { |_property, entry| entry['required'] }
file_properties.each_key do |property|
next unless required_file_properties.key?(property) ||
(required_file_properties.empty? && property == 'fastq_1')
@properties[property]['autopopulate'] = true
end
end
end
end