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

This class has now been split into two and should be eliminated.

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, Receptacle

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


132
133
134
135
136
137
138
139
# File 'app/models/asset.rb', line 132

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


95
96
97
98
# File 'app/models/asset.rb', line 95

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.


91
92
93
# File 'app/models/asset.rb', line 91

def asset_type_for_request_types
  self.class
end

#assign_relationships(parents, child) ⇒ Object


124
125
126
127
128
129
130
# File 'app/models/asset.rb', line 124

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


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

def barcode_number
  nil
end

#compatible_purposesObject


153
154
155
# File 'app/models/asset.rb', line 153

def compatible_purposes
  Purpose.none
end

#contained_samplesObject


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

def contained_samples
  Sample.none
end

#detailsObject


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

def details
  nil
end

#external_identifierObject


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

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

#generate_barcodeObject

By default only barcodeable assets generate barcodes


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

def generate_barcode
  nil
end

#get_qc_result_value_for(key) ⇒ Object


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

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

#has_stock_asset?Boolean

Returns:

  • (Boolean)

149
150
151
# File 'app/models/asset.rb', line 149

def has_stock_asset?
  false
end

#labelObject


100
101
102
# File 'app/models/asset.rb', line 100

def label
  sti_type || 'Unknown'
end

#label=(new_type) ⇒ Object


104
105
106
# File 'app/models/asset.rb', line 104

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

#original_stock_platesObject


141
142
143
# File 'app/models/asset.rb', line 141

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

#prefixObject


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

def prefix
  nil
end

#printable?Boolean

Returns:

  • (Boolean)

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

def printable?
  printable_target.present?
end

#printable_targetObject


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

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)

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

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


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

def request_types
  RequestType.where(asset_type: label)
end

#roleObject


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

def role
  stock_plate&.stock_role
end

#source_plateObject


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

def source_plate
  nil
end

#spiked_in_bufferObject


145
146
147
# File 'app/models/asset.rb', line 145

def spiked_in_buffer
  nil
end

#summary_hashObject


84
85
86
87
88
# File 'app/models/asset.rb', line 84

def summary_hash
  {
    asset_id: id
  }
end

#typeObject


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

def type
  self.class.name.underscore
end

#update_from_qc(qc_result) ⇒ Object


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

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