Class: Plate

Overview

A plate is a piece of labware made up of a number of wells. This class represents the physical piece of plastic.

  • PlatePurpose: describes the role a plate has in the lab. In some cases a plate's purpose may change as it gets processed.

  • Well: Plates can have multiple wells (most often 96 or 384) each of which can contain multiple samples.

  • PlateType: Identifies the plates form factor, typically provided to robots to ensure tips are positioned correctly.

Defined Under Namespace

Modules: FluidigmBehaviour Classes: Creator, CreatorParameters, QuadCreator, SampleTubeFactory

Constant Summary

Constants included from Metadata

Metadata::SECTION_FIELDS

Instance Attribute Summary

Attributes inherited from Labware

#storage_location_service

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Metadata

has_metadata

Methods included from QcFile::Associations

has_qc_files

Methods included from PlateCreation::CreationChild

included

Methods included from SubmissionPool::Association::Plate

included

Methods included from FluidigmBehaviour

#apply_fluidigm_data, included, #retrieve_fluidigm_data

Methods included from Asset::Ownership::Owned

#change_owner_to, included

Methods included from Barcode::Barcodeable

#aker_barcode, #aker_barcode=, #any_barcode_matching?, #barcode_format, #barcode_number, #cgap_barcode, #cgap_barcode=, #external_barcode, #external_barcode=, #external_identifier, #fluidigm_barcode, #fluidigm_barcode=, included, #infinium_barcode, #infinium_barcode=, #prefix, #primary_barcode, #printable_target, #sanger_barcode

Methods included from Transfer::State::PlateState

included

Methods included from Transfer::Associations

included

Methods included from Api::PlateIO::Extensions

included, #json_root

Methods inherited from Labware

#ancestor_of_purpose, #ancestors_of_purpose, #child, #display_name, find_by_barcode, find_from_any_barcode, #generate_name, #human_barcode, #labware, #labwhere_location, labwhere_locations, #parent, #role, #scanned_in_date, #source_plate, #source_plates, #storage_location

Methods included from SharedBehaviour::Named

included

Methods included from AssetLink::Associations

included

Methods included from Uuid::Uuidable

included, #unsaved_uuid!, #uuid

Methods inherited from Asset

#add_parent, #ancestor_of_purpose, #asset_type_for_request_types, #assign_relationships, #barcode_number, #contained_samples, #external_identifier, #get_qc_result_value_for, #has_stock_asset?, #label, #label=, #original_stock_plates, #prefix, #printable?, #printable_target, #register_stock!, #request_types, #spiked_in_buffer, #type, #update_from_qc

Methods included from EventfulRecord

#has_many_events, #has_many_lab_events, #has_one_event_with_family

Methods included from Event::PlateEvents

#event_date, #fluidigm_stamp_date, #gel_qc_date, #pico_date, #qc_started_date, #sequenom_stamp_date

Methods inherited from ApplicationRecord

convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Squishify

extended

Methods included from Warren::BroadcastMessages

#broadcast, included, #queue_associated_for_broadcast, #queue_for_broadcast, #warren

Class Method Details

.create_with_barcode!(*args, &block) ⇒ Object


339
340
341
342
343
# File 'app/models/plate.rb', line 339

def self.create_with_barcode!(*args, &block)
  attributes = args.extract_options!
  attributes[:sanger_barcode] = safe_sanger_barcode(attributes[:sanger_barcode] || {})
  create!(attributes, &block)
end

.plate_ids_from_requests(requests) ⇒ Object


308
309
310
# File 'app/models/plate.rb', line 308

def self.plate_ids_from_requests(requests)
  with_requests(requests).pluck(:id)
end

.safe_sanger_barcode(sanger_barcode) ⇒ Object


345
346
347
348
349
350
351
352
# File 'app/models/plate.rb', line 345

def self.safe_sanger_barcode(sanger_barcode)
  if sanger_barcode[:number].blank? || Barcode.sanger_barcode(sanger_barcode[:prefix],
                                                              sanger_barcode[:number]).exists?
    { number: PlateBarcode.create.barcode, prefix: sanger_barcode[:prefix] }
  else
    sanger_barcode
  end
end

.search_for_plates(params) ⇒ Object


248
249
250
251
252
253
254
255
# File 'app/models/plate.rb', line 248

def self.search_for_plates(params)
  with_faculty_sponsor_ids(params[:faculty_sponsor_ids] || nil)
    .with_study_id(params[:study_id] || nil)
    .with_plate_purpose_ids(params[:plate_purpose_ids] || nil)
    .created_between(params[:start_date], params[:end_date])
    .filter_by_barcode(params[:barcodes] || nil)
    .distinct
end

Instance Method Details

#after_comment_addition(comment) ⇒ Object


465
466
467
# File 'app/models/plate.rb', line 465

def after_comment_addition(comment)
  comments.add_comment_to_submissions(comment)
end

#all_submission_idsObject

Prioritised the submissions that have been made from the plate then falls back onto the ones under which the plate was made


178
179
180
# File 'app/models/plate.rb', line 178

def all_submission_ids
  submission_ids_as_source.presence || submission_ids
end

#buffer_required?Boolean

Returns:

  • (Boolean)

362
363
364
# File 'app/models/plate.rb', line 362

def buffer_required?
  wells.any?(&:buffer_required?)
end

#cherrypick_completedVoid

Called when cherrypicking is completed to allow the plate to trigger any callbacks, such as broadcasting Fluidigm plates to the warehouse. This behaviour varies based on the PlatePurpose

Returns:

  • (Void)

155
156
157
# File 'app/models/plate.rb', line 155

def cherrypick_completed
  plate_purpose.cherrypick_completed(self)
end

#commentsObject


195
196
197
# File 'app/models/plate.rb', line 195

def comments
  @comments ||= CommentsProxy::Plate.new(self)
end

#compatible_purposesObject


416
417
418
# File 'app/models/plate.rb', line 416

def compatible_purposes
  PlatePurpose.compatible_with_purpose(purpose)
end

#convert_to(new_purpose) ⇒ Object


412
413
414
# File 'app/models/plate.rb', line 412

def convert_to(new_purpose)
  update!(plate_purpose: new_purpose)
end

#detailsObject


304
305
306
# File 'app/models/plate.rb', line 304

def details
  purpose.try(:name) || 'Unknown plate purpose'
end

#find_well_by_name(well_name) ⇒ Object Also known as: find_well_by_map_description


279
280
281
282
283
284
285
# File 'app/models/plate.rb', line 279

def find_well_by_name(well_name)
  if wells.loaded?
    wells.indexed_by_location[well_name]
  else
    wells.located_at_position(well_name).first
  end
end

#generate_barcodeObject

Plates use a different counter to tubes, and prior to the foreign barcodes update this method would have fallen back to Barcodable#generate tubes, and potentially generated an invalid plate barcode. In the future we probably want to scrap this approach entirely, and generate all barcodes in the plate style. (That is, as part of the factory on, eg. plate purpose)

Raises:

  • (StandardError)

457
458
459
# File 'app/models/plate.rb', line 457

def generate_barcode
  raise StandardError, "#generate_barcode has been called on plate, which wasn't supposed to happen, and probably indicates a bug."
end

#heightObject


389
390
391
# File 'app/models/plate.rb', line 389

def height
  asset_shape.plate_height(size)
end

#invalid_positions(positions) ⇒ Array

Given a list of well map_descriptions (eg. A1), returns those not present on the plate

Parameters:

  • positions (Array)

    Array of positions to test

Returns:

  • (Array)

    Array of invalid positions


373
374
375
# File 'app/models/plate.rb', line 373

def invalid_positions(positions)
  (positions.uniq - unique_positions_on_plate).sort
end

#iterationObject


186
187
188
189
190
191
192
193
# File 'app/models/plate.rb', line 186

def iteration
  iter = siblings # assets sharing the same parent
         .where(plate_purpose_id: plate_purpose_id, sti_type: sti_type) # of the same purpose and type
         .where("#{self.class.table_name}.created_at <= ?", created_at) # created before or at the same time
         .count(:id) # count the siblings.

  iter.zero? ? nil : iter # Maintains compatibility with legacy version
end

#mapsObject


275
276
277
# File 'app/models/plate.rb', line 275

def maps
  Map.where_plate_size(size).where_plate_shape(asset_shape)
end

#name_for_labelObject


381
382
383
# File 'app/models/plate.rb', line 381

def name_for_label
  name
end

#number_of_blank_samplesObject


354
355
356
# File 'app/models/plate.rb', line 354

def number_of_blank_samples
  wells.with_blank_samples.count
end

#occupied_well_countInteger

Note:

Does not take into account the Sample#empty_supplier_sample_name flag on older samples

Counts the number of wells containing one or more aliquots.

Returns:

  • (Integer)

    The number of wells with samples


137
138
139
# File 'app/models/plate.rb', line 137

def occupied_well_count
  wells.with_contents.count
end

#pick_as_control?false

When Cherrypicking, especially on the Hamilton, control plates get placed on a seperate bed. ControlPlates overide this.

Returns:

  • (false)

492
493
494
# File 'app/models/plate.rb', line 492

def pick_as_control?
  false
end

#plate_columnsObject


292
293
294
# File 'app/models/plate.rb', line 292

def plate_columns
  (1..width)
end

#plate_rowsObject


288
289
290
# File 'app/models/plate.rb', line 288

def plate_rows
  ('A'..('A'.getbyte(0) + height - 1).chr.to_s).to_a
end

#plate_typeObject


296
297
298
# File 'app/models/plate.rb', line 296

def plate_type
  labware_type&.name || Sequencescape::Application.config.plate_default_type
end

#plate_type=(plate_type) ⇒ Object


300
301
302
# File 'app/models/plate.rb', line 300

def plate_type=(plate_type)
  self.labware_type = PlateType.find_by(name: plate_type)
end

#priorityObject


199
200
201
202
203
# File 'app/models/plate.rb', line 199

def priority
  waiting_submissions.maximum(:priority) ||
    in_progress_submissions.maximum(:priority) ||
    0
end

#receptacles_with_positionObject

Used to unify interface with TubeRacks. Returns a list of all receptacles wells with position information included for aid performance


102
103
104
# File 'app/models/plate.rb', line 102

def receptacles_with_position
  wells.includes(:map)
end

469
470
471
# File 'app/models/plate.rb', line 469

def related_studies
  studies
end

#sanger_barcode=(attributes) ⇒ Object


461
462
463
# File 'app/models/plate.rb', line 461

def sanger_barcode=(attributes)
  barcodes << Barcode.build_sanger_code39(attributes)
end

#scored?Boolean

Returns:

  • (Boolean)

358
359
360
# File 'app/models/plate.rb', line 358

def scored?
  wells.any?(&:get_gel_pass)
end

#stateString

The state of a plate loosely defines what has happened to it. In most cases it is determined by aggregating the state of transfer requests into the wells, although exact behaviour is determined by the PlatePurpose. State typically only works for pipeline application plates. In general:

  • pending: The plate has been registered, but it empty.

  • started: The plate contains samples, but required further processing

  • passed: Work on the plate is complete, and it can be transferred to another target

  • failed: The plate failed QC and can not be progressed further

  • cancelled: The plate is no longer required and should be ignored.

Returns:

  • (String)

    Name of the state the plate is in


117
118
119
# File 'app/models/plate.rb', line 117

def state
  plate_purpose.state_of(self)
end

#stock_platePlate?

Attempts to find the 'stock_plate' for the plate. However this is a fairly nebulous concept. Often it means the plate that first entered a pipeline, but in other cases it can be the XP plate part way through the process. Further complication comes from tubes which pool across multiple plates, where identifying a single stock plate is meaningless. In other scenarios, you split plates out again and the asset link graph is insufficient.

JG: 2021-02-11: See github.com/sanger/sequencescape/issues/3040 for more information

Returns:

  • (Plate, nil)

    The stock plate if found


334
335
336
# File 'app/models/plate.rb', line 334

def stock_plate
  @stock_plate ||= stock_plate? ? self : lookup_stock_plate
end

#stock_plate?Boolean

Returns:

  • (Boolean)

312
313
314
315
316
# File 'app/models/plate.rb', line 312

def stock_plate?
  return true if plate_purpose.nil?

  plate_purpose.stock_plate? && plate_purpose.attatched?(self)
end

#stock_wellsObject

This method returns a map from the wells on the plate to their stock well.


398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'app/models/plate.rb', line 398

def stock_wells
  # Optimisation: if the plate is a stock plate then it's wells are it's stock wells!]
  if stock_plate?
    wells.with_pool_id.each_with_object({}) { |w, store| store[w] = [w] }
  else
    wells.include_stock_wells.with_pool_id.each_with_object({}) do |w, store|
      storted_stock_wells = w.stock_wells.sort_by { |sw| sw.map.column_order }
      store[w] = storted_stock_wells unless storted_stock_wells.empty?
    end.tap do |stock_wells_hash|
      raise "No stock plate associated with #{id}" if stock_wells_hash.empty?
    end
  end
end

#subject_typeObject


449
450
451
# File 'app/models/plate.rb', line 449

def subject_type
  'plate'
end

#submission_idsObject


168
169
170
# File 'app/models/plate.rb', line 168

def submission_ids
  @submission_ids ||= in_progress_submissions.ids
end

#submission_ids_as_sourceObject


172
173
174
# File 'app/models/plate.rb', line 172

def submission_ids_as_source
  @submission_ids_as_source ||= waiting_submissions.ids
end

#submissionsObject


182
183
184
# File 'app/models/plate.rb', line 182

def submissions
  waiting_submissions.presence || in_progress_submissions
end

#summary_hashObject


141
142
143
144
145
146
147
# File 'app/models/plate.rb', line 141

def summary_hash
  {
    asset_id: id,
    barcode: { ean13_barcode: ean13_barcode, human_readable: human_barcode },
    occupied_wells: wells.with_aliquots.include_map.map(&:map_description)
  }
end

#teamObject


439
440
441
442
443
444
445
446
# File 'app/models/plate.rb', line 439

def team
  ProductLine.joins([
    'INNER JOIN request_types ON request_types.product_line_id = product_lines.id',
    'INNER JOIN requests ON requests.request_type_id = request_types.id',
    'INNER JOIN well_links ON well_links.source_well_id = requests.asset_id AND well_links.type = "stock"',
    'INNER JOIN receptacles AS re ON re.id = well_links.target_well_id'
  ]).find_by(['re.labware_id = ?', id]).try(:name) || 'UNKNOWN'
end

#unique_positions_on_plateObject


377
378
379
# File 'app/models/plate.rb', line 377

def unique_positions_on_plate
  maps.distinct.pluck(:description)
end

#update_qc_values_with_parser(parser) ⇒ Object


424
425
426
427
428
429
430
431
432
433
434
435
436
437
# File 'app/models/plate.rb', line 424

def update_qc_values_with_parser(parser)
  ActiveRecord::Base.transaction do
    qc_assay = QcAssay.new
    parser.each_well_and_parameters do |position, well_updates|
      # We might have a nil well if a plate was only partially cherrypicked
      well = well_hash[position] || next
      well_updates.each do |attribute, value|
        QcResult.create!(asset: well, key: attribute, unit_value: value, assay_type: parser.assay_type,
                         assay_version: parser.assay_version, qc_assay: qc_assay)
      end
    end
  end
  true
end

#update_volume(volume_change) ⇒ Void

Modifies the recorded volume information of all wells on a plate by volume_change

Parameters:

  • volume_change (Numeric)

    The adjustment to apply to all wells (in ul). Negative values reduce the target volume, positive values increase it.

Returns:

  • (Void)

126
127
128
129
130
# File 'app/models/plate.rb', line 126

def update_volume(volume_change)
  ActiveRecord::Base.transaction do
    wells.each { |well| well.update_volume(volume_change) }
  end
end

#well_hashObject


420
421
422
# File 'app/models/plate.rb', line 420

def well_hash
  @well_hash ||= wells.include_map.includes(:well_attribute).index_by(&:map_description)
end

#wells_in_column_orderObject


481
482
483
484
485
486
487
# File 'app/models/plate.rb', line 481

def wells_in_column_order
  if wells.loaded?
    wells.sort_by(&:column_order)
  else
    wells.in_column_major_order
  end
end

#wells_in_row_orderObject


473
474
475
476
477
478
479
# File 'app/models/plate.rb', line 473

def wells_in_row_order
  if wells.loaded?
    wells.sort_by(&:row_order)
  else
    wells.in_row_major_order
  end
end

#widthObject


393
394
395
# File 'app/models/plate.rb', line 393

def width
  asset_shape.plate_width(size)
end