Class: SampleManifestExcel::Upload::Processor::Base

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, SequencescapeExcel::SubclassChecker
Defined in:
app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb

Overview

Uploads will be processed slightly differently based on the manifest type.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(upload) ⇒ Base

Returns a new instance of Base.


20
21
22
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 20

def initialize(upload)
  @upload = upload
end

Instance Attribute Details

#uploadObject (readonly)

Returns the value of attribute upload.


14
15
16
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 14

def upload
  @upload
end

Instance Method Details

#aliquots_updated?Boolean

Returns:

  • (Boolean)

95
96
97
98
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 95

def aliquots_updated?
  downstream_aliquots_updated? || no_substitutions? ||
    log_error_and_return_false('Could not update tags in other assets.')
end

#create_samples_if_not_presentObject


40
41
42
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 40

def create_samples_if_not_present
  upload.rows.each(&:sample)
end

#downstream_aliquots_updated?Boolean

Returns:

  • (Boolean)

91
92
93
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 91

def downstream_aliquots_updated?
  @downstream_aliquots_updated
end

#processed?Boolean

Returns:

  • (Boolean)

69
70
71
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 69

def processed?
  samples_updated? && sample_manifest_updated? && aliquots_updated?
end

#run(tag_group) ⇒ Object

If the processor is valid the samples and manifest are updated.


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 26

def run(tag_group)
  return unless valid?

  # find or create samples
  create_samples_if_not_present

  # run the validation (some depends on samples being present)
  return unless samples_valid?

  # update the metadata and specialised fields
  update_samples_and_aliquots(tag_group)
  update_sample_manifest
end

#sample_manifest_updated?Boolean

Returns:

  • (Boolean)

79
80
81
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 79

def sample_manifest_updated?
  @sample_manifest_updated
end

#samples_updated?Boolean

Returns:

  • (Boolean)

65
66
67
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 65

def samples_updated?
  upload.rows.all?(&:sample_skipped_or_updated?) || log_error_and_return_false('Could not update samples')
end

#samples_valid?Boolean

Returns:

  • (Boolean)

44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 44

def samples_valid?
  all_valid = true

  upload.rows.each do |row|
    unless row.validate_sample
      upload.errors.add(:base, row.errors.full_messages.join(', ').to_s)
      all_valid = false
    end
  end

  all_valid
end

#substitutionsObject


87
88
89
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 87

def substitutions
  @substitutions ||= []
end

#typeObject


83
84
85
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 83

def type
  self.class.to_s
end

#update_sample_manifestObject

Override the sample manifest with the raw uploaded data.


75
76
77
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 75

def update_sample_manifest
  @sample_manifest_updated = upload.sample_manifest.update(uploaded: upload.file)
end

#update_samples_and_aliquots(tag_group) ⇒ Object


57
58
59
60
61
62
63
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/processor/base.rb', line 57

def update_samples_and_aliquots(tag_group)
  upload.rows.each do |row|
    row.update_sample(tag_group, upload.override)
    substitutions << row.aliquot.substitution_hash if row.reuploaded?
  end
  update_downstream_aliquots unless no_substitutions?
end