Class: CherrypickTask::PickTarget::Base

Inherits:
Object
  • Object
show all
Defined in:
app/models/cherrypick_task/pick_target.rb

Overview

Base class for different pick target beha

Direct Known Subclasses

ByColumn, ByInterlacedColumn, ByRow

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, asset_shape = nil, partial = nil) ⇒ Base

rubocop:todo Metrics/ClassLength


14
15
16
17
18
19
20
# File 'app/models/cherrypick_task/pick_target.rb', line 14

def initialize(template, asset_shape = nil, partial = nil)
  @wells = []
  @size = template.size
  @shape = asset_shape || AssetShape.default
  initialize_already_occupied_wells_from(template, partial)
  add_any_wells_from_template_or_partial(@wells)
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.


30
31
32
# File 'app/models/cherrypick_task/pick_target.rb', line 30

def size
  @size
end

Instance Method Details

#add_any_consecutive_control_requests(control_posns, batch, control_assets) ⇒ Object

Adds any consecutive list of control requests into the current_destination_plate


60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/models/cherrypick_task/pick_target.rb', line 60

def add_any_consecutive_control_requests(control_posns, batch, control_assets)
  # find the index of the well we are filling right now
  current_well_index = content.length

  # check if this well should contain a control
  # add it if so, and any consecutive ones by looping
  while control_posns.include?(current_well_index)
    control_asset = control_assets[control_posns.find_index(current_well_index)]
    add_control_request(batch, control_asset)

    # above adds to current_destination_plate, so current_well_index should be recalculated
    current_well_index = content.length
  end
end

#add_any_initial_control_requests(control_posns, batch, control_assets) ⇒ Object

When starting a new plate, it writes all control requests from the beginning of the plate


153
154
155
156
157
158
159
160
161
162
# File 'app/models/cherrypick_task/pick_target.rb', line 153

def add_any_initial_control_requests(control_posns, batch, control_assets)
  current_well_index = content.length
  control_posns
    .select { |c| c <= current_well_index }
    .each do |control_well_index|
      control_asset = control_assets[control_posns.find_index(control_well_index)]
      add_control_request(batch, control_asset)
    end
  add_any_consecutive_control_requests(control_posns, batch, control_assets)
end

#add_control_request(batch, control_asset) ⇒ Object

Creates a new control request for the control_asset and adds it into the current_destination_plate plate


53
54
55
56
57
# File 'app/models/cherrypick_task/pick_target.rb', line 53

def add_control_request(batch, control_asset)
  control_request = create_control_requests!(batch, [control_asset]).first
  control_request.start!
  push(control_request.id, control_request.asset.plate.human_barcode, control_request.asset.map_description)
end

#add_remaining_control_requests(control_posns, batch, control_assets) ⇒ Object

Adds any remaining control requests not already added, into the current_destination_plate plate


76
77
78
79
80
81
82
83
# File 'app/models/cherrypick_task/pick_target.rb', line 76

def add_remaining_control_requests(control_posns, batch, control_assets)
  control_posns.each_with_index do |pos, idx|
    if pos >= content.length
      control_asset = control_assets[idx]
      add_control_request(batch, control_asset)
    end
  end
end

#contentObject


26
27
28
# File 'app/models/cherrypick_task/pick_target.rb', line 26

def content
  @wells
end

#create_control_requests!(batch, control_assets) ⇒ Object

Creates control requests for the control assets provided and adds them to the batch


37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/cherrypick_task/pick_target.rb', line 37

def create_control_requests!(batch, control_assets)
  control_requests =
    control_assets.map do |control_asset|
      CherrypickRequest.create(
        asset: control_asset,
        target_asset: Well.new,
        submission: batch.requests.first.submission,
        request_type: batch.requests.first.request_type,
        request_purpose: 'standard'
      )
    end
  batch.requests << control_requests
  control_requests
end

#empty?Boolean

Returns:

  • (Boolean)

22
23
24
# File 'app/models/cherrypick_task/pick_target.rb', line 22

def empty?
  @wells.empty?
end

#full?Boolean

Returns:

  • (Boolean)

32
33
34
# File 'app/models/cherrypick_task/pick_target.rb', line 32

def full?
  @wells.size == @size
end

#push(request_id, plate_barcode, well_location) ⇒ Object


85
86
87
88
89
90
# File 'app/models/cherrypick_task/pick_target.rb', line 85

def push(request_id, plate_barcode, well_location)
  @wells << [request_id, plate_barcode, well_location]

  add_any_wells_from_template_or_partial(@wells)
  self
end

#push_with_controls(request_id, plate_barcode, well_location, control_posns, batch, control_assets) ⇒ Object

rubocop:todo Metrics/ParameterLists


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

def push_with_controls(request_id, plate_barcode, well_location, control_posns, batch, control_assets)
  # rubocop:enable Metrics/ParameterLists
  @wells << [request_id, plate_barcode, well_location]
  if control_posns
    # would be nil if no control plate selected
    add_any_consecutive_control_requests(control_posns, batch, control_assets)

    # This assumes that the template wells will fall at the end of the plate
    if (@wells.length + remaining_wells(control_posns).length) == @size
      add_remaining_control_requests(control_posns, batch, control_assets)
    end
  end
  add_any_wells_from_template_or_partial(@wells)
  self
end

#remaining_wells(control_posns) ⇒ Object

includes control wells and template / partial wells that are yet to be added


93
94
95
96
97
# File 'app/models/cherrypick_task/pick_target.rb', line 93

def remaining_wells(control_posns)
  remaining_controls = control_posns.select { |c| c > @wells.length }
  remaining_used_wells = @used_wells.keys.select { |c| c > @wells.length }
  remaining_controls.concat(remaining_used_wells).flatten
end