Class: SampleManifest::PlateBehaviour::Base

Inherits:
Object
  • Object
show all
Includes:
CoreBehaviour::NoSpecializedValidation, CoreBehaviour::Shared
Defined in:
app/models/sample_manifest/plate_behaviour.rb

Direct Known Subclasses

LibraryPlateBehaviour::Core, Core

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CoreBehaviour::NoSpecializedValidation

#specialized_fields, #validate_specialized_fields

Methods included from CoreBehaviour::Shared

#details, #generate_sanger_ids, included

Constructor Details

#initialize(manifest) ⇒ Base

Returns a new instance of Base.



9
10
11
12
# File 'app/models/sample_manifest/plate_behaviour.rb', line 9

def initialize(manifest)
  @manifest = manifest
  @plates = []
end

Instance Attribute Details

#platesObject (readonly)

Returns the value of attribute plates.



7
8
9
# File 'app/models/sample_manifest/plate_behaviour.rb', line 7

def plates
  @plates
end

Instance Method Details

#acceptable_purposesObject



27
28
29
# File 'app/models/sample_manifest/plate_behaviour.rb', line 27

def acceptable_purposes
  PlatePurpose.for_submissions
end

#default_purposeObject



31
32
33
# File 'app/models/sample_manifest/plate_behaviour.rb', line 31

def default_purpose
  PlatePurpose.stock_plate_purpose
end

#details_arrayObject



58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/models/sample_manifest/plate_behaviour.rb', line 58

def details_array
  @details_array ||=
    sample_manifest_assets
      .includes(asset: [:map, :aliquots, { plate: :barcodes }])
      .map do |sample_manifest_asset|
        {
          barcode: sample_manifest_asset.asset.plate.human_barcode,
          position: sample_manifest_asset.asset.map_description,
          sample_id: sample_manifest_asset.sanger_sample_id
        }
      end
end

#generateObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/sample_manifest/plate_behaviour.rb', line 14

def generate
  @plates = generate_plates(purpose)

  sanger_sample_ids = insert_sanger_sample_ids
  well_data = build_well_data(sanger_sample_ids)

  build_wells_async(well_data)

  @details_array = build_details_array(well_data)

  @manifest.update!(barcodes: @plates.map(&:human_barcode))
end

#included_resourcesObject



35
36
37
# File 'app/models/sample_manifest/plate_behaviour.rb', line 35

def included_resources
  [{ sample: :sample_metadata, asset: { plate: :barcodes } }]
end

#io_samplesObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/sample_manifest/plate_behaviour.rb', line 39

def io_samples
  samples.map do |sample|
    container = sample.primary_receptacle
    {
      sample: sample,
      container: {
        barcode: container.plate.human_barcode,
        position: container.map.description.sub(/^([^\d]+)(\d)$/, '\10\2')
      }
    }
  end
end

#labwareObject Also known as: printables

We use the barcodes here as we may need to reference the plates before the delayed job has passed



76
77
78
# File 'app/models/sample_manifest/plate_behaviour.rb', line 76

def labware
  plates | Labware.with_barcode(barcodes)
end

#labware=(labware) ⇒ Object



71
72
73
# File 'app/models/sample_manifest/plate_behaviour.rb', line 71

def labware=(labware)
  @plates = labware
end

#updated_by!(user, samples) ⇒ Object



52
53
54
55
56
# File 'app/models/sample_manifest/plate_behaviour.rb', line 52

def updated_by!(user, samples)
  # It's more efficient to look for the wells with the samples than to look for the assets from the samples
  # themselves as the former can use named_scopes where as the latter is an array that needs iterating over.
  Plate.with_sample(samples).each { |plate| plate.events.updated_using_sample_manifest!(user) }
end