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

Methods included from Warren::BroadcastMessages

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

Instance Method Details

#add_parent(parent) ⇒ Object


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

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


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

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.


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

def asset_type_for_request_types
  self.class
end

#assign_relationships(parents, child) ⇒ Object


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

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


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

def barcode_number
  nil
end

#compatible_purposesObject


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

def compatible_purposes
  Purpose.none
end

#contained_samplesObject


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

def contained_samples
  Sample.none
end

#detailsObject


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

def details
  nil
end

#external_identifierObject


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

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

#generate_barcodeObject

By default only barcodeable assets generate barcodes


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

def generate_barcode
  nil
end

#get_qc_result_value_for(key) ⇒ Object


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

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

#has_stock_asset?Boolean

Returns:

  • (Boolean)

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

def has_stock_asset?
  false
end

#labelObject


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

def label
  sti_type || 'Unknown'
end

#label=(new_type) ⇒ Object


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

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

#original_stock_platesObject


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

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

#prefixObject


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

def prefix
  nil
end

#printable?Boolean

Returns:

  • (Boolean)

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

def printable?
  printable_target.present?
end

#printable_targetObject


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

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


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

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


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

def request_types
  RequestType.where(asset_type: label)
end

#spiked_in_bufferObject


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

def spiked_in_buffer
  nil
end

#summary_hashObject


80
81
82
83
84
# File 'app/models/asset.rb', line 80

def summary_hash
  {
    asset_id: id
  }
end

#typeObject


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

def type
  self.class.name.underscore
end

#update_from_qc(qc_result) ⇒ Object


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

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