Class: Pacbio::Run

Inherits:
ApplicationRecord show all
Includes:
Stateful, Uuidable
Defined in:
app/models/pacbio/run.rb

Overview

Pacbio::Run

Constant Summary collapse

NAME_PREFIX =
'TRACTION-RUN-'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Uuidable

#add_uuid

Instance Attribute Details

#plates_attributesObject (readonly)

This will return an empty list If plate/well data is required via the run, use ?include=plates.wells



48
49
50
# File 'app/models/pacbio/run.rb', line 48

def plates_attributes
  @plates_attributes
end

Instance Method Details

#adaptive_loadingBoolean

Returns true if all wells have adaptive loading enabled.

Returns:

  • (Boolean)

    true if all wells have adaptive loading enabled



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

def adaptive_loading
  wells.all? { |w| w.use_adaptive_loading == 'True' }
end

#aliquots_to_publish_on_runArray

Collects and returns a list of aliquots to be published during a run.

It iterates over all plates associated with the run, and for each plate, it collects

the used aliquots from the wells. It also collects the used aliquots from the wells that have a source type of ‘Pacbio::Pool’ and further collects the used aliquots from these pools that have a source type of ‘Pacbio::Library’. and aliquots that have a source of ‘Pacbio::Library’ within those pools.

Returns:

  • (Array)

    An array of aliquots that are either sourced from Pacbio::Pool,Pacbio::Library



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/models/pacbio/run.rb', line 95

def aliquots_to_publish_on_run
  [].tap do |to_publish|
    plates.flat_map do |plate|
      # Collect all used aliquots from the plate
      used_aliquots = plate.wells.flat_map(&:used_aliquots)
      # Collect all used aliquots from the plate that have a source of 'Pacbio::Pool'
      used_aliquots_pool_source = used_aliquots
                                  .select { |aliquot| aliquot.source_type == 'Pacbio::Pool' }
      # Aggregate all used aliquots from the plate and used aliquots from the pool with
      # a source of 'Pacbio::Library'
      to_publish.concat(used_aliquots,
                        used_aliquots_lib_source_in_pool(used_aliquots_pool_source))
    end
  end
end

#generate_barcodes_and_concentrationsObject

combines the library concentration or on plate loading concentration with the tube barcode to generate a comment for each well in the run

Examples:

TRAC-2-10850 304pM  TRAC-2-10851 273pM  TRAC-2-10852 301pM  TRAC-2-10853 315pM


55
56
57
58
59
60
61
62
# File 'app/models/pacbio/run.rb', line 55

def generate_barcodes_and_concentrations
  barcodes_and_concentrations = wells.collect do |well|
    concentration = well.library_concentration || well.on_plate_loading_concentration
    "#{well.used_aliquots.first.source.tube.barcode} #{concentration}pM"
  end.join(' ')

  update(barcodes_and_concentrations: barcodes_and_concentrations)
end

#generate_sample_sheetObject

returns sample sheet csv for a Pacbio::Run using pipelines.yml configuration to generate data



133
134
135
136
137
138
# File 'app/models/pacbio/run.rb', line 133

def generate_sample_sheet
  configuration = Pipelines.pacbio.sample_sheet.by_version(smrt_link_version.name)
  sample_sheet_class = "RunCsv::#{configuration.sample_sheet_class}".constantize
  sample_sheet = sample_sheet_class.new(object: self, configuration:)
  sample_sheet.payload
end

#instrument_nameObject

v12 has changed to use instrument_name We can’t alias it as it is an enum



66
67
68
# File 'app/models/pacbio/run.rb', line 66

def instrument_name
  system_name
end

#sequencing_kit_box_barcodesArray<String>

Returns the barcodes of the sequencing kits.

Returns:

  • (Array<String>)

    the barcodes of the sequencing kits



124
125
126
# File 'app/models/pacbio/run.rb', line 124

def sequencing_kit_box_barcodes
  plates.map { |p| "Plate #{p.plate_number}: #{p.sequencing_kit_box_barcode}" }
end

#sorted_wellsObject

Returns a list of wells associated with all plates which are sorted by plate first and then by wells in column order Example: ([<Plate plate_number:1> [<Well position:‘A1’>, <Well position:‘A2’>,<Well position:‘B1’>]<Plate> <Plate plate_number:2> [<Well position:‘A3’>, <Well position:‘A4’>,<Well position:‘B3’>]<Plate>]) => [<Well position:‘A1’>, <Well position:‘B1’>, <Well position:‘A2’>,<Well position:‘A3’> <Well position:‘A3’>,<Well position:‘B3’>,<Well position:‘A4’>],



153
154
155
156
# File 'app/models/pacbio/run.rb', line 153

def sorted_wells
  sorted_plates = plates.sort_by(&:plate_number)
  sorted_plates.flat_map { |plate| plate.wells.sort_by { |well| [well.column.to_i, well.row] } }
end

updates the smrt link options for all of the wells in the run returns the number of wells updated each well is saved after the update it is inefficient to save each well individually but this is not used by the UI

Parameters:

  • options (Hash)

    the options to update

Returns:

  • (Integer)

    the number of wells updated



81
82
83
84
85
86
# File 'app/models/pacbio/run.rb', line 81

def update_smrt_link_options(options)
  wells.each do |well|
    well.update_smrt_link_options(options)
  end
  wells.count
end

#used_aliquots_lib_source_in_pool(pools) ⇒ Array

This method filters and retrieves all aliquots from a given collection of pools where the aliquot’s source is of type ‘Pacbio::Library’.

Parameters:

  • pools (Array)

    An array of pools

Returns:

  • (Array)

    An array of aliquots that have a source of type ‘Pacbio::Library’.



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

def used_aliquots_lib_source_in_pool(pools)
  pools.flat_map(&:source).flat_map(&:used_aliquots)
       .select do |aliquot|
    aliquot.source_type == 'Pacbio::Library'
  end
end

#wellsObject

This is needed to generate the comments



71
72
73
# File 'app/models/pacbio/run.rb', line 71

def wells
  plates.collect(&:wells).flatten
end