Class: Asset

Inherits:
ApplicationRecord show all
Extended by:
EventfulRecord
Includes:
Api::Messages::QcResultIO::AssetExtensions, Event::PlateEvents
Defined in:
app/models/asset.rb

Overview

Asset is a very busy class which combines what should probably be two separate concepts: Labware: A physical item which can move round the lab, such as a Plate or Tube

Key subclasses


  • Receptacle: Something which can contain aliquots, such as a Well or Tube Currently those these all share a table, and exhibit single table inheritance.

  • Plate: A piece of labware containing multiple receptacles known as wells. Plates can be a variety of shapes and sizes, although the marority are 12*8 (96) or 24*16 (384) wells in size.

  • Well: A receptacle on a plate. Wells themselves do not exist independently of plates in reality, although may occasionally be modelled as such.

  • Tube: A piece of labware with a single Receptacle. These behaviours are currently coupled together.

  • Lane: Forms part of a sequencing Flowcell. The flowcell itself is not currently modelled but can be approximated by a Batch

  • Fragment: Represents an isolated segment of DNA on a Gel. Historical.

  • Receptacle: Abstract class inherited by any asset which can contain stuff directly

Some of the above are further subclasses to handle specific behaviours.

Direct Known Subclasses

Labware

Defined Under Namespace

Modules: ApplyIdToNameOnCreate, Ownership, SharedLibraryTubeBehaviour, Stock Classes: Finder

Instance Method Summary collapse

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 Warren::BroadcastMessages

#broadcast, included, #queue_associated_for_broadcast, #queue_for_broadcast, #warren

Instance Method Details

#add_parent(parent) ⇒ Object


149
150
151
152
153
154
155
156
# File 'app/models/asset.rb', line 149

def add_parent(parent)
  return unless parent

  # should be self.parents << parent but that doesn't work
  save!
  parent.save!
  AssetLink.create_edge!(parent, self)
end

#ancestor_of_purpose(_ancestor_purpose_id) ⇒ Object


112
113
114
115
# File 'app/models/asset.rb', line 112

def ancestor_of_purpose(_ancestor_purpose_id)
  # If it's not a tube or a plate, defaults to stock_plate
  stock_plate
end

#asset_type_for_request_typesObject

Returns the type of asset that can be considered appropriate for request types.


108
109
110
# File 'app/models/asset.rb', line 108

def asset_type_for_request_types
  self.class
end

#assign_relationships(parents, child) ⇒ Object


141
142
143
144
145
146
147
# File 'app/models/asset.rb', line 141

def assign_relationships(parents, child)
  parents.each do |parent|
    parent.children.delete(child)
    AssetLink.create_edge(parent, self)
  end
  AssetLink.create_edge(self, child)
end

#barcode_numberObject

Most assets don't have a barcode


175
176
177
# File 'app/models/asset.rb', line 175

def barcode_number
  nil
end

#compatible_purposesObject


170
171
172
# File 'app/models/asset.rb', line 170

def compatible_purposes
  Purpose.none
end

#contained_samplesObject


188
189
190
# File 'app/models/asset.rb', line 188

def contained_samples
  Sample.none
end

#detailsObject


137
138
139
# File 'app/models/asset.rb', line 137

def details
  nil
end

#external_identifierObject


133
134
135
# File 'app/models/asset.rb', line 133

def external_identifier
  "#{sti_type}#{id}"
end

#generate_barcodeObject

By default only barcodeable assets generate barcodes


184
185
186
# File 'app/models/asset.rb', line 184

def generate_barcode
  nil
end

#get_qc_result_value_for(key) ⇒ Object


222
223
224
# File 'app/models/asset.rb', line 222

def get_qc_result_value_for(key)
  last_qc_result_for(key).pluck(:value).first
end

#has_stock_asset?Boolean

Returns:

  • (Boolean)

166
167
168
# File 'app/models/asset.rb', line 166

def has_stock_asset?
  false
end

#labelObject


117
118
119
# File 'app/models/asset.rb', line 117

def label
  sti_type || 'Unknown'
end

#label=(new_type) ⇒ Object


121
122
123
# File 'app/models/asset.rb', line 121

def label=(new_type)
  self.sti_type = new_type
end

#original_stock_platesObject


158
159
160
# File 'app/models/asset.rb', line 158

def original_stock_plates
  ancestors.where(plate_purpose_id: PlatePurpose.stock_plate_purpose)
end

#prefixObject


179
180
181
# File 'app/models/asset.rb', line 179

def prefix
  nil
end

#printable?Boolean

Returns:

  • (Boolean)

196
197
198
# File 'app/models/asset.rb', line 196

def printable?
  printable_target.present?
end

#printable_targetObject


200
201
202
# File 'app/models/asset.rb', line 200

def printable_target
  nil
end

#register_stock!Object

Generates a message to broadcast the tube to the stock warehouse tables. Raises an exception if no template is configured for a give asset. In most cases this is because the asset is not a stock

Raises:

  • (StandardError)

211
212
213
214
215
216
# File 'app/models/asset.rb', line 211

def register_stock!
  class_name = self.class.name
  raise StandardError, "No stock template configured for #{class_name}. If #{class_name} is a stock, set stock_template on the class." if stock_message_template.nil?

  Messenger.create!(target: self, template: stock_message_template, root: 'stock_resource')
end

#request_typesObject


125
126
127
# File 'app/models/asset.rb', line 125

def request_types
  RequestType.where(asset_type: label)
end

#roleObject


129
130
131
# File 'app/models/asset.rb', line 129

def role
  stock_plate&.stock_role
end

#source_plateObject


192
193
194
# File 'app/models/asset.rb', line 192

def source_plate
  nil
end

#spiked_in_bufferObject


162
163
164
# File 'app/models/asset.rb', line 162

def spiked_in_buffer
  nil
end

#summary_hashObject


101
102
103
104
105
# File 'app/models/asset.rb', line 101

def summary_hash
  {
    asset_id: id
  }
end

#typeObject


204
205
206
# File 'app/models/asset.rb', line 204

def type
  self.class.name.underscore
end

#update_from_qc(qc_result) ⇒ Object


218
219
220
# File 'app/models/asset.rb', line 218

def update_from_qc(qc_result)
  Rails.logger.info "#{self.class.name} #{id} updated by QcResult #{qc_result.id}"
end