Class: WorkCompletion::PlateCompletion

Inherits:
Object
  • Object
show all
Defined in:
app/models/work_completion/plate_completion.rb

Overview

Class WorkCompletion::PlateCompletion provides the business logic for passing plates, especially in the Limber pipelines. This has been pulled out of WorkCompletion itself to allow for separate behaviour for plates and tubes.

Author:

  • Genome Research Ltd.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plate, submission_ids) ⇒ PlateCompletion

Returns a new instance of PlateCompletion


13
14
15
16
# File 'app/models/work_completion/plate_completion.rb', line 13

def initialize(plate, submission_ids)
  @target_plate = plate
  @submission_ids = submission_ids
end

Instance Attribute Details

#submission_idsObject (readonly)

Returns the value of attribute submission_ids


11
12
13
# File 'app/models/work_completion/plate_completion.rb', line 11

def submission_ids
  @submission_ids
end

#target_plateObject (readonly)

Returns the value of attribute target_plate


11
12
13
# File 'app/models/work_completion/plate_completion.rb', line 11

def target_plate
  @target_plate
end

Instance Method Details

#connect_requestsObject


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/work_completion/plate_completion.rb', line 23

def connect_requests
  target_wells.each do |target_well|
    detect_upstream_requests(target_well).each do |upstream|
      # We need to find the downstream requests BEFORE connecting the upstream
      # This is because submission.next_requests tries to take a shortcut through
      # the target_asset if it is defined.
      upstream.next_requests.each { |ds| ds.update!(asset: target_well) }
      # In some cases, such as the Illumina-C pipelines, requests might be
      # connected upfront. We don't want to touch these.
      upstream.target_asset ||= target_well
      # We don't try and pass failed requests.
      # I'm not 100% convinced this decision belongs here, and instead
      # we may want to let the client specify wells to pass, and perform
      # validation to ensure this is correct. However this increases
      # the complexity of both the code and the interface, with only
      # marginal system simplification.
      upstream.pass if upstream.may_pass?
      upstream.save!
    end
  end
end

#detect_upstream_requests(target_well) ⇒ Object


45
46
47
# File 'app/models/work_completion/plate_completion.rb', line 45

def detect_upstream_requests(target_well)
  target_well.aliquots.map(&:request)
end

#processObject


18
19
20
21
# File 'app/models/work_completion/plate_completion.rb', line 18

def process
  connect_requests
  update_stock_wells
end

#suitable_request?(request) ⇒ Boolean

Returns:

  • (Boolean)

49
50
51
# File 'app/models/work_completion/plate_completion.rb', line 49

def suitable_request?(request)
  submission_ids.include?(request.submission_id)
end

#target_wellsObject


58
59
60
61
62
63
# File 'app/models/work_completion/plate_completion.rb', line 58

def target_wells
  @target_wells ||= target_plate.wells
                                .includes(aliquots: { request: WorkCompletion::REQUEST_INCLUDES })
                                .include_stock_wells_for_modification
                                .where(requests: { submission_id: submission_ids })
end

#update_stock_wellsObject


53
54
55
56
# File 'app/models/work_completion/plate_completion.rb', line 53

def update_stock_wells
  Well::Link.stock.where(target_well_id: target_wells.map(&:id)).delete_all
  Well::Link.stock.import(target_wells.map { |well| { source_well_id: well.id, target_well_id: well.id } })
end