Module: IlluminaHtp::PlatePurposes::PurposeHelpers

Included in:
IlluminaB::PlatePurposes, IlluminaC::PlatePurposes, IlluminaHtp::PlatePurposes
Defined in:
app/models/illumina_htp/plate_purposes.rb

Instance Method Summary collapse

Instance Method Details

#create_branch(branch_o) ⇒ Object


193
194
195
196
197
198
199
200
# File 'app/models/illumina_htp/plate_purposes.rb', line 193

def create_branch(branch_o)
  branch = branch_o.clone
  branch.inject(Purpose.find_by!(name: branch.shift)) do |parent, child|
    Purpose.find_by!(name: child).tap do |child_purpose|
      parent.child_relationships.create!(child: child_purpose)
    end
  end
end

#create_branchesObject


202
203
204
205
206
# File 'app/models/illumina_htp/plate_purposes.rb', line 202

def create_branches
  self::BRANCHES.each do |branch|
    create_branch(branch)
  end
end

#create_plate_flow(flow_o) ⇒ Object


164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'app/models/illumina_htp/plate_purposes.rb', line 164

def create_plate_flow(flow_o)
  flow = flow_o.clone
  raise 'Flow already exists' if Purpose.find_by(name: flow.first).present?

  stock_plate = create_plate_purpose(
    flow.shift,
    stock_plate: true,
    default_state: 'passed',
    cherrypickable_target: true
  )

  flow.each do |name|
    create_plate_purpose(name, source_purpose_id: stock_plate.id)
  end
end

#create_plate_purpose(plate_purpose_name, options = {}) ⇒ Object


213
214
215
216
217
218
219
220
221
222
223
# File 'app/models/illumina_htp/plate_purposes.rb', line 213

def create_plate_purpose(plate_purpose_name, options = {})
  purpose_for(plate_purpose_name).create!(options.reverse_merge(
                                            name: plate_purpose_name,
                                            cherrypickable_target: false,
                                            cherrypick_direction: 'column',
                                            stock_plate: self::OUTPUT_PLATE_PURPOSES.include?(plate_purpose_name),
                                            asset_shape_id: AssetShape.default.id
                                          )).tap do |plate_purpose|
    plate_purpose.barcode_printer_type = BarcodePrinterType.find_by(type: 'BarcodePrinterType96Plate') || plate_purpose.barcode_printer_type
  end
end

#create_plate_purposesObject


180
181
182
183
184
185
# File 'app/models/illumina_htp/plate_purposes.rb', line 180

def create_plate_purposes
  self::PLATE_PURPOSE_FLOWS.each do |flow|
    create_plate_flow(flow)
  end
  create_qc_plates
end

#create_qc_plate_for(name) ⇒ Object


244
245
246
247
248
# File 'app/models/illumina_htp/plate_purposes.rb', line 244

def create_qc_plate_for(name)
  qc_plate_purpose = purpose_for("#{name} QC").create!(name: "#{name} QC", cherrypickable_target: false)
  plate_purpose = Purpose.find_by!(name: name)
  plate_purpose.child_relationships.create!(child: qc_plate_purpose)
end

#create_qc_platesObject


236
237
238
239
240
241
242
# File 'app/models/illumina_htp/plate_purposes.rb', line 236

def create_qc_plates
  ActiveRecord::Base.transaction do
    self::PLATE_PURPOSE_LEADING_TO_QC_PLATES.each do |name|
      create_qc_plate_for(name)
    end
  end
end

#create_qc_tube_flow(flow_o) ⇒ Object


149
150
151
152
153
154
155
156
# File 'app/models/illumina_htp/plate_purposes.rb', line 149

def create_qc_tube_flow(flow_o)
  flow = flow_o.clone
  raise 'Flow already exists' if Purpose.find_by(name: flow.first).present?

  flow.each do |purpose|
    create_tube_purpose(purpose, target_type: 'QcTube')
  end
end

#create_tube_flow(flow_o) ⇒ Object


141
142
143
144
145
146
147
# File 'app/models/illumina_htp/plate_purposes.rb', line 141

def create_tube_flow(flow_o)
  flow = flow_o.clone
  raise 'Flow already exists' if Purpose.find_by(name: flow.first).present?

  create_tube_purpose(flow.pop, target_type: 'MultiplexedLibraryTube')
  flow.each(&method(:create_tube_purpose))
end

#create_tube_purposesObject


132
133
134
135
136
137
138
139
# File 'app/models/illumina_htp/plate_purposes.rb', line 132

def create_tube_purposes
  self::TUBE_PURPOSE_FLOWS.each do |flow|
    create_tube_flow(flow)
  end
  self::QC_TUBE_PURPOSE_FLOWS.each do |flow|
    create_qc_tube_flow(flow)
  end
end

#destroy_plate_purposesObject


187
188
189
190
191
# File 'app/models/illumina_htp/plate_purposes.rb', line 187

def destroy_plate_purposes
  self::PLATE_PURPOSE_FLOWS.each do |flow|
    PlatePurpose.where(name: flow.flatten).map(&:destroy)
  end
end

#destroy_tube_purposesObject


158
159
160
161
162
# File 'app/models/illumina_htp/plate_purposes.rb', line 158

def destroy_tube_purposes
  self::TUBE_PURPOSE_FLOWS.each do |flow|
    Tube::Purpose.where(name: flow.flatten).map(&:destroy)
  end
end