Class: Well
- Inherits:
-
Receptacle
- Object
- ActiveRecord::Base
- ApplicationRecord
- Asset
- Receptacle
- Well
- Includes:
- Api::Messages::FluidigmPlateIo::WellExtensions, Api::Messages::QcResultIo::WellExtensions, Api::WellIo::Extensions, Cherrypick::VolumeByMicroLitre, Cherrypick::VolumeByNanoGrams, Cherrypick::VolumeByNanoGramsPerMicroLitre, ModelExtensions::Well, StudyReport::WellDetails, Tag::Associations
- Defined in:
- app/models/well.rb
Overview
A Well is a Receptacle on a Plate, it can contain one or more aliquots. A plate may have multiple wells, with the two most common sizes being 128 (96) and 2426 (384). The wells are differentiated via their Map which corresponds to a row and column. Most well locations are identified by a letter-number combination, eg. A1, H12.
Defined Under Namespace
Modules: AttributeUpdater Classes: Link
Constant Summary
Constants inherited from Receptacle
Constants included from Transfer::State
Class Method Summary collapse
- .delegate_to_well_attribute(attribute, options = {}) ⇒ Object
- .hash_stock_with_targets(wells, purpose_names) ⇒ Object
- .writer_for_well_attribute_as_float(attribute) ⇒ Object
Instance Method Summary collapse
-
#absolute_position_name ⇒ Object
Returns the name of the position (eg. A1) of the well.
- #asset_type_for_request_types ⇒ Object
- #buffer_required? ⇒ Boolean
- #details ⇒ Object
-
#display_name ⇒ Object
Returns a name for the well in the format HumanBarcode:Location eg.
- #external_identifier ⇒ Object
- #generate_name(_) ⇒ Object
-
#get_sequenom_pass ⇒ Object
The sequenom pass value is either the string 'Unknown' or it is the combination of gender marker values.
- #latest_stock_metrics(product) ⇒ Object
- #library_name ⇒ Object
- #name ⇒ Object
- #outer_request(submission_id) ⇒ Object
-
#poly_metadata ⇒ ActiveRecord::Relation
Returns a collection of PolyMetadatum records associated with the Well.
- #qc_data ⇒ Object
- #qc_result_for(key) ⇒ Object
- #qc_results_by_key ⇒ Object
- #stock_wells_for_downstream_wells ⇒ Object
- #subject_type ⇒ Object
- #update_from_qc(qc_result) ⇒ Object
-
#update_gender_markers!(gender_markers, resource) ⇒ Object
rubocop:todo Metrics/MethodLength.
-
#update_sequenom_count!(sequenom_count, resource) ⇒ Object
rubocop:enable Metrics/MethodLength.
- #update_volume(volume_change) ⇒ Object
- #well_attribute ⇒ Object
Methods included from Tag::Associations
Methods included from StudyReport::WellDetails
Methods included from Cherrypick::VolumeByMicroLitre
#volume_to_cherrypick_by_micro_litre
Methods included from Cherrypick::VolumeByNanoGramsPerMicroLitre
#volume_to_cherrypick_by_nano_grams_per_micro_litre
Methods included from Cherrypick::VolumeByNanoGrams
#volume_to_cherrypick_by_nano_grams
Methods included from Api::WellIo::Extensions
Methods inherited from Receptacle
#any_barcode_matching?, #api_asset_type, #assign_tag2, #attach_tag, #been_through_qc?, #compatible_qc_state, #created_with_request_options, #friendly_name, #labware_comment_count, #legacy_asset_type, #library_information, #library_types, #most_recent_requests_as_target_group_by_same_source, #primary_aliquot_if_unique, #related_studies, #role, #set_as_library, #set_qc_state, #tag_range, #total_comment_count, #update_aliquot_quality
Methods included from Receptacle::DownstreamAliquotsRemoval::Mixin
#allow_to_remove_downstream_aliquots?
Methods included from StudyReport::AssetDetails
Methods included from Aliquot::Remover
#on_downstream_aliquots, #process_aliquots, #remove_downstream_aliquots, #remove_matching_aliquots
Methods included from Transfer::State
#default_state, #state, #state_from, state_helper
Methods included from Commentable
Methods included from Uuid::Uuidable
included, #unsaved_uuid!, #uuid
Methods inherited from Asset
#ancestor_of_purpose, #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
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
.delegate_to_well_attribute(attribute, options = {}) ⇒ Object
178 179 180 181 182 183 184 |
# File 'app/models/well.rb', line 178 def delegate_to_well_attribute(attribute, = {}) class_eval <<-END_OF_METHOD_DEFINITION def get_#{attribute} self.well_attribute.#{attribute} || #{[:default].inspect} end END_OF_METHOD_DEFINITION end |
.hash_stock_with_targets(wells, purpose_names) ⇒ Object
194 195 196 197 198 199 200 201 202 203 |
# File 'app/models/well.rb', line 194 def hash_stock_with_targets(wells, purpose_names) return {} unless purpose_names purposes = PlatePurpose.where(name: purpose_names) # We might need to be careful about this line in future. target_wells = Well.target_wells_for(wells).on_plate_purpose(purposes).preload(:well_attribute).with_concentration target_wells.group_by(&:stock_well_id) end |
.writer_for_well_attribute_as_float(attribute) ⇒ Object
186 187 188 189 190 191 192 |
# File 'app/models/well.rb', line 186 def writer_for_well_attribute_as_float(attribute) class_eval <<-END_OF_METHOD_DEFINITION def set_#{attribute}(value) self.well_attribute.update!(:#{attribute} => value.to_f) end END_OF_METHOD_DEFINITION end |
Instance Method Details
#absolute_position_name ⇒ Object
Returns the name of the position (eg. A1) of the well
320 321 322 |
# File 'app/models/well.rb', line 320 def absolute_position_name map_description end |
#asset_type_for_request_types ⇒ Object
358 359 360 |
# File 'app/models/well.rb', line 358 def asset_type_for_request_types self.class end |
#buffer_required? ⇒ Boolean
328 329 330 |
# File 'app/models/well.rb', line 328 def buffer_required? get_buffer_volume > 0.0 end |
#details ⇒ Object
345 346 347 348 349 |
# File 'app/models/well.rb', line 345 def details return 'Not yet picked' if plate.nil? plate.purpose.try(:name) || 'Unknown plate purpose' end |
#display_name ⇒ Object
Be very wary of changing this as we have places in limber (github.com/sanger/limber/blob/develop/app/helpers/exports_helper.rb) where it is assumed to contain the barcode and well location. It is highly likely that we aren't the only ones making this assumption.
Returns a name for the well in the format HumanBarcode:Location eg. DN12345S:A1
338 339 340 341 342 343 |
# File 'app/models/well.rb', line 338 def display_name source = association_cached?(:plate) ? plate : labware plate_name = source.present? ? source. : '(not on a plate)' plate_name ||= source.display_name # In the even the plate is barcodeless (ie strip tubes) use its name "#{plate_name}:#{map_description}" end |
#external_identifier ⇒ Object
241 242 243 |
# File 'app/models/well.rb', line 241 def external_identifier display_name end |
#generate_name(_) ⇒ Object
237 238 239 |
# File 'app/models/well.rb', line 237 def generate_name(_) # Do nothing end |
#get_sequenom_pass ⇒ Object
The sequenom pass value is either the string 'Unknown' or it is the combination of gender marker values.
314 315 316 317 |
# File 'app/models/well.rb', line 314 def get_sequenom_pass markers = well_attribute.gender_markers markers.is_a?(Array) ? markers.join : markers end |
#latest_stock_metrics(product) ⇒ Object
351 352 353 354 355 356 |
# File 'app/models/well.rb', line 351 def latest_stock_metrics(product) # If we don't have any stock wells, use ourself. If it is a stock well, we'll find our # qc metric. If its not a stock well, then a metric won't be present anyway metric_wells = stock_wells.empty? ? [self] : stock_wells metric_wells.filter_map { |stock_well| stock_well.qc_metrics.for_product(product).most_recent_first.first }.uniq end |
#library_name ⇒ Object
370 371 372 |
# File 'app/models/well.rb', line 370 def library_name nil end |
#name ⇒ Object
366 367 368 |
# File 'app/models/well.rb', line 366 def name nil end |
#outer_request(submission_id) ⇒ Object
214 215 216 |
# File 'app/models/well.rb', line 214 def outer_request(submission_id) outer_requests.order(id: :desc).find_by(submission_id:) end |
#poly_metadata ⇒ ActiveRecord::Relation
Returns a collection of PolyMetadatum records associated with the Well. This method overrides the autogenerated poly_metadata method to pick the correct metadatable_type instead of the parent type. Without this override, the generated SQL uses the wrong class name, e.g. Receptacle instead of Well.
60 61 62 |
# File 'app/models/well.rb', line 60 def PolyMetadatum.where(metadatable_id: id, metadatable_type: self.class.name) end |
#qc_data ⇒ Object
324 325 326 |
# File 'app/models/well.rb', line 324 def qc_data { pico: get_pico_pass, gel: get_gel_pass, sequenom: get_sequenom_pass, concentration: get_concentration } end |
#qc_result_for(key) ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'app/models/well.rb', line 222 def qc_result_for(key) result = if key == 'quantity_in_nano_grams' well_attribute.quantity_in_nano_grams else results = qc_results_by_key[key] results.first.value if results.present? end return if result.nil? return result.to_f.round(3) if result.to_s.include?('.') result.to_i end |
#qc_results_by_key ⇒ Object
218 219 220 |
# File 'app/models/well.rb', line 218 def qc_results_by_key @qc_results_by_key ||= qc_results.by_key end |
#stock_wells_for_downstream_wells ⇒ Object
206 207 208 |
# File 'app/models/well.rb', line 206 def stock_wells_for_downstream_wells labware&.stock_plate? ? [self] : stock_wells end |
#subject_type ⇒ Object
210 211 212 |
# File 'app/models/well.rb', line 210 def subject_type 'well' end |
#update_from_qc(qc_result) ⇒ Object
362 363 364 |
# File 'app/models/well.rb', line 362 def update_from_qc(qc_result) Well::AttributeUpdater.update(self, qc_result) end |
#update_gender_markers!(gender_markers, resource) ⇒ Object
rubocop:todo Metrics/MethodLength
291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'app/models/well.rb', line 291 def update_gender_markers!(gender_markers, resource) # rubocop:todo Metrics/AbcSize if well_attribute.gender_markers == gender_markers gender_marker_event = events.where(family: 'update_gender_markers').order('id desc').first if gender_marker_event.blank? events.update_gender_markers!(resource) elsif resource == 'SNP' && gender_marker_event.content != resource events.update_gender_markers!(resource) end else events.update_gender_markers!(resource) end well_attribute.update!(gender_markers:) end |
#update_sequenom_count!(sequenom_count, resource) ⇒ Object
rubocop:enable Metrics/MethodLength
308 309 310 311 |
# File 'app/models/well.rb', line 308 def update_sequenom_count!(sequenom_count, resource) events.update_sequenom_count!(resource) unless well_attribute.sequenom_count == sequenom_count well_attribute.update!(sequenom_count:) end |
#update_volume(volume_change) ⇒ Object
268 269 270 271 |
# File 'app/models/well.rb', line 268 def update_volume(volume_change) value_current_volume = get_current_volume.nil? ? 0 : get_current_volume set_current_volume([0, value_current_volume + volume_change].max) end |
#well_attribute ⇒ Object
245 246 247 |
# File 'app/models/well.rb', line 245 def well_attribute super || build_well_attribute end |