Class: Utility::ConcentrationBinningCalculator

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, CommonDilutionCalculations
Defined in:
app/models/utility/concentration_binning_calculator.rb

Overview

Handles the Computations for Concentration Binning Used by the Concentration Binning Plate and Presenter classes to handle the binning configuration, compute the bins and provide helpers on displaying the bins on the child plate.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly) Originally defined in module CommonDilutionCalculations

Returns the value of attribute config.

Instance Method Details

#compute_presenter_bin_details(plate) ⇒ Object

This is used by the plate presenter. It uses the amount in the well and the plate purpose binning config to work out the well bin colour and number of PCR cycles. The multiplication factor takes into account the dilution performed on the samples.



49
50
51
52
# File 'app/models/utility/concentration_binning_calculator.rb', line 49

def compute_presenter_bin_details(plate)
  well_amounts = compute_well_amounts(plate.wells, dest_multiplication_factor)
  compute_bin_details_by_well(well_amounts)
end

#compute_vol_source_reqd(sample_conc) ⇒ float Originally defined in module CommonDilutionCalculations

Computes the volume of source material required for normalisation based on the sample concentration and attributes from the purpose configuration (target amount and volume, minimum source volume). Includes checks for minimum source volume and rounding for low diluent volumes due to liquid handler robot restrictions.

Parameters:

  • sample_conc (float)

    The concentration of the source sample in ng/ul

Returns:

  • (float)

    The volume of the source required in ul.

#compute_well_amounts(wells, multiplication_factor) ⇒ Object

Calculates the well amounts from the filtered well concentrations and a volume multiplication factor. The multiplication factor is different depending on whether we are working with the parent plate or the diluted child plate.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/utility/concentration_binning_calculator.rb', line 17

def compute_well_amounts(wells, multiplication_factor)
  # sort on well coordinate to ensure wells are in plate column order
  wells
    .sort_by(&:coordinate)
    .each_with_object({}) do |well, well_amounts|
      next if well.aliquots.blank?

      # check for well concentration value present
      if well.latest_concentration.blank?
        errors.add(:base, "Well #{well.location} does not have a concentration, cannot calculate amount in well")
        next
      end

      # concentration recorded is per microlitre, multiply by volume to get amount in ng in well
      well_amounts[well.location] = well.latest_concentration.value.to_f * multiplication_factor
    end
end

#compute_well_transfers(parent_plate, filtered_wells) ⇒ Object



35
36
37
38
# File 'app/models/utility/concentration_binning_calculator.rb', line 35

def compute_well_transfers(parent_plate, filtered_wells)
  well_amounts = compute_well_amounts(filtered_wells, source_multiplication_factor)
  compute_well_transfers_hash(well_amounts, parent_plate.number_of_rows, parent_plate.number_of_columns)
end

#compute_well_transfers_hash(well_amounts, number_of_rows, number_of_columns) ⇒ Object



40
41
42
43
44
# File 'app/models/utility/concentration_binning_calculator.rb', line 40

def compute_well_transfers_hash(well_amounts, number_of_rows, number_of_columns)
  conc_bins = concentration_bins(well_amounts)
  compression_reqd = compression_required?(conc_bins, number_of_rows, number_of_columns)
  build_transfers_hash(conc_bins, number_of_rows, compression_reqd)
end

#construct_dest_qc_assay_attributes(child_uuid, transfer_hash) ⇒ array Originally defined in module CommonDilutionCalculations

Constructs the qc_assays collection details for use when writing calculated concentrations for the newly created child plate.

Parameters:

  • child_uuid (string)

    The uuid of the child plate being transferred into.

  • transfer_hash (hash)

    The transfers hash from which we extract the destination concentrations.

Returns:

  • (array)

    An array of qc assay details for the child plate, ready to send via Api to sequencescape.

#extract_destination_concentrations(transfer_hash) ⇒ hash Originally defined in module CommonDilutionCalculations

Refactor the transfers hash to give destination concentrations

Parameters:

  • transfer_hash (hash)

    The transfer details.

Returns:

  • (hash)

    A refactored hash of well concentrations.

#initialize(config) ⇒ Object Originally defined in module CommonDilutionCalculations

The calculators all use a common configuration structure stored on the plate purpose.

Parameters:

  • config (hash)

    The relevant section from the plate purpose configuration.

#normalisation_details(wells) ⇒ hash Originally defined in module CommonDilutionCalculations

Creates a hash of well normalisation details for a plate used when generating the well transfers and qc assays.

Parameters:

  • wells (Wells)

    The source wells being normalised.

Returns:

  • (hash)

    The well details hash containing calculated normalisation values.