Class: SampleManifestExcel::Upload::Row

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, Converters
Defined in:
app/sample_manifest_excel/sample_manifest_excel/upload/row.rb

Overview

A Row relates to a row in a sample manifest spreadsheet. Each Row relates to a sample Required fields: *number: Number of the row which is used for error tracking *data: An array of sample data *columns: The columns which relate to the data.

Constant Summary

Constants included from Converters

Converters::BLANK_CHARS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Converters

#strip_all_blanks

Constructor Details

#initialize(attributes = {}) ⇒ Row

Finds a sample based on the sanger_sample_id column. Must exist for row to be valid. Creates the specialised fields for updating the sample based on the passed columns


29
30
31
32
33
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 29

def initialize(attributes = {})
  super
  @cache ||= SampleManifestAsset
  @sanger_sample_id ||= value(:sanger_sample_id).presence if columns.present? && data.present?
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache


16
17
18
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 16

def cache
  @cache
end

#columnsObject

Returns the value of attribute columns


16
17
18
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 16

def columns
  @columns
end

#dataObject

Returns the value of attribute data


16
17
18
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 16

def data
  @data
end

#numberObject

Returns the value of attribute number


16
17
18
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 16

def number
  @number
end

#sanger_sample_idObject (readonly)

Returns the value of attribute sanger_sample_id


17
18
19
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 17

def sanger_sample_id
  @sanger_sample_id
end

Instance Method Details

#aliquotObject


59
60
61
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 59

def aliquot
  @aliquot ||= manifest_asset.aliquot
end

#aliquot_transferred?Boolean

Returns:

  • (Boolean)

138
139
140
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 138

def aliquot_transferred?
  @aliquot_transferred
end

#at(col_num) ⇒ Object

Finds the data value for a particular column. Offset by 1. Columns have numbers data is an array


38
39
40
41
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 38

def at(col_num)
  val = data[col_num - 1]
  strip_all_blanks(val)
end

#changed?Boolean

Returns:

  • (Boolean)

94
95
96
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 94

def changed?
  @sample_updated && sample.previous_changes.present? || .previous_changes.present? || aliquot.previous_changes.present?
end

#empty?Boolean

Returns:

  • (Boolean)

142
143
144
145
146
147
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 142

def empty?
  primary_column = 'supplier_name'
  return true unless columns.present? && columns.valid? && columns.names.include?(primary_column)

  value(primary_column).blank?
end

#first?Boolean

Returns:

  • (Boolean)

49
50
51
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 49

def first?
  number == 1
end

#labwareObject


149
150
151
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 149

def labware
  sample.primary_receptacle.labware
end

#metadataObject


63
64
65
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 63

def 
  @metadata ||= sample.
end

#reuploaded?Boolean

Returns:

  • (Boolean)

122
123
124
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 122

def reuploaded?
  @reuploaded || false
end

#row_titleObject

Used for errors


55
56
57
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 55

def row_title
  "Row #{number} -"
end

#sampleObject


126
127
128
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 126

def sample
  @sample ||= manifest_asset&.find_or_create_sample if sanger_sample_id.present? && !empty?
end

#sample_skipped_or_updated?Boolean

Returns:

  • (Boolean)

134
135
136
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 134

def sample_skipped_or_updated?
  @sample_skipped || sample_updated?
end

#sample_updated?Boolean

Returns:

  • (Boolean)

130
131
132
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 130

def sample_updated?
  @sample_updated || false
end

#specialised_fieldsObject


67
68
69
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 67

def specialised_fields
  @specialised_fields ||= create_specialised_fields
end

#transfer_aliquotObject

If it is a multiplexed library tube the aliquot is transferred from the library tube to a multiplexed library tube and stated set to passed.


114
115
116
117
118
119
120
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 114

def transfer_aliquot
  return unless valid?

  manifest_asset.asset.external_library_creation_requests.each do |request|
    @aliquot_transferred = request.passed? || request.manifest_processed!
  end
end

#update_metadata_fieldsObject


104
105
106
107
108
109
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 104

def 
  columns..each do |column|
    value = at(column.number)
    column.(, value) if value.present?
  end
end

#update_sample(tag_group, override) ⇒ Object

Updating the sample involves: *Checking it is ok to update row *Updating all of the specialised fields in the aliquot *Updating the sample metadata *Saving the aliquot, metadata and sample


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 77

def update_sample(tag_group, override)
  return unless valid?

  @reuploaded = sample.updated_by_manifest

  if sample.updated_by_manifest && !override
    @sample_skipped = true
  else
    update_specialised_fields(tag_group)
    aliquot.save!
    .save!
    sample.updated_by_manifest = true
    sample.empty_supplier_sample_name = false
    @sample_updated = sample.save
  end
end

#update_specialised_fields(tag_group) ⇒ Object


98
99
100
101
102
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 98

def update_specialised_fields(tag_group)
  specialised_fields.each do |specialised_field|
    specialised_field.update(aliquot: aliquot, tag_group: tag_group)
  end
end

#value(key) ⇒ Object

Find a value based on a column name


45
46
47
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 45

def value(key)
  at(columns.find_column_or_null(:name, key).number)
end