Class: SampleManifest::MultiplexedLibraryBehaviour::Core

Inherits:
SharedTubeBehaviour::Base show all
Includes:
CoreBehaviour::LibraryAssets
Defined in:
app/models/sample_manifest/multiplexed_library_behaviour.rb

Overview

rubocop:todo Style/Documentation

Constant Summary collapse

MxLibraryTubeException =

for #multiplexed_library_tube

Class.new(ActiveRecord::RecordNotFound)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CoreBehaviour::LibraryAssets

#generate_sample_and_aliquot, #stocks?

Methods inherited from SharedTubeBehaviour::Base

#details_array, #updated_by!

Methods included from CoreBehaviour::Shared

#details, #generate_sanger_ids, included

Constructor Details

#initialize(manifest) ⇒ Core

Returns a new instance of Core.


11
12
13
# File 'app/models/sample_manifest/multiplexed_library_behaviour.rb', line 11

def initialize(manifest)
  @manifest = manifest
end

Instance Attribute Details

#library_tubesObject

Returns the value of attribute library_tubes.


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

def library_tubes
  @library_tubes
end

Instance Method Details

#acceptable_purposesObject


41
42
43
# File 'app/models/sample_manifest/multiplexed_library_behaviour.rb', line 41

def acceptable_purposes
  Purpose.none
end

#default_purposeObject


45
46
47
# File 'app/models/sample_manifest/multiplexed_library_behaviour.rb', line 45

def default_purpose
  Tube::Purpose.standard_library_tube
end

#generateObject


15
16
17
18
# File 'app/models/sample_manifest/multiplexed_library_behaviour.rb', line 15

def generate
  @library_tubes = generate_tubes(Tube::Purpose.standard_library_tube)
  @mx_tube = generate_mx_library
end

#generate_mx_libraryObject


20
21
22
23
24
25
26
27
# File 'app/models/sample_manifest/multiplexed_library_behaviour.rb', line 20

def generate_mx_library
  Tube::Purpose
    .standard_mx_tube
    .create!
    .tap do |mx_tube|
      RequestFactory.create_external_multiplexed_library_creation_requests(@library_tubes, mx_tube, study)
    end
end

#included_resourcesObject


79
80
81
# File 'app/models/sample_manifest/multiplexed_library_behaviour.rb', line 79

def included_resources
  [{ sample: :sample_metadata, asset: [:barcodes, :aliquots, { requests: :target_asset }] }]
end

#io_samplesObject


29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/sample_manifest/multiplexed_library_behaviour.rb', line 29

def io_samples
  samples.map do |sample|
    {
      sample: sample,
      container: {
        barcode: sample.primary_receptacle.human_barcode
      },
      library_information: sample.primary_receptacle.library_information
    }
  end
end

#labwareObject


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

def labware
  [multiplexed_library_tube]
end

#labware=(labware) ⇒ Object

Raises:

  • (ArgumentError)

65
66
67
68
69
# File 'app/models/sample_manifest/multiplexed_library_behaviour.rb', line 65

def labware=(labware)
  raise ArgumentError, 'labware should contain only one element' if labware.count > 1

  @mx_tube = labware.first
end

#multiplexed_library_tubeObject


49
50
51
# File 'app/models/sample_manifest/multiplexed_library_behaviour.rb', line 49

def multiplexed_library_tube
  mx_tube || raise(MxLibraryTubeException.new, 'Mx tube not found')
end

#mx_tubeObject


53
54
55
# File 'app/models/sample_manifest/multiplexed_library_behaviour.rb', line 53

def mx_tube
  @mx_tube ||= mx_tube_from_manifest_asset
end

#mx_tube_from_manifest_assetObject


57
58
59
# File 'app/models/sample_manifest/multiplexed_library_behaviour.rb', line 57

def mx_tube_from_manifest_asset
  @manifest.assets.first&.external_library_creation_requests&.first&.target_asset
end

#pending_external_library_creation_requestsObject


61
62
63
# File 'app/models/sample_manifest/multiplexed_library_behaviour.rb', line 61

def pending_external_library_creation_requests
  multiplexed_library_tube.requests_as_target.for_state('pending')
end

#printablesObject


75
76
77
# File 'app/models/sample_manifest/multiplexed_library_behaviour.rb', line 75

def printables
  multiplexed_library_tube.labware
end