Module: SequencingQcBatch

Included in:
Batch
Defined in:
lib/sequencing_qc_batch.rb

Overview

Place to put Illumina QC code to be refactored

Constant Summary collapse

VALID_QC_STATES =

NOTE: Be careful that the length of these do not exceed 25 characters, otherwise you will have to alter the batches.qc_state field in the DB to accommodate. FYI, 25 characters is:

<----------------------->
%w(
  qc_pending
  qc_submitted
  qc_manual
  qc_manual_in_progress
  qc_completed
)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.adjacent_state_helper(direction, offset, delimiter) ⇒ Object


48
49
50
51
52
53
54
55
# File 'lib/sequencing_qc_batch.rb', line 48

def self.adjacent_state_helper(direction, offset, delimiter)
  define_method(:"qc_#{direction}_state") do
    raise StandardError, "Current QC state appears to be invalid: '#{qc_state}'" unless qc_states.include?(qc_state.to_s)
    return nil if qc_state.to_s == qc_states.send(delimiter)

    return qc_states[qc_states.index(qc_state.to_s) + offset]
  end
end

.included(base) ⇒ Object


14
15
16
17
18
19
20
21
22
# File 'lib/sequencing_qc_batch.rb', line 14

def self.included(base)
  base.instance_eval do
    # TODO[xxx]: Isn't qc_state supposed to be initialised to 'qc_pending' rather than blank?
    validates_inclusion_of :qc_state, in: VALID_QC_STATES, allow_blank: true

    belongs_to :qc_pipeline, class_name: 'Pipeline'
    before_create :qc_pipeline_update
  end
end

.state_transition_helper(name) ⇒ Object


62
63
64
65
66
67
68
69
# File 'lib/sequencing_qc_batch.rb', line 62

def self.state_transition_helper(name)
  # TODO[xxx]: Really we should restrict the state transitions
  define_method(:"qc_#{name}") do
    # Maintaining legacy behaviour here as not sure if it was intentional.
    # Allows QC decisions to be made on invalid assets.
    update_attribute(:qc_state, qc_next_state) unless qc_next_state.nil? # rubocop:disable Rails/SkipsModelValidations
  end
end

Instance Method Details

#processing_in_manual_qc?Boolean


76
77
78
# File 'lib/sequencing_qc_batch.rb', line 76

def processing_in_manual_qc?
  %w[qc_manual_in_progress qc_manual].include?(qc_state)
end

#qc_manual_in_progressObject


80
81
82
83
# File 'lib/sequencing_qc_batch.rb', line 80

def qc_manual_in_progress
  self.qc_state = 'qc_manual_in_progress'
  save
end

#qc_previous_state!(current_user) ⇒ Object


38
39
40
41
42
43
44
45
46
# File 'lib/sequencing_qc_batch.rb', line 38

def qc_previous_state!(current_user)
  previous_state = qc_previous_state
  if previous_state
    lab_events.create(description: 'QC Rollback', message: "Manual QC moved from #{qc_state} to #{previous_state}", user_id: current_user.id)
    self.qc_state = previous_state
  end
  self.state = 'started'
  save
end

#qc_statesObject

Returns qc_states used


34
35
36
# File 'lib/sequencing_qc_batch.rb', line 34

def qc_states
  VALID_QC_STATES
end