Class: Tube

Inherits:
Labware show all
Extended by:
QcFile::Associations
Includes:
Api::Messages::QcResultIo::TubeExtensions, Asset::Ownership::Unowned, Barcode::Barcodeable, ModelExtensions::Tube, SingleReceptacleLabware, Tag::Associations, Transfer::Associations, Transfer::State::TubeState
Defined in:
app/models/tube.rb

Overview

A Tube is a piece of Labware

Defined Under Namespace

Modules: AttributeUpdater Classes: Purpose, StandardMx, StockMx

Instance Attribute Summary

Attributes inherited from Labware

#storage_location_service

Class Method Summary collapse

Instance Method Summary collapse

Methods included from QcFile::Associations

has_qc_files

Methods included from SingleReceptacleLabware

#receptacle

Methods included from Transfer::State::TubeState

included

Methods included from Transfer::Associations

included

Methods included from Asset::Ownership::Unowned

#change_owner_to

Methods included from Tag::Associations

#untag!

Methods included from Barcode::Barcodeable

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

Methods inherited from Labware

#ancestor_of_purpose, #ancestors_of_purpose, #child, #display_name, #external_identifier, find_by_barcode, find_from_any_barcode, #generate_name, #labware, #labwhere_location, labwhere_locations, #parent, #received_date, #retention_instructions, #role, #scanned_in_date, #source_plate, #source_plates, #spiked_in_buffer, #state, #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

#ancestor_of_purpose, #asset_type_for_request_types, #barcode_number, #compatible_purposes, #contained_samples, #generate_barcode, #get_qc_result_value_for, #has_stock_asset?, #label, #label=, #original_stock_plates, #prefix, #printable?, #printable_target, #register_stock!, #request_types, #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

alias_association, convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Squishify

extended

Class Method Details

.create_with_barcode!(*args) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/models/tube.rb', line 86

def self.create_with_barcode!(*args, &)
  attributes = args.extract_options!.symbolize_keys

  barcode, prefix = extract_barcode(args, attributes)
  validate_barcode(barcode, prefix) if barcode.present?
  barcode ||= AssetBarcode.new_barcode

  # remove this so it's not passed in on creation, and set it explicitly afterwards
  # this is to control the order of barcode addition so that it gets set as the 'primary' barcode
  foreign_barcode = attributes.delete(:foreign_barcode)

  tube = create!(attributes.merge(sanger_barcode: { prefix: prefix, number: barcode }), &)

  tube.foreign_barcode = foreign_barcode if foreign_barcode
  tube.reload
end

.delegate_to_purpose(*methods) ⇒ Object

Delegates the provided methods to purpose, passing the tube as the first argument, and the remaining arguments as-is



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

def self.delegate_to_purpose(*methods)
  methods.each { |method| class_eval("def #{method}(*args, &block) ; purpose.#{method}(self, *args, &block) ; end") }
end

Instance Method Details

#after_comment_addition(comment) ⇒ Object



82
83
84
# File 'app/models/tube.rb', line 82

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

#barcode!Object



25
26
27
28
# File 'app/models/tube.rb', line 25

def barcode!
  self.sanger_barcode = { number: AssetBarcode.new_barcode, prefix: default_prefix } unless barcode_number
  save!
end

#commentsObject



32
33
34
# File 'app/models/tube.rb', line 32

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

#detailsObject



78
79
80
# File 'app/models/tube.rb', line 78

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

#name_for_child_tubeObject



70
71
72
# File 'app/models/tube.rb', line 70

def name_for_child_tube
  name
end

#name_for_labelObject



44
45
46
# File 'app/models/tube.rb', line 44

def name_for_label
  primary_sample&.shorten_sanger_sample_id.presence || name
end

#pool_idObject



40
41
42
# File 'app/models/tube.rb', line 40

def pool_id
  submissions.ids.first
end

#sanger_barcode=(attributes) ⇒ Object



74
75
76
# File 'app/models/tube.rb', line 74

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

#stock_platePlate

Returns the stock plate of the tube, behaviour delegated to purpose

Returns:

  • (Plate)

    The stock plate



66
# File 'app/models/tube.rb', line 66

delegate_to_purpose(:stock_plate)

#subject_typeObject



21
22
23
# File 'app/models/tube.rb', line 21

def subject_type
  'tube'
end

#submissionObject



36
37
38
# File 'app/models/tube.rb', line 36

def submission
  submissions.first
end