Skip to content

Commit

Permalink
ColumnComponent: Exclude non-fastq files if no fastq are present (#742)
Browse files Browse the repository at this point in the history
* fix: Include non-fastq files if none are present

* chore: Fixed typo resulting in error

* chore: Don't render single files if no fastq are available

* chore: Ensure singles are only add if it is not pe only

* chore: Updated to use filter_files_by_pattern

* chore: Fixed parameters
  • Loading branch information
joshsadam authored Sep 11, 2024
1 parent 21c4f73 commit a6aa6c5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
46 changes: 33 additions & 13 deletions app/components/nextflow/samplesheet/column_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,41 @@ def render_cell_type(property, entry, sample, fields, index) # rubocop:disable M
end

def render_fastq_cell(sample, property, entry, fields, index)
direction = property.match(/fastq_(\d+)/)[1].to_i == 1 ? :pe_forward : :pe_reverse
files = sample.sorted_files[direction] || []
data = {}
if files.empty? && property != 'fastq_2'
files = sample.sorted_files[:singles] || []
direction = get_fastq_direction(property)
files = get_fastq_files(entry, sample, direction, pe_only: property['pe_only'].present?)
data = get_fastq_data(files, direction, index, property)
render_file_cell(property, entry, fields, files, @required, data, files&.first)
end

private

def get_fastq_direction(property)
property.match(/fastq_(\d+)/)[1].to_i == 1 ? :pe_forward : :pe_reverse
end

def get_fastq_files(entry, sample, direction, pe_only: false)
singles = filter_files_by_pattern(sample.sorted_files[:singles] || [],
entry['pattern'] || "/^\S+.f(ast)?q(.gz)?$/")

files = []
if sample.sorted_files[direction].present?
files = sample.sorted_files[direction] || []
files.concat(singles) unless pe_only
else
data = {
'data-action' => 'change->nextflow--samplesheet#file_selected',
'data-nextflow--samplesheet-target' => "select#{direction.to_s.sub!('pe_', '').capitalize}",
'data-direction' => direction.to_s,
'data-index' => index
}
files = singles
end
render_file_cell(property, entry, fields, files,
@required, data, files.nil? ? nil : files.first)
files
end

def get_fastq_data(files, direction, index, property)
return {} if files.empty? && property == 'fastq_2'

{
'data-action' => 'change->nextflow--samplesheet#file_selected',
'data-nextflow--samplesheet-target' => "select#{direction.to_s.sub!('pe_', '').capitalize}",
'data-direction' => direction.to_s,
'data-index' => index
}
end

def render_other_file_cell(sample, property, entry, fields)
Expand Down
4 changes: 4 additions & 0 deletions app/components/nextflow/samplesheet_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def extract_properties(schema)
@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

Expand Down

0 comments on commit a6aa6c5

Please sign in to comment.