Class: LabwareCreators::PooledTubesFromWholePlates

Inherits:
Base
  • Object
show all
Includes:
CustomPage, SupportParent::TaggedPlateOnly
Defined in:
app/models/labware_creators/pooled_tubes_from_whole_plates.rb

Overview

Pools one or more plates into a single tube. Useful for MiSeqQC

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from LabwareCreators::Base

Instance Attribute Details

#barcodesObject

Returns the value of attribute barcodes.



8
9
10
# File 'app/models/labware_creators/pooled_tubes_from_whole_plates.rb', line 8

def barcodes
  @barcodes
end

#childObject (readonly)

Returns the value of attribute child.



8
9
10
# File 'app/models/labware_creators/pooled_tubes_from_whole_plates.rb', line 8

def child
  @child
end

#tube_transferObject (readonly)

Returns the value of attribute tube_transfer.



8
9
10
# File 'app/models/labware_creators/pooled_tubes_from_whole_plates.rb', line 8

def tube_transfer
  @tube_transfer
end

Instance Method Details

#available_platesObject

TODO: This should probably be asynchronous



46
47
48
49
# File 'app/models/labware_creators/pooled_tubes_from_whole_plates.rb', line 46

def available_plates
  @search_options = OngoingPlate.new(purposes: [parent.plate_purpose.uuid], include_used: false, states: ['passed'])
  @search_results = plate_search.all(Limber::Plate, @search_options.search_parameters)
end

#create_labware!Object

rubocop:todo Metrics/AbcSize



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/labware_creators/pooled_tubes_from_whole_plates.rb', line 16

def create_labware! # rubocop:todo Metrics/AbcSize
  # Create a single tube
  # TODO: This should link to multiple parents in production
  @child =
    api
      .specific_tube_creation
      .create!(
        user: user_uuid,
        parent: parents.first.uuid,
        child_purposes: [purpose_uuid],
        tube_attributes: [{ name: "#{stock_plate_barcode}+" }]
      )
      .children
      .first

  # Transfer EVERYTHING into it
  parents.each do |parent_plate|
    transfer_template.create!(user: user_uuid, source: parent_plate.uuid, destination: @child.uuid)
  end
end

#number_of_parent_labwaresObject



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

def number_of_parent_labwares
  # default to 4 if value not found in config
  purpose_config.fetch(:number_of_parent_labwares, 4)
end

#parentObject Originally defined in module SupportParent::TaggedPlateOnly

#parentsObject



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

def parents
  @parents ||=
    api.search.find(Settings.searches['Find assets by barcode']).all(Limber::BarcodedAsset, barcode: barcodes)
end

#parents_suitableObject



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

def parents_suitable
  missing_barcodes = barcodes - parents.map { |p| p.barcode.machine }
  return if missing_barcodes.empty?

  errors.add(:barcodes, "could not be found: #{missing_barcodes}")
end

#plate_searchObject



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

def plate_search
  api.search.find(Settings.searches['Find plates'])
end

#stock_plate_barcodeObject



41
42
43
# File 'app/models/labware_creators/pooled_tubes_from_whole_plates.rb', line 41

def stock_plate_barcode
  "#{parents.first.stock_plate.barcode.prefix}#{parents.first.stock_plate.barcode.number}"
end