Class: MultiPool

Inherits:
ApplicationRecord show all
Includes:
Pipelineable
Defined in:
app/models/multi_pool.rb

Overview

MultiPool A collection of pools grouped/created together using a specific pooling method.

Instance Method Summary collapse

Methods included from Pipelineable

#pipeline_handler

Instance Method Details

#consistent_pools_type?void

This method returns an undefined value.

Checks that all pools in the multi pool are of the same type.



23
24
25
26
27
28
29
30
31
32
# File 'app/models/multi_pool.rb', line 23

def consistent_pools_type?
  return true if multi_pool_positions.empty?

  types = multi_pool_positions.map(&:pipeline).compact.uniq

  return true if types.size <= 1

  errors.add(:multi_pool_positions, 'all pools must be of the same type')
  false
end

#library_source_volume_mapObject

Returns a hash map of library sources to the total volume used across all pools in the multi pool.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/models/multi_pool.rb', line 71

def library_source_volume_map
  library_source_volume_map = {}
  multi_pool_positions.each do |position|
    next unless position.pacbio_pool

    position.pacbio_pool.used_aliquots.each do |aliquot|
      next unless aliquot.source_type == 'Pacbio::Library'

      # Merges the aliquot volume into the library source total, summing volumes
      # for duplicate sources
      library_source_volume_map.merge!(aliquot.source => aliquot.volume) do |_, old_vol, new_vol|
        old_vol + new_vol
      end
    end
  end
  library_source_volume_map
end

#number_of_poolsInteger

Returns the number of pools in the multi pool.

Returns:

  • (Integer)

    number of pools



49
50
51
# File 'app/models/multi_pool.rb', line 49

def number_of_pools
  multi_pool_positions.length
end

#sufficient_library_available_volume?Boolean

Extra validation to prevent race conditions where libraries are used across pools in the same multi pool and the total used library volume exceeds the library available volume. This is an edge case because the aliquot volume checks should prevent this from happening but since the pools are created in parallel they are not aware of each others existence so they are not factored into the volume checks.

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
# File 'app/models/multi_pool.rb', line 58

def sufficient_library_available_volume?
  library_source_volume_map.each do |source, used_volume|
    if source.available_volume < used_volume
      errors.add(:base, "#{source.barcode} does not have sufficient available volume")
      return false
    end
  end

  true
end

#unique_pool_positions?void

This method returns an undefined value.

Checks that all pools in the multi pool have unique positions.



36
37
38
39
40
41
42
43
44
45
# File 'app/models/multi_pool.rb', line 36

def unique_pool_positions?
  positions = multi_pool_positions.map(&:position)
  duplicate_positions = positions.select { |pos| positions.count(pos) > 1 }

  return true unless duplicate_positions.any?

  errors.add(:multi_pool_positions,
             "#{duplicate_positions.uniq.join(', ')} positions are duplicated")
  false
end