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

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


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

def self.create_with_barcode!(*args, &block)
  attributes = args.extract_options!
  barcode    = args.first || attributes.delete(:barcode)
  prefix     = attributes.delete(:barcode_prefix)&.prefix || default_prefix
  if barcode.present?
    human = SBCF::SangerBarcode.new(prefix: prefix, number: barcode).human_barcode
    raise "Barcode: #{barcode} already used!" if Barcode.exists?(barcode: human)
  end
  barcode ||= AssetBarcode.new_barcode
  primary_barcode = { prefix: prefix, number: barcode }
  create!(attributes.merge(sanger_barcode: primary_barcode), &block)
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


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

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

Instance Method Details

#after_comment_addition(comment) ⇒ Object


85
86
87
# File 'app/models/tube.rb', line 85

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

#barcode!Object


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

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

#commentsObject


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

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

#detailsObject


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

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

#name_for_child_tubeObject


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

def name_for_child_tube
  name
end

#name_for_labelObject


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

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

#pool_idObject


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

def pool_id
  submissions.ids.first
end

#sanger_barcode=(attributes) ⇒ Object


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

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


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

delegate_to_purpose(:stock_plate)

#subject_typeObject


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

def subject_type
  'tube'
end

#submissionObject


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

def submission
  submissions.first
end