Class: SampleManifestExcel::Upload::Processor::OneDTube

Inherits:
Base
  • Object
show all
Defined in:
app/sample_manifest_excel/sample_manifest_excel/upload/processor/one_d_tube.rb

Overview

TODO: had to explicitly specify the namespace for Base here otherwise it picks up Upload::Base Processor to handle 1dtube uploads

Constant Summary

Constants inherited from Base

Base::MANDATORY_FIELDS

Instance Attribute Summary

Attributes inherited from Base

#upload

Instance Method Summary collapse

Methods inherited from Base

#aliquots_updated?, #create_samples_if_not_present, #downstream_aliquots_updated?, #initialize, #processed?, #run, #sample_manifest_updated?, #samples_updated?, #samples_valid?, #substitutions, #type, #update_sample_manifest, #update_samples_and_aliquots

Constructor Details

This class inherits a constructor from SampleManifestExcel::Upload::Processor::Base

Instance Method Details

#check_for_retention_instructionObject

All extraction tubes on the same manifest must have the same retention instructions.



12
13
14
15
16
17
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/one_d_tube.rb', line 12

def check_for_retention_instruction
  retention_error_row, err_msg = non_matching_retention_instructions
  return if retention_error_row.nil?

  errors.add(:base, "Retention instruction checks failed at row: #{retention_error_row.number}. #{err_msg}")
end

#check_row_retention_value(row, tube_barcode, tube_retentions) ⇒ Object

rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/one_d_tube.rb', line 45

def check_row_retention_value(row, tube_barcode, tube_retentions)
  # if present the column is mandatory
  row_retention_value = row.value('retention_instruction')
  return 'Value cannot be blank.' if row_retention_value.nil?

  # Check that the manifest has only one retention instruction value
  if tube_retentions.key?('first')
    if tube_retentions['first'] != row_retention_value
      return "Tube (#{tube_barcode}) cannot have different retention instruction value."
    end
  else
    # first time we are seeing a tube, add its retention value to hash
    tube_retentions['first'] = row_retention_value
  end
  nil
end

#non_matching_retention_instructionsObject

rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/one_d_tube.rb', line 20

def non_matching_retention_instructions
  return nil, nil unless upload.respond_to?(:rows)

  upload
    .rows
    .each_with_object({}) do |row, tube_retentions|
      # ignore empty rows and skip if the retention column is not present
      if row.columns.blank? || row.data.blank? || row.columns.extract(['retention_instruction']).count.zero?
        next
      end

      tube_barcode = row.value('sanger_tube_id')
      sample_id = row.value('sanger_sample_id')

      # ignore rows where primary sample fields have not been filled in
      next unless tube_barcode.present? && sample_id.present?

      # check the row retention instruction is valid
      err_msg = check_row_retention_value(row, tube_barcode, tube_retentions)
      return row, err_msg if err_msg.present?
    end
  [nil, nil]
end