Class: PlatePurpose

Inherits:
Purpose show all
Includes:
Api::PlatePurposeIO::Extensions, Purpose::Relationship::Associations
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 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 included from SharedBehaviour::Named

included

Methods inherited from ApplicationRecord

convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Squishify

extended

Class Method Details

.stock_plate_purposeObject


91
92
93
# File 'app/models/plate_purpose.rb', line 91

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


35
36
37
# File 'app/models/plate_purpose.rb', line 35

def asset_shape
  super || AssetShape.default
end

#attatched?(_plate) ⇒ Boolean

Returns:

  • (Boolean)

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

def attatched?(_plate)
  true
end

#cherrypick_completed(plate) ⇒ Object


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

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

#cherrypick_in_rows?Boolean

Returns:

  • (Boolean)

112
113
114
# File 'app/models/plate_purpose.rb', line 112

def cherrypick_in_rows?
  cherrypick_direction == 'row'
end

#child_plate_purposesObject


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

def child_plate_purposes
  child_purposes.where_is_a(PlatePurpose)
end

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

rubocop:todo Metrics/AbcSize


99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/models/plate_purpose.rb', line 99

def create!(*args, &block) # rubocop:todo Metrics/AbcSize
  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 { |plate| plate.wells.construct! unless do_not_create_wells }
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


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

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

#plate_heightObject


46
47
48
# File 'app/models/plate_purpose.rb', line 46

def plate_height
  asset_shape.plate_height(size)
end

#plate_widthObject


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

def plate_width
  asset_shape.plate_width(size)
end

#pool_wells(wells) ⇒ Object

rubocop:todo Metrics/MethodLength


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/models/plate_purpose.rb', line 68

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

#sizeObject


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

def size
  super || 96
end

#source_wells_for(stock_wells) ⇒ Object


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

def source_wells_for(stock_wells)
  stock_wells
end

#state_of(plate) ⇒ Object

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


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

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