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

#annotations_attributesObject (readonly)

Returns the value of attribute annotations_attributes.



53
54
55
# File 'app/models/pacbio/run.rb', line 53

def annotations_attributes
  @annotations_attributes
end

#plates_attributesObject (readonly)

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



52
53
54
# File 'app/models/pacbio/run.rb', line 52

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



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

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



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/models/pacbio/run.rb', line 100

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


60
61
62
63
64
65
66
67
# File 'app/models/pacbio/run.rb', line 60

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



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

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



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

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



129
130
131
# File 'app/models/pacbio/run.rb', line 129

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’>],



158
159
160
161
# File 'app/models/pacbio/run.rb', line 158

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



86
87
88
89
90
91
# File 'app/models/pacbio/run.rb', line 86

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’.



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

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



76
77
78
# File 'app/models/pacbio/run.rb', line 76

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