From a6aa6c5d4d9de080a0c5ee55ebbf278bda92f597 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Wed, 11 Sep 2024 10:20:08 -0500 Subject: [PATCH] ColumnComponent: Exclude non-fastq files if no fastq are present (#742) * 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 --- .../nextflow/samplesheet/column_component.rb | 46 +++++++++++++------ .../nextflow/samplesheet_component.rb | 4 ++ 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/app/components/nextflow/samplesheet/column_component.rb b/app/components/nextflow/samplesheet/column_component.rb index 9f1686a3a1..214fedbaba 100644 --- a/app/components/nextflow/samplesheet/column_component.rb +++ b/app/components/nextflow/samplesheet/column_component.rb @@ -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) diff --git a/app/components/nextflow/samplesheet_component.rb b/app/components/nextflow/samplesheet_component.rb index 03c2d3c361..04dc2c9fce 100644 --- a/app/components/nextflow/samplesheet_component.rb +++ b/app/components/nextflow/samplesheet_component.rb @@ -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