Class: LabwareCreators::Tagging::TagCollection

Inherits:
Object
  • Object
show all
Defined in:
app/models/labware_creators/tagging/tag_collection.rb

Overview

rubocop:todo Style/Documentation

Instance Method Summary collapse

Constructor Details

#initialize(api, plate, purpose_uuid) ⇒ TagCollection

Create a tag collection

Parameters:

  • api (Sequencescape::Client::Api)

    an api object used to retrieve tag templates

  • plate (Limber::Plate)

    The plate from which the tag layout will be generated

  • purpose_uuid (String)

    The uuid of the purpose which is about to be created



12
13
14
15
16
# File 'app/models/labware_creators/tagging/tag_collection.rb', line 12

def initialize(api, plate, purpose_uuid)
  @api = api
  @plate = plate
  @purpose_uuid = purpose_uuid
end

Instance Method Details

#layout_hash(layout) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'app/models/labware_creators/tagging/tag_collection.rb', line 33

def layout_hash(layout)
  {
    tags: tags_by_column(layout),
    dual_index: layout.dual_index?,
    used: used.include?(layout.uuid),
    matches_templates_in_pool: matches_templates_in_pool(layout.uuid),
    approved: acceptable_template?(layout)
  }
end

#listHash

Returns hash of usable tag layout templates, and the tags assigned to each well: eg. { “tag-layout-template-0” => { tags: [[“A1”, [1, 1]], [“B1”, [1, 2]]], dual_index: true } } where { tag_template_uuid => { tags: [[well_name, [ pool_id, tag_id ]]], dual_index: dual_index? } }

Returns:

  • (Hash)

    Tag layouts and their tags



25
26
27
28
29
30
31
# File 'app/models/labware_creators/tagging/tag_collection.rb', line 25

def list
  @list ||=
    tag_layout_templates.each_with_object({}) do |layout, hash|
      # the `throw` that this catches comes from `generate_tag_layout` method
      catch(:unacceptable_tag_layout) { hash[layout.uuid] = layout_hash(layout) }
    end
end

#matches_templates_in_pool(uuid) ⇒ Bool

Used where the wells being pooled together originate from the same sample, so should have the same tags, so they are kept together when analysing sequencing data. (As opposed to when the pool will contain multiple samples, and therefore need to have different tags)

Parameters:

  • uuid (string)
    • the uuid of the Tag Layout Template we are currently dealing with

Returns:

  • (Bool)

    true if either no other templates have been used in the submission pool, or if all the templates used are the same as this one



69
70
71
72
73
74
75
# File 'app/models/labware_creators/tagging/tag_collection.rb', line 69

def matches_templates_in_pool(uuid)
  # if there haven't been any templates used yet in the pool, we say it matches them
  return true if used.empty?

  # return true if this template has been used already in the pool
  used.include?(uuid)
end

#usedObject

Returns a list of the tag layout templates (their uuids) that have already been used on other plates in the relevant submission pools



45
46
47
48
49
50
51
52
# File 'app/models/labware_creators/tagging/tag_collection.rb', line 45

def used
  return [] if @plate.submission_pools.empty?

  @used ||=
    @plate
      .submission_pools
      .each_with_object(Set.new) { |pool, set| pool.used_tag_layout_templates.each { |used| set << used['uuid'] } }
end

#used?Boolean

Have any tag layout templates already been used on other plates in the relevant submission pools?

Returns:

  • (Boolean)


55
56
57
# File 'app/models/labware_creators/tagging/tag_collection.rb', line 55

def used?
  used.present?
end