Class: SampleManifest::CompoundSampleBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/models/sample_manifest/compound_sample_builder.rb

Overview

Creates, or updates, the compound sample for one receptacle of a compound sample manifest, e.g. a tube of a Kinnex compound sample tube manifest.

The manifest upload creates the component samples without aliquots. This creates:

  • the compound sample, in the study, with a new sanger sample id as its name and its sanger sample id, as it is the sample in the tube
  • a link to each component sample, with the component's tag
  • the compound sample's aliquot: the only aliquot in the receptacle

A re-upload updates the compound sample like other manifests update their samples: it adds new component samples, corrects tags and updates the shared metadata. It does not remove component samples.

The component samples are told apart by their tags, so a tag can be used only once in a compound sample.

Constant Summary collapse

SHARED_METADATA =

Metadata copied to the compound sample when all its components agree.

%i[supplier_name sample_common_name sample_taxon_id].freeze

Instance Method Summary collapse

Constructor Details

#initialize(study:, receptacle:, tags_by_component:, library_type: nil) ⇒ CompoundSampleBuilder

Returns a new instance of CompoundSampleBuilder.

Parameters:

  • study (Study) —

    the study of the manifest

  • receptacle (Receptacle) —

    the receptacle for the compound sample

  • tags_by_component (Hash{Sample => Tag}) —

    the component samples and their tags

  • library_type (String, nil) (defaults to: nil) —

    the library type of the aliquot



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/sample_manifest/compound_sample_builder.rb', line 28

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

Instance Method Details

#build! ⇒ Sample

Returns the compound sample.

Returns:

  • (Sample) —

    the compound sample

Raises:

  • (ActiveRecord::RecordInvalid) —

    if a tag is used more than once



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/sample_manifest/compound_sample_builder.rb', line 37

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#update!(compound) ⇒ Boolean

Links the given component samples that are new to the compound sample, corrects the tags of the others, and updates the shared metadata from all its component samples.

Parameters:

  • compound (Sample) —

    the compound sample

Returns:

  • (Boolean) —

    true

Raises:

  • (ActiveRecord::RecordInvalid) —

    if a tag is used more than once



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/models/sample_manifest/compound_sample_builder.rb', line 53

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end