Skip to content

Commit

Permalink
Merge branch 'dpl-977-update-tnano-export-file' into uat-19th-feb-24
Browse files Browse the repository at this point in the history
  • Loading branch information
yoldas committed Feb 19, 2024
2 parents 9f474be + 92358f6 commit 8a203bf
Show file tree
Hide file tree
Showing 45 changed files with 2,183 additions and 456 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# frozen_string_literal: true

# Part of the Labware creator classes
module LabwareCreators
require_dependency 'labware_creators/pcr_cycles_binned_plate/csv_file_for_duplex_seq'

module PcrCyclesBinnedPlate::CsvFile
#
# This version of the row is for the Duplex Seq pipeline.
#
class DuplexSeq::Row < RowBase
include ActiveModel::Validations

SUB_POOL_NOT_BLANK = 'has a value when Submit for Sequencing is N, it should be empty, in %s'
SUBMIT_FOR_SEQ_INVALID = 'is empty or has an unrecognised value (should be Y or N), in %s'
COVERAGE_MISSING = 'is missing but should be present when Submit for Sequencing is Y, in %s'
COVERAGE_NEGATIVE = 'is negative but should be a positive value, in %s'

attr_reader :submit_for_sequencing, :sub_pool, :coverage

validate :submit_for_sequencing_has_expected_value
validate :sub_pool_within_expected_range
validates :coverage,
presence: {
message: ->(object, _data) { COVERAGE_MISSING % object }
},
numericality: {
greater_than: 0,
message: ->(object, _data) { COVERAGE_NEGATIVE % object }
},
unless: -> { empty? || !submit_for_sequencing? }

delegate :submit_for_sequencing_column, :sub_pool_column, :coverage_column, to: :header

def initialize_pipeline_specific_columns
@submit_for_sequencing_as_string = @row_data[submit_for_sequencing_column]&.strip&.upcase
@sub_pool = @row_data[sub_pool_column]&.strip&.to_i
@coverage = @row_data[coverage_column]&.strip&.to_i
end

def submit_for_sequencing?
@submit_for_sequencing ||= (@submit_for_sequencing_as_string == 'Y')
end

def submit_for_sequencing_has_expected_value
return if empty?

return if %w[Y N].include? @submit_for_sequencing_as_string

errors.add('submit_for_sequencing', format(SUBMIT_FOR_SEQ_INVALID, to_s))
end

def sub_pool_within_expected_range
return if empty?

# check the value is within range when we do expect a value to be present
if submit_for_sequencing?
in_range('sub_pool', sub_pool, @row_config.sub_pool_min, @row_config.sub_pool_max)
else
# expect sub-pool field to be blank, possible mistake by user if not
return if sub_pool.blank?

# sub-pool is NOT blank and should be
errors.add('sub_pool', format(SUB_POOL_NOT_BLANK, to_s))
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

# Part of the Labware creator classes
module LabwareCreators
require_dependency 'labware_creators/pcr_cycles_binned_plate/csv_file_for_duplex_seq'

module PcrCyclesBinnedPlate::CsvFile
#
# Class WellDetailsHeader provides a simple wrapper for handling and validating
# the plate barcode header row from the customer csv file
#
class DuplexSeq::WellDetailsHeader < WellDetailsHeaderBase
# Return the index of the respective column.
attr_reader :submit_for_sequencing_column, :sub_pool_column, :coverage_column

SUBMIT_FOR_SEQUENCING_COLUMN = 'Submit for sequencing (Y/N)?'
SUB_POOL_COLUMN = 'Sub-Pool'
COVERAGE_COLUMN = 'Coverage'
NOT_FOUND = 'could not be found in: '

validates :submit_for_sequencing_column, presence: { message: ->(object, _data) { "#{NOT_FOUND}'#{object}'" } }
validates :sub_pool_column, presence: { message: ->(object, _data) { "#{NOT_FOUND}'#{object}'" } }
validates :coverage_column, presence: { message: ->(object, _data) { "#{NOT_FOUND}'#{object}'" } }

private

def initialize_pipeline_specific_columns
@submit_for_sequencing_column = index_of_header(SUBMIT_FOR_SEQUENCING_COLUMN)
@sub_pool_column = index_of_header(SUB_POOL_COLUMN)
@coverage_column = index_of_header(COVERAGE_COLUMN)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Part of the Labware creator classes
module LabwareCreators
require_dependency 'labware_creators/custom_pooled_tubes/csv_file'
require_dependency 'labware_creators/pcr_cycles_binned_plate/csv_file_base'

#
# Class PlateBarcodeHeader provides a simple wrapper for handling and validating
Expand All @@ -22,9 +22,10 @@ class PcrCyclesBinnedPlate::CsvFile::PlateBarcodeHeader
BARCODE_NOT_MATCHING =
'The plate barcode in the file (%s) does not match the barcode of ' \
'the plate being uploaded to (%s), please check you have the correct file.'
NOT_FOUND = 'could not be found in: '

validates :barcode_lbl_index, presence: { message: ->(object, _data) { "could not be found in: '#{object}'" } }
validates :plate_barcode, presence: { message: ->(object, _data) { "could not be found in: '#{object}'" } }
validates :barcode_lbl_index, presence: { message: ->(object, _data) { "#{NOT_FOUND}'#{object}'" } }
validates :plate_barcode, presence: { message: ->(object, _data) { "#{NOT_FOUND}'#{object}'" } }
validate :plate_barcode_matches_parent?

#
Expand Down
173 changes: 0 additions & 173 deletions app/models/labware_creators/pcr_cycles_binned_plate/csv_file/row.rb

This file was deleted.

Loading

0 comments on commit 8a203bf

Please sign in to comment.