Module: Api::Messages::FlowcellIo::LaneExtensions

Included in:
SequencingRequest
Defined in:
app/models/api/messages/flowcell_io.rb

Overview

The following modules add methods onto the relevant models, which are used below in generation of the flowcell MLWH message. Included in SequencingRequest model

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

rubocop:todo Metrics/AbcSize, Metrics/MethodLength



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/models/api/messages/flowcell_io.rb', line 29

def self.included(base) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
  base.class_eval do
    def mx_library
      asset.external_identifier
    end

    def manual_qc
      MANUAL_QC_BOOLS[target_asset.try(:qc_state)]
    end

    def flowcell_barcode
      detect_descriptor(flowcell_identifier)
    end

    def lane_samples
      target_asset.aliquots
    end

    def lane
      target_asset.labware
    end

    delegate :spiked_in_buffer, :external_release, to: :lane, allow_nil: true

    def controls
      spiked_in_buffer.present? ? spiked_in_buffer.aliquots : []
    end

    def lane_identifier
      target_asset_id
    end

    def request_purpose_key
      request_purpose.try(:key)
    end

    def workflow
      detect_descriptor('Workflow (Standard or Xp)')
    end

    def spiked_phix_barcode
      spiked_in_buffer&.human_barcode
    end

    def spiked_phix_percentage
      detect_float_descriptor('PhiX %', '%')
    end

    def loading_concentration
      detect_float_descriptor('Lane loading concentration (pM)', 'pM')
    end

    # Currently the tangled mass that is descriptors does little in the way of validation
    # This means non-float values have been entered in some case (such as ranges)
    # This extracts floats only until the data can be repaired, and validation added to prevent
    # bad data from being added in future
    def detect_float_descriptor(name, ignored_unit)
      value = detect_descriptor(name)
      return nil if value.nil?

      begin
        # If someone has added the units to the input, strip them off then convert to a float
        # We also strip whitespace.
        # However if float conversion fails, then the input is unsuitable.
        # Note: .to_f is too permissive here
        Float(value.gsub(ignored_unit, '').strip)
      rescue ArgumentError
        nil
      end
    end
  end
end