Class: Receptacle

Inherits:
Object
  • Object
show all
Includes:
Aliquot::Remover, StudyReport::AssetDetails, Transfer::State
Defined in:
app/models/receptacle.rb

Overview

A receptacle is a container for aliquots, they are associated with Labware, which represents the physical object which moves round the lab. A Labware may have a single Receptacle, such as in the case of a Tube or multiple, in the case of a Plate. Work can be requested on a particular receptacle.

Direct Known Subclasses

Lane, Qc, Well

Defined Under Namespace

Classes: Qc

Constant Summary collapse

QC_STATE_ALIASES =
{
  'passed' => 'pass',
  'failed' => 'fail'
}.freeze

Constants included from Transfer::State

Transfer::State::ALL_STATES

Instance Method Summary collapse

Methods included from StudyReport::AssetDetails

#qc_report

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

Instance Method Details

#api_asset_typeObject

Compatibility for v1 API maintains legacy 'type' for assets


286
287
288
# File 'app/models/receptacle.rb', line 286

def api_asset_type
  legacy_asset_type.tableize
end

#assign_tag2(tag) ⇒ Object


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

def assign_tag2(tag)
  aliquots.each do |aliquot|
    aliquot.tag2 = tag
    aliquot.save!
  end
end

#attach_tag(tag, tag2 = nil) ⇒ Object Also known as: attach_tags

Raises:

  • (StandardError)

243
244
245
246
247
248
249
250
# File 'app/models/receptacle.rb', line 243

def attach_tag(tag, tag2 = nil)
  tags = { tag: tag, tag2: tag2 }.compact
  return if tags.empty?
  raise StandardError, 'Cannot tag an empty asset'   if aliquots.empty?
  raise StandardError, 'Cannot tag multiple samples' if aliquots.size > 1

  aliquots.first.update!(tags)
end

#been_through_qc?Boolean

Returns:

  • (Boolean)

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

def been_through_qc?
  qc_state.present?
end

#compatible_qc_stateObject


191
192
193
# File 'app/models/receptacle.rb', line 191

def compatible_qc_state
  QC_STATE_ALIASES.fetch(qc_state, qc_state) || ''
end

#created_with_request_optionsObject


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

def created_with_request_options
  aliquots.first&.created_with_request_options || {}
end

#latest_stock_metrics(_product, *_args) ⇒ Object

We only support wells for the time being


257
258
259
# File 'app/models/receptacle.rb', line 257

def latest_stock_metrics(_product, *_args)
  []
end

#legacy_asset_typeObject

Compatibility for v1 API maintains legacy 'type' for assets


291
292
293
# File 'app/models/receptacle.rb', line 291

def legacy_asset_type
  labware.sti_type
end

#library_informationObject


209
# File 'app/models/receptacle.rb', line 209

def library_information; end

#library_typesObject

Library types are still just a string on aliquot.


223
224
225
# File 'app/models/receptacle.rb', line 223

def library_types
  aliquots.pluck(:library_type).uniq
end

#outer_request(submission_id) ⇒ Object


234
235
236
# File 'app/models/receptacle.rb', line 234

def outer_request(submission_id)
  transfer_requests_as_target.find_by(submission_id: submission_id).try(:outer_request)
end

#primary_aliquot_if_uniqueObject


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

def primary_aliquot_if_unique
  primary_aliquot if aliquots.count == 1
end

All studies related to this asset


239
240
241
# File 'app/models/receptacle.rb', line 239

def related_studies
  (ordered_studies + studies).compact.uniq
end

#set_as_libraryObject


227
228
229
230
231
232
# File 'app/models/receptacle.rb', line 227

def set_as_library
  aliquots.each do |aliquot|
    aliquot.set_library
    aliquot.save!
  end
end

#set_qc_state(state) ⇒ Object


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

def set_qc_state(state)
  self.qc_state = QC_STATE_ALIASES.key(state) || state
  save
  set_external_release(qc_state)
end

#tag_rangeString?

Returns the map_id of the first and last tag in an asset eg 1-96. Caution: Used on barcode labels. Avoid using elsewhere as makes assumptions

about tag behaviour which may change shortly.

Returns:

  • (String, nil)

    Returns nil is no tags, the map_id is a single tag, or the first and last map id separated by a hyphen if multiple tags.


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

def tag_range
  map_ids = tags.order(:map_id).pluck(:map_id)
  case map_ids.length
  when 0; then nil
  when 1; then map_ids.first
  else "#{map_ids.first}-#{map_ids.last}"
  end
end

#update_aliquot_quality(suboptimal_quality) ⇒ Object


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

def update_aliquot_quality(suboptimal_quality)
  aliquots.each { |a| a.update_quality(suboptimal_quality) }
  true
end