Module: SampleManifest::CoreBehaviour::StockAssets

Included in:
PlateBehaviour::Core, SampleTubeBehaviour::Core, TubeRackBehaviour::Core
Defined in:
app/models/sample_manifest/core_behaviour.rb

Overview

The samples get registered in the stock resource table at the end of manifest upload and processing (It used to happen here)

Instance Method Summary collapse

Instance Method Details

#generate_sample_and_aliquot(sanger_sample_id, receptacle) ⇒ Object

Used in manifest upload code to insert the sample and aliquot into the database. The receptacle and sanger_sample_id already exist as they are inserted upfront when the manifest is generated. tag_depth is set on the aliquot to avoid tag clash if a) pools are present, and b) if the samples are not tagged. The assumption is made that samples passed to the below method are never tagged, because we’re in the ‘StockAssets’ module rather than the ‘LibraryAssets’ module.



43
44
45
46
47
48
49
50
51
# File 'app/models/sample_manifest/core_behaviour.rb', line 43

def generate_sample_and_aliquot(sanger_sample_id, receptacle)
  create_sample(sanger_sample_id).tap do |sample|
    tag_depth = tag_depth_for_sample(@manifest.pools, receptacle, sanger_sample_id)

    receptacle.aliquots.create!(sample:, study:, tag_depth:)

    study.samples << sample
  end
end

#stocks?Boolean

Returns:

  • (Boolean)


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

def stocks?
  true
end

#tag_depth_for_sample(pools, receptacle, sanger_sample_id) ⇒ Object

Assigns a tag_depth to a sample in a pool. Tag_depth just needs to be a unique integer for each sample in the pool, So we just use the index in the list of sample manifest assets in this receptacle.



60
61
62
63
64
# File 'app/models/sample_manifest/core_behaviour.rb', line 60

def tag_depth_for_sample(pools, receptacle, sanger_sample_id)
  return nil unless pools

  pools[receptacle].find_index { |sma| sma.sanger_sample_id == sanger_sample_id }
end