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 Squishify

extended

Instance Method Details

#add_parent(parent) ⇒ Object


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

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


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

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.


88
89
90
# File 'app/models/asset.rb', line 88

def asset_type_for_request_types
  self.class
end

#assign_relationships(parents, child) ⇒ Object


117
118
119
120
121
122
123
# File 'app/models/asset.rb', line 117

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


151
152
153
# File 'app/models/asset.rb', line 151

def barcode_number
  nil
end

#compatible_purposesObject


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

def compatible_purposes
  Purpose.none
end

#contained_samplesObject


164
165
166
# File 'app/models/asset.rb', line 164

def contained_samples
  Sample.none
end

#detailsObject


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

def details
  nil
end

#external_identifierObject


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

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

#generate_barcodeObject

By default only barcodeable assets generate barcodes


160
161
162
# File 'app/models/asset.rb', line 160

def generate_barcode
  nil
end

#get_qc_result_value_for(key) ⇒ Object


198
199
200
# File 'app/models/asset.rb', line 198

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

#has_stock_asset?Boolean

Returns:

  • (Boolean)

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

def has_stock_asset?
  false
end

#labelObject


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

def label
  sti_type || 'Unknown'
end

#label=(new_type) ⇒ Object


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

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

#original_stock_platesObject


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

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

#prefixObject


155
156
157
# File 'app/models/asset.rb', line 155

def prefix
  nil
end

#printable?Boolean

Returns:

  • (Boolean)

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

def printable?
  printable_target.present?
end

#printable_targetObject


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

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 Called when importing samples, e.g. in sample_manifest > core_behaviour, on manifest upload


184
185
186
187
188
189
190
191
192
# File 'app/models/asset.rb', line 184

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

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

#request_typesObject


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

def request_types
  RequestType.where(asset_type: label)
end

#spiked_in_bufferObject


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

def spiked_in_buffer
  nil
end

#summary_hashObject


83
84
85
# File 'app/models/asset.rb', line 83

def summary_hash
  { asset_id: id }
end

#typeObject


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

def type
  self.class.name.underscore
end

#update_from_qc(qc_result) ⇒ Object


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

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