Class: Ont::Run

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

Overview

Ont::Run

Constant Summary collapse

NAME_PREFIX =

Used for generating a unique experiment name for the run.

'ONTRUN-'

Instance Method Summary collapse

Methods included from Uuidable

#add_uuid

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'app/models/ont/run.rb', line 95

def active?
  deactivated_at.nil?
end

#cancelObject



99
100
101
102
103
# File 'app/models/ont/run.rb', line 99

def cancel
  return true unless active?

  update(deactivated_at: DateTime.current)
end

#flowcell_attributes=(flowcell_options) ⇒ Object

Sets flowcells from an array of attributes (hash) If there is no id in attributes, a new flowcell will be created. If there is an id, existing flowcell will be updated. If there is no attributes hash for an existing flowcell, it will be deleted. This method is called before validations, therefore it must properly set up all flowcells to be saved together with the run. It must first do the deletions and then “build” flowcells and “assign” attributes without saving.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/models/ont/run.rb', line 115

def flowcell_attributes=(flowcell_options)
  # Delete flowcells if attributes are not given
  options_ids = flowcell_options.pluck(:id).compact
  flowcells.each do |flowcell|
    flowcells.delete(flowcell) if options_ids.exclude? flowcell.id
  end

  # Update existing flowcells or create new ones
  flowcell_options.map do |attributes|
    if attributes[:id]
      flowcells.find(attributes[:id]).assign_attributes(attributes)
    else
      flowcells.build(attributes)
    end
  end
end

#flowcell_id_uniquenessObject

Check if flowcell_ids are duplicated in the run.



78
79
80
81
82
83
84
85
# File 'app/models/ont/run.rb', line 78

def flowcell_id_uniqueness
  duplicates = flowcells.group_by(&:flowcell_id).select { |_k, v| v.size > 1 }.values.flatten

  duplicates.each do |flowcell|
    errors.add(:flowcells, :flowcell_id_duplicated, flowcell_id: flowcell.flowcell_id,
                                                    position_name: flowcell.position_name)
  end
end

#generate_sample_sheetObject

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



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

def generate_sample_sheet
  sample_sheet = RunCsv::OntSampleSheet.new(object: self,
                                            configuration: ont_run_sample_sheet_config)
  sample_sheet.generate
end

#max_number_of_flowcellsObject

Return the max_number of flowcells for the instrument if instrument is present.



88
89
90
# File 'app/models/ont/run.rb', line 88

def max_number_of_flowcells
  instrument&.max_number_of_flowcells
end

#position_uniquenessObject

Check if positions are duplicated in the run.



68
69
70
71
72
73
74
75
# File 'app/models/ont/run.rb', line 68

def position_uniqueness
  position_names = flowcells.collect(&:position_name)
  duplicates = position_names.group_by { |f| f }.select { |_k, v| v.size > 1 }.map(&:first)

  duplicates.each do |position_name|
    errors.add(:flowcells, :position_duplicated, position_name:)
  end
end