Class: TubeRack
- Inherits:
-
Labware
- Object
- ActiveRecord::Base
- ApplicationRecord
- Asset
- Labware
- TubeRack
- Includes:
- Asset::Ownership::Unowned, Barcode::Barcodeable
- Defined in:
- app/models/tube_rack.rb
Overview
A rack that holds tubes Tubes are linked via the RackedTubes association
Defined Under Namespace
Classes: Purpose
Constant Summary collapse
- LAYOUTS =
{ 48 => { rows: 6, columns: 8 }, 96 => { rows: 8, columns: 12 } }.freeze
- TUBE_RACK_STATES =
%w[started qc_complete pending passed failed cancelled mixed empty].freeze
- STATES_TO_FILTER_OUT =
%w[cancelled failed].freeze
- STATE_EMPTY =
'empty'
- STATE_MIXED =
'mixed'
Instance Attribute Summary
Attributes inherited from Labware
Class Method Summary collapse
- .generate_valid_row_values(num_rows) ⇒ Object
- .invalid_coordinates(rack_size, list_coordinates) ⇒ Object
Instance Method Summary collapse
-
#after_comment_addition(comment) ⇒ Object
Handles the addition of a comment to the tube rack and its associated submissions and tubes.
-
#comments ⇒ Object
Comments are proxied as they need to collect comments from various different associations, not just the tubes.
-
#number_of_columns ⇒ Integer
(also: #width)
Returns the number of columns in the tube rack based on its size.
-
#number_of_rows ⇒ Integer
(also: #height)
Returns the number of rows in the tube rack based on its size.
-
#receptacles_with_position ⇒ ActiveRecord::Relation
Used to unify interface with TubeRacks.
-
#state ⇒ Object
The state of a tube rack is based on the transfer requests in the tubes.
Methods included from Asset::Ownership::Unowned
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, search_for_labware, #source_plate, #source_plates, #spiked_in_buffer, #storage_location
Methods included from SharedBehaviour::Named
Methods included from AssetLink::Associations
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, #details, #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
Class Method Details
.generate_valid_row_values(num_rows) ⇒ Object
59 60 61 |
# File 'app/models/tube_rack.rb', line 59 def self.generate_valid_row_values(num_rows) ('A'..).first(num_rows) end |
.invalid_coordinates(rack_size, list_coordinates) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/tube_rack.rb', line 46 def self.invalid_coordinates(rack_size, list_coordinates) num_rows = LAYOUTS.fetch(rack_size)[:rows] num_columns = LAYOUTS.fetch(rack_size)[:columns] valid_row_values = generate_valid_row_values(num_rows) valid_column_values = (1..num_columns) list_coordinates.reject do |coordinate| row = coordinate[/[A-Za-z]+/].capitalize column = coordinate[/[0-9]+/] valid_row_values.include?(row) && valid_column_values.cover?(column.to_i) end end |
Instance Method Details
#after_comment_addition(comment) ⇒ Object
Handles the addition of a comment to the tube rack and its associated submissions and tubes. Adds the comment to the submissions to avoid duplicate comments and also adds the comment to the tubes.
97 98 99 100 101 102 103 104 105 |
# File 'app/models/tube_rack.rb', line 97 def after_comment_addition(comment) # We don't let the tubes handle addition to submissions, as if they # all belong to the same submission, we'll get duplicate comments comments.add_comment_to_submissions(comment) # But we still want to add to the tube anyway, as we may have some # tubes that don't have submissions. Or even a mixed rack. comments.add_comment_to_tubes(comment) end |
#comments ⇒ Object
Comments are proxied as they need to collect comments from various different associations, not just the tubes
65 66 67 |
# File 'app/models/tube_rack.rb', line 65 def comments @comments ||= CommentsProxy::TubeRack.new(self) end |
#number_of_columns ⇒ Integer Also known as: width
Returns the number of columns in the tube rack based on its size.
88 89 90 |
# File 'app/models/tube_rack.rb', line 88 def number_of_columns LAYOUTS.fetch(size)[:columns] end |
#number_of_rows ⇒ Integer Also known as: height
Returns the number of rows in the tube rack based on its size.
80 81 82 |
# File 'app/models/tube_rack.rb', line 80 def number_of_rows LAYOUTS.fetch(size)[:rows] end |
#receptacles_with_position ⇒ ActiveRecord::Relation
Used to unify interface with TubeRacks. Returns a list of all receptacles with position information included for aid performance.
73 74 75 |
# File 'app/models/tube_rack.rb', line 73 def receptacles_with_position tube_receptacles.includes(:racked_tube) end |
#state ⇒ Object
The state of a tube rack is based on the transfer requests in the tubes. If they are all in the same state then it takes that state.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/models/tube_rack.rb', line 109 def state # fetch states from ther transfer requests in all racked tubes in the rack. unique_states = transfer_requests_as_target.map(&:state).uniq return STATE_EMPTY if unique_states.empty? return unique_states.first if unique_states.size == 1 STATES_TO_FILTER_OUT.each do |filter| unique_states.delete(filter) return unique_states.first if unique_states.one? end # we still have tubes with a mixed state STATE_MIXED end |