Skip to content

Commit

Permalink
Fix: Nextflow Samplesheet File Cell Pattern Recognition (#965)
Browse files Browse the repository at this point in the history
* chore: update samplesheet_component to merge patterns when anyOf is present

* chore: fix file selection for fastq_NUM cells
  • Loading branch information
ericenns authored Feb 26, 2025
1 parent 44f0614 commit f046e69
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
15 changes: 13 additions & 2 deletions app/components/nextflow/samplesheet_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ def sample_samplesheet_params(sample) # rubocop:disable Metrics/CyclomaticComple
end
end

def expected_pattern(entry)
if entry.key?('pattern')
entry['pattern']
elsif entry.key?('anyOf')
entry['anyOf'].select do |condition|
condition.key?('pattern')
end.pluck('pattern').join('|')
end
end

def file_samplesheet_values(file)
{ form_value: file.empty? ? '' : file[:global_id],
filename: file.empty? ? I18n.t('nextflow.samplesheet.file_cell_component.no_selected_file') : file[:filename],
Expand All @@ -64,11 +74,12 @@ def metadata_samplesheet_values(sample, name)
{ form_value: metadata.empty? ? '' : metadata }
end

def extract_properties(schema)
def extract_properties(schema) # rubocop:disable Metrics/AbcSize
@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)
@properties[property]['pattern'] = expected_pattern(entry)
end

if @required_properties.include?('fastq_1') && @required_properties.include?('fastq_2')
Expand All @@ -83,7 +94,7 @@ def identify_cell_type(property, entry)

return 'sample_name_cell' if property == 'sample_name'

return 'fastq_cell' if property.match(/fastq_\d+/)
return 'fastq_cell' if property.match(/^fastq_\d+$/)

return 'file_cell' if check_for_file(entry)

Expand Down
23 changes: 14 additions & 9 deletions app/models/concerns/file_selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,9 @@ def sort_files # rubocop:disable Metrics/MethodLength
def samplesheet_fastq_files(property, pattern)
direction = fastq_direction(property)
singles = filter_files_by_pattern(sorted_files[:singles] || [], pattern || "/^\S+.f(ast)?q(.gz)?$/")
files = []
if sorted_files[direction].present?
files = sorted_files[direction] || []
files.concat(singles) if property['pe_only'].blank?
else
files = singles
end
files = sorted_files.fetch(direction, [])

files.concat(singles) if (direction == :pe_forward && property['pe_only'].blank?) || direction == :none
(files.sort_by! { |file| file[:created_at] }).reverse
end

Expand All @@ -58,9 +54,11 @@ def most_recent_fastq_file(property, pattern)

if sorted_files[direction].present?
sorted_files[direction].last
else
elsif %i[pe_forward none].include?(direction)
last_single = filter_files_by_pattern(sorted_files[:singles] || [], pattern || "/^\S+.f(ast)?q(.gz)?$/").last
last_single.nil? ? {} : last_single
else
{}
end
end

Expand All @@ -82,6 +80,13 @@ def filter_files_by_pattern(files, pattern)
private

def fastq_direction(property)
property.match(/fastq_(\d+)/)[1].to_i == 1 ? :pe_forward : :pe_reverse
case property.match(/^fastq_(\d+)$/).to_a[1]
when '1'
:pe_forward
when '2'
:pe_reverse
else
:single
end
end
end

0 comments on commit f046e69

Please sign in to comment.