Class: PlatePurpose

Inherits:
Purpose show all
Includes:
Api::PlatePurposeIO::Extensions, Purpose::Relationship::Associations, SharedBehaviour::Named
Defined in:
app/models/plate_purpose.rb

Overview

Note:

JG: Generally I have been trying to eliminate as much of the purpose specific behaviour as possible, and have pushed the business logic outwards towards the pipeline applications themselves. This is to try and reduce the overall complexity or Sequencescape models, reduce coupling between Sequencescape and its clients, and to make behaviour of individual plates more predictable. This is intended to increase the flexibility and adaptability of the pipelines.

The standard Purpose class for plates. This defines the standard behaviour, and is the class used for the majority of PlatePurposes.

The Purpose of a piece of Labware describes its role in the lab. While most labware will retain a single purpose through their life cycle, it is possible for purpose to be changed. Ideally this should be performed with a PlateConversion to ensure proper tracking.

Historically Purpose has modified the behaviour of its corresponding Labware, with a number of methods, such as Plate#state delegating to Plate#plate_purpose. While this is still occasionally required, it tends to result in quite brittle, unflexible behaviour. More recently we have been trying to push these differences in business logic outwards. In this new approach the Pipeline handles differences in behaviour, and the purpose acts merely as a tag, which can be used to inform the pipeline how it may wish to proceed. This approach makes Labware far more interchangeable.

Information about which purpose classes are used, and their last activity can be generated by running: `bundle exec rake report:purposes` in the appropriate environment. (Probably production)

Defined Under Namespace

Classes: InitialPurpose, Input

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Api::PlatePurposeIO::Extensions

included, #json_root

Methods included from Purpose::Relationship::Associations

included

Methods included from SharedBehaviour::Named

included

Methods inherited from Purpose

#barcode_type, #prefix=, #set_default_barcode_prefix, #source_plate, #source_plates, #source_purpose_name=, #target_class

Methods included from Uuid::Uuidable

included, #unsaved_uuid!, #uuid

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

.stock_plate_purposeObject


95
96
97
# File 'app/models/plate_purpose.rb', line 95

def self.stock_plate_purpose
  PlatePurpose.create_with(stock_plate: true, cherrypickable_target: true).find_or_create_by!(name: 'Stock Plate')
end

Instance Method Details

#asset_shapeObject


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

def asset_shape
  super || AssetShape.default
end

#attatched?(_plate) ⇒ Boolean

Returns:

  • (Boolean)

120
121
122
# File 'app/models/plate_purpose.rb', line 120

def attatched?(_plate)
  true
end

#cherrypick_completed(plate) ⇒ Object


50
51
52
# File 'app/models/plate_purpose.rb', line 50

def cherrypick_completed(plate)
  messenger_creators.each { |creator| creator.create!(plate) }
end

#cherrypick_in_rows?Boolean

Returns:

  • (Boolean)

116
117
118
# File 'app/models/plate_purpose.rb', line 116

def cherrypick_in_rows?
  cherrypick_direction == 'row'
end

#child_plate_purposesObject


124
125
126
# File 'app/models/plate_purpose.rb', line 124

def child_plate_purposes
  child_purposes.where_is_a(PlatePurpose)
end

#create!(*args, &block) ⇒ Object


103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/models/plate_purpose.rb', line 103

def create!(*args, &block)
  attributes          = args.extract_options!
  do_not_create_wells = args.first.present?
  attributes[:size] ||= size
  attributes[:purpose] = self
  number = attributes.delete(:barcode)
  prefix = (attributes.delete(:barcode_prefix) || barcode_prefix).prefix
  attributes[:sanger_barcode] ||= { prefix: prefix, number: number }
  target_class.create_with_barcode!(attributes, &block).tap do |plate|
    plate.wells.construct! unless do_not_create_wells
  end
end

#input_plate=(is_input) ⇒ Object

Set the class to PlatePurpose::Input is set to true. Allows creation of the input plate purposes through the API without directly exposing our class names.

Parameters:

  • is_input (Bool)

    Set to true to assign the sti type to PlatePurpose::Input


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

def input_plate=(is_input)
  self.type = 'PlatePurpose::Input' if is_input
end

#plate_heightObject


54
55
56
# File 'app/models/plate_purpose.rb', line 54

def plate_height
  asset_shape.plate_height(size)
end

#plate_widthObject


58
59
60
# File 'app/models/plate_purpose.rb', line 58

def plate_width
  asset_shape.plate_width(size)
end

#pool_wells(wells) ⇒ Object


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

def pool_wells(wells)
  _pool_wells(wells)
    .joins('LEFT OUTER JOIN uuids AS pool_uuids ON pool_uuids.resource_type="Submission" AND pool_uuids.resource_id=submission_id')
    .select('pool_uuids.external_id AS pool_uuid')
    .readonly(false)
    .tap do |wells_with_pool|
      raise StandardError, 'Cannot deal with a well in multiple pools' if wells_with_pool.group_by(&:id).any? do |_, multiple_pools|
                                                                            multiple_pools.uniq.size > 1
                                                                          end
    end
end

#sizeObject


99
100
101
# File 'app/models/plate_purpose.rb', line 99

def size
  super || 96
end

#source_wells_for(stock_wells) ⇒ Object


128
129
130
# File 'app/models/plate_purpose.rb', line 128

def source_wells_for(stock_wells)
  stock_wells
end

#state_of(plate) ⇒ Object

The state of a plate is based on the transfer requests.


63
64
65
# File 'app/models/plate_purpose.rb', line 63

def state_of(plate)
  plate.state_from(plate.transfer_requests)
end