Class: Aliquot

Inherits:
ApplicationRecord show all
Includes:
Uuidable
Defined in:
app/models/aliquot.rb

Overview

A portion of a sample that is used for a library, sample or pool. An aliquot can be a primary aliquot or a derived aliquot. An aliquot can be used to track volumes and concentrations of samples.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Uuidable

#add_uuid

Class Method Details

.publishableObject

Returns a list of all the aliquots that are publishable.



97
98
99
100
101
102
103
# File 'app/models/aliquot.rb', line 97

def self.publishable
  [].tap do |aliquots|
    filtered_aliquots = filter_by_publishable.to_a
    aliquots.concat(filtered_aliquots)
    aliquots.concat(used_by_well_library_aliquots(filtered_aliquots))
  end
end

.used_by_well_library_aliquots(aliquots) ⇒ Object

Find aliquots from a Pacbio::Pool used by a Pacbio::Well and add their source's used aliquots if from a Pacbio::Library



107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/models/aliquot.rb', line 107

def self.used_by_well_library_aliquots(aliquots)
  well_aliquots = aliquots.select do |aliquot|
    aliquot.source_type == 'Pacbio::Pool' && aliquot.used_by_type == 'Pacbio::Well'
  end
  [].tap do |library_aliquots|
    well_aliquots.each do |aliquot|
      library_aliquots.concat(aliquot.source.used_aliquots.select do |used_aliquot|
        used_aliquot.source_type == 'Pacbio::Library'
      end)
    end
  end
end

Instance Method Details

#adapterObject

Sample Adapter field The same adapter is used for both left and right, see same_barcodes_on_both_ends_of_sequence Returns nil if the tag is nil



174
175
176
# File 'app/models/aliquot.rb', line 174

def adapter
  tag&.group_id
end

#barcode_nameObject

Barcode Name field Deprecated as of SMRT-Link v13.0 See https://www.pacb.com/wp-content/uploads/SMRT-Link-Release-Notes-v13.0.pdf



165
166
167
168
169
# File 'app/models/aliquot.rb', line 165

def barcode_name
  return if tag_set.hidden_sample_sheet_behaviour?

  "#{tag.group_id}--#{tag.group_id}"
end

#bio_sample_nameObject

Sample bio Name field



149
150
151
152
153
# File 'app/models/aliquot.rb', line 149

def bio_sample_name
  return '' if tag_set.hidden_sample_sheet_behaviour?

  source.sample_name || ''
end

#check_available_parent_volumeObject

Checks the derived aliquot does not exceed the available volume of the source See models/multi_pool.rb sufficient_library_used_volume? for additional edge case checks



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/aliquot.rb', line 45

def check_available_parent_volume
  # Some sources may not have a primary aliquot, e.g. a Pacbio::Request, so we only want to check
  # the volume if there is a primary aliquot to check against
  return unless aliquot_type == 'derived' && source&.primary_aliquot&.volume

  # For persisted records, add back the previous volume to avoid double subtraction
  previous_volume = persisted? ? volume_was : 0
  adjusted_available_volume = source.available_volume + previous_volume

  if adjusted_available_volume - volume < 0
    # We add the source barcode to the error message to make it easier for the user to identify
    errors.add(:volume, "Insufficient volume available for #{source.barcode}")
    return false
  end
  true
end

#collection?Boolean

Generic method used by pacbio sample sheet generation to determine whether the data is a collection or not. Assuming false is a simplification used previously for sample-sheets

Returns:

  • (Boolean)


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

def collection?
  false
end

#formatted_bio_sample_nameObject

Returns the formatted bio sample name. Replaces all colons (:) in the bio sample name with hyphens (-).



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

def formatted_bio_sample_name
  bio_sample_name.gsub(':', '-')
end

#primary_aliquot_volume_sufficientnil, ...

This method is used to validate the volume of the primary aliquot. It is typically used as a callback before updating a library/pool record.

The method performs the following checks:

  1. If the primary aliquot has not changed its volume, the method returns immediately without performing any further checks.
  2. If the volume of the primary aliquot is greater than or equal to the used volume, the method returns true.
  3. If the volume of the primary aliquot is less than the used volume, the method adds an error to the library record and aborts the update operation.

false if the volume of the primary aliquot is less than the used volume.

Returns:

  • (nil, true, false)

    Returns nil if the primary aliquot has not changed its volume, true if the volume of the primary aliquot is greater than or equal to the used volume, and



76
77
78
79
80
81
82
# File 'app/models/aliquot.rb', line 76

def primary_aliquot_volume_sufficient
  return unless aliquot_type == 'primary' && source && volume
  return true if volume >= source.used_volume

  errors.add(:volume, 'must be greater than the current used volume')
  false
end

#tag_setObject

Returns the tag set for the aliquot If the tag_set is nil, it returns a NullTagSet



122
123
124
# File 'app/models/aliquot.rb', line 122

def tag_set
  super || NullTagSet.new
end

#tagged?Boolean

Checks if the aliquot is tagged. An aliquot is considered tagged if it has a non-nil and non-empty tag.

Returns:

  • (Boolean)

    Returns true if the aliquot is tagged, false otherwise.



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

def tagged?
  # This feels like a bit of a hack but I wasn't exactly sure where the best place to
  # it. I tried to follow the sample sheet behaviour but got lost.
  # it looks like the only place this is used is in the sample sheet generation
  return false if tag.nil?

  tag_set.default_sample_sheet_behaviour?
end