Module: LabwareCreators::DonorPoolingValidator

Extended by:
ActiveSupport::Concern
Included in:
DonorPoolingPlate
Defined in:
app/models/concerns/labware_creators/donor_pooling_validator.rb

Overview

This module contains validations for donor pooling.

Constant Summary collapse

SOURCE_BARCODES_MUST_BE_ENTERED =
'At least one source plate must be scanned.'
SOURCE_BARCODES_MUST_BE_DIFFERENT =
'You must not scan the same barcode more than once.'
SOURCE_PLATES_MUST_EXIST =
'Source plates not found: %s. ' \
'Please check you scanned the correct source plates. '
NUMBER_OF_POOLS_MUST_NOT_EXCEED_CONFIGURED =
'The calculated number of pools (%s) is higher than the number of pools ' \
'(%s) configured. This is due to constraints such as: ' \
'* samples with different Studies or Projects cannot be combined ' \
'* multiple samples from the same donor cannot be combined. ' \
'Please check you have scanned the correct set of source plates.'
WELLS_WITH_ALIQUOTS_MUST_HAVE_DONOR_ID =
'All samples must have the donor_id specified. ' \
'Wells missing donor_id (on sample metadata): %s'
WELLS_WITH_ALIQUOTS_MUST_HAVE_CELL_COUNT =
'All wells must have cell count data unless they are failed. ' \
'Wells missing cell count data: %s'

Instance Method Summary collapse

Instance Method Details

#number_of_pools_must_not_exceed_configuredvoid

This method returns an undefined value.

Validates that the number of calculated pools does not exceed the configured number of pools. If the number of calculated pools is greater, an error is added to the :source_plates attribute.



77
78
79
80
81
82
83
84
# File 'app/models/concerns/labware_creators/donor_pooling_validator.rb', line 77

def number_of_pools_must_not_exceed_configured
  # Don't add this error if there are already errors about invalid wells
  return if locations_with_missing_donor_id.any? || locations_with_missing_cell_count.any?

  return if pools.size <= number_of_pools

  errors.add(:source_plates, format(NUMBER_OF_POOLS_MUST_NOT_EXCEED_CONFIGURED, pools.size, number_of_pools))
end

#source_barcodes_must_be_differentvoid

This method returns an undefined value.

Validates that all source barcodes are unique. If any barcodes are duplicated, an error is added to the :source_barcodes attribute.



53
54
55
56
57
# File 'app/models/concerns/labware_creators/donor_pooling_validator.rb', line 53

def source_barcodes_must_be_different
  return if minimal_barcodes.size == minimal_barcodes.uniq.size

  errors.add(:source_barcodes, SOURCE_BARCODES_MUST_BE_DIFFERENT)
end

#source_barcodes_must_be_enteredvoid

This method returns an undefined value.

Validates that at least one source barcode has been entered. If no barcodes are entered, an error is added to the :source_barcodes attribute.



43
44
45
46
47
# File 'app/models/concerns/labware_creators/donor_pooling_validator.rb', line 43

def source_barcodes_must_be_entered
  return if minimal_barcodes.size >= 1

  errors.add(:source_barcodes, SOURCE_BARCODES_MUST_BE_ENTERED)
end

#source_plates_must_existvoid

This method returns an undefined value.

Validates that all source plates corresponding to the minimal barcodes exist. If the number of source plates does not match the number of minimal barcodes, an error is added to the :source_plates attribute.



64
65
66
67
68
69
70
# File 'app/models/concerns/labware_creators/donor_pooling_validator.rb', line 64

def source_plates_must_exist
  return if source_plates.size == minimal_barcodes.size

  formatted_string = (minimal_barcodes - source_plates.map(&:human_barcode)).join(', ')

  errors.add(:source_plates, format(SOURCE_PLATES_MUST_EXIST, formatted_string))
end

#wells_with_aliquots_must_have_cell_countvoid

This method returns an undefined value.

Validates that wells with aliquots have a latest_live_cell_count. It uses the locations_with_missing_cell_count method to find any wells that are missing a cell count. If any such wells are found, it adds an error message to the source_plates attribute, formatted with the barcodes of the plates and the wells that are missing a cell count. Note that the well filter already excludes failed wells. This validation ensures that all wells with aliquots have a cell count unless they are failed.



110
111
112
113
114
115
116
# File 'app/models/concerns/labware_creators/donor_pooling_validator.rb', line 110

def wells_with_aliquots_must_have_cell_count
  invalid_wells_hash = locations_with_missing_cell_count
  return if invalid_wells_hash.empty?

  formatted_string = formatted_invalid_wells_hash(invalid_wells_hash)
  errors.add(:source_plates, format(WELLS_WITH_ALIQUOTS_MUST_HAVE_CELL_COUNT, formatted_string))
end

#wells_with_aliquots_must_have_donor_idvoid

This method returns an undefined value.

Validates that all wells with aliquots must have a donor_id. It uses the locations_with_missing_donor_id method to find any wells that are missing a donor_id. If any such wells are found, it adds an error message to the source_plates attribute, formatted with the barcodes of the plates and the wells that are missing a donor_id.



93
94
95
96
97
98
99
# File 'app/models/concerns/labware_creators/donor_pooling_validator.rb', line 93

def wells_with_aliquots_must_have_donor_id
  invalid_wells_hash = locations_with_missing_donor_id
  return if invalid_wells_hash.empty?

  formatted_string = formatted_invalid_wells_hash(invalid_wells_hash)
  errors.add(:source_plates, format(WELLS_WITH_ALIQUOTS_MUST_HAVE_DONOR_ID, formatted_string))
end