Class: LabwareCreators::CardinalPoolsPlate

Inherits:
Base
  • Object
show all
Includes:
RequireWellsWithCollectedBy, SupportParent::PlateOnly
Defined in:
app/models/labware_creators/cardinal_pools_plate.rb

Overview

This class is used for creating Cardinal pools into destination plate

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from LabwareCreators::Base

Instance Method Details

#build_poolsObject

Returns a nested list of wells, grouped by pool e.g. pools = [[w1,w4],,[w3,w6]]



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'app/models/labware_creators/cardinal_pools_plate.rb', line 124

def build_pools
  pools = []
  current_pool = 0

  # wells_grouped_by_collected_by = {0=>['w1', 'w4'], 1=>['w6', 'w2'], 2=>['w9', 'w23']}
  wells_grouped_by_collected_by.each_value do |wells|
    # Loop through the wells for that collected_by
    wells.each do |well|
      # Create pool if it doesnt already exist
      pools[current_pool] = [] unless pools[current_pool]

      # Add well to pool
      pools[current_pool] << well

      # Rotate through the pools
      current_pool = current_pool == number_of_pools - 1 ? 0 : current_pool + 1
    end
  end
  pools
end

#dest_coordinatesObject

Returns: [A1, B1, … H1] Used to assign pools to a destination well, e.g. Pool 1 > A1, Pool2 > B1



96
97
98
# File 'app/models/labware_creators/cardinal_pools_plate.rb', line 96

def dest_coordinates
  ('A'..'H').to_a.map { |letter| "#{letter}1" }
end

#filters=(filter_parameters) ⇒ Object



28
29
30
# File 'app/models/labware_creators/cardinal_pools_plate.rb', line 28

def filters=(filter_parameters)
  well_filter.assign_attributes(filter_parameters)
end

#get_well_for_plate_location(plate, well_location) ⇒ Object

Returns: An instance of Sequencescape::Api::V2::Well



72
73
74
# File 'app/models/labware_creators/cardinal_pools_plate.rb', line 72

def get_well_for_plate_location(plate, well_location)
  plate.wells.detect { |well| well.location == well_location }
end

#number_of_poolsObject

Returns: the number of pools required for a given passed samples count this config is appended in the Cardinal initialiser e.g. 95,12,12,12,12,12,12,12,11 ==> 8 e.g. 53,11,11,11,10,10,,, ==> 5



51
52
53
# File 'app/models/labware_creators/cardinal_pools_plate.rb', line 51

def number_of_pools
  Rails.application.config.cardinal_pooling_config[passed_parent_wells.count]
end

#parentObject Originally defined in module SupportParent::PlateOnly

#passed_parent_wellsObject

Returns: a list of passed wells passed_parent_wells



39
40
41
# File 'app/models/labware_creators/cardinal_pools_plate.rb', line 39

def passed_parent_wells
  source_plate.wells.select { |well| well.state == 'passed' }
end

#poolsObject



43
44
45
# File 'app/models/labware_creators/cardinal_pools_plate.rb', line 43

def pools
  @pools ||= build_pools
end

#request_hash(source_well, dest_plate) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'app/models/labware_creators/cardinal_pools_plate.rb', line 76

def request_hash(source_well, dest_plate)
  source_location = transfer_hash[source_well.location][:dest_locn]
  {
    'source_asset' => source_well.uuid,
    'target_asset' => get_well_for_plate_location(dest_plate, source_location)&.uuid,
    :aliquot_attributes => {
      'tag_depth' => tag_depth(source_well)
    }
  }
end

#source_plateObject

parent is using SS v1 API so this method is used to access the plate via SS v2 API



34
35
36
# File 'app/models/labware_creators/cardinal_pools_plate.rb', line 34

def source_plate
  @source_plate ||= Sequencescape::Api::V2::Plate.find_by(uuid: parent.uuid)
end

#tag_depth(source_well) ⇒ Object



87
88
89
90
91
92
# File 'app/models/labware_creators/cardinal_pools_plate.rb', line 87

def tag_depth(source_well)
  pools.each do |pool|
    return (pool.index(source_well) + 1).to_s if pool.index(source_well)
    # index + 1 incase of 0th index
  end
end

#transfer_hashObject

Returns: an object mapping a source well location to the destination well location e.g. { ‘A1’: { ‘dest_locn’: ‘B1’ }, { ‘A2’: { ‘dest_locn’: ‘A1’ }, { ‘A3’: { ‘dest_locn’: ‘B1’ }}

"A4"=>{:dest_locn=>"A1",
"A11"=>:dest_locn=>"A1",
"G3"=>:dest_locn=>"A1",
"C5"=>:dest_locn=>"A1",

}



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/models/labware_creators/cardinal_pools_plate.rb', line 108

def transfer_hash
  result = {}

  # Build only once, as this is called in a loop
  pools.each_with_index do |pool, index|
    destination_well_location = dest_coordinates[index]
    pool.each do |well|
      source_position = well.location
      result[source_position] = { dest_locn: destination_well_location }
    end
  end
  result
end

#transfer_material_from_parent!(dest_uuid) ⇒ Object

Send the transfer request to SS



56
57
58
59
60
61
62
63
# File 'app/models/labware_creators/cardinal_pools_plate.rb', line 56

def transfer_material_from_parent!(dest_uuid)
  dest_plate = Sequencescape::Api::V2::Plate.find_by(uuid: dest_uuid)
  api.transfer_request_collection.create!(
    user: user_uuid,
    transfer_requests: transfer_request_attributes(dest_plate)
  )
  true
end

#transfer_request_attributes(dest_plate) ⇒ Object

returns: a list of objects, mapping source well to destination well e.g [‘auuid’, ‘target_asset’: ‘anotheruuid’]



67
68
69
# File 'app/models/labware_creators/cardinal_pools_plate.rb', line 67

def transfer_request_attributes(dest_plate)
  passed_parent_wells.map { |source_well| request_hash(source_well, dest_plate) }
end

#well_filterObject



24
25
26
# File 'app/models/labware_creators/cardinal_pools_plate.rb', line 24

def well_filter
  @well_filter ||= WellFilter.new(creator: self)
end

#wells_grouped_by_collected_byObject

Get passed parent wells, randomise, then group by sample metadata: collected_by e.g. { collected_by_0=>[‘w1’, ‘w4’], collected_by_1=>[‘w6’, ‘w2’], collected_by_2=>[‘w9’, ‘w23’] } wells_with_aliquots_must_have_collected_by handles the validation of sample metadata presence



148
149
150
# File 'app/models/labware_creators/cardinal_pools_plate.rb', line 148

def wells_grouped_by_collected_by
  passed_parent_wells.to_a.shuffle.group_by { |well| well.aliquots.first.sample..collected_by }
end

#wells_with_aliquots_must_have_collected_byObject Originally defined in module RequireWellsWithCollectedBy

Validation method that can be called to check that all wells, with aliquots, have an associated sample metadata, with collected_by.