Class: SampleManifestExcel::Upload::Row
- Inherits:
-
Object
- Object
- SampleManifestExcel::Upload::Row
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, Converters::BLANK_CHARS_REGEXP
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
#cache ⇒ Object
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
|
#columns ⇒ Object
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
|
#data ⇒ Object
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
|
#number ⇒ Object
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_id ⇒ Object
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
#aliquot ⇒ Object
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
142
143
144
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 142
def aliquot_transferred?
@aliquot_transferred
end
|
#asset ⇒ Object
63
64
65
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 63
def asset
@asset ||= manifest_asset.asset
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
98
99
100
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 98
def changed?
@sample_updated && sample.previous_changes.present? || metadata.previous_changes.present? || aliquot.previous_changes.present?
end
|
#empty? ⇒ Boolean
146
147
148
149
150
151
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 146
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
49
50
51
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 49
def first?
number == 1
end
|
#labware ⇒ Object
153
154
155
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 153
def labware
sample.primary_receptacle.labware
end
|
67
68
69
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 67
def metadata
@metadata ||= sample.sample_metadata
end
|
#reuploaded? ⇒ Boolean
126
127
128
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 126
def reuploaded?
@reuploaded || false
end
|
#row_title ⇒ Object
55
56
57
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 55
def row_title
"Row #{number} -"
end
|
#sample ⇒ Object
130
131
132
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 130
def sample
@sample ||= manifest_asset&.find_or_create_sample if sanger_sample_id.present? && !empty?
end
|
#sample_skipped_or_updated? ⇒ Boolean
138
139
140
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 138
def sample_skipped_or_updated?
@sample_skipped || sample_updated?
end
|
#sample_updated? ⇒ Boolean
134
135
136
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 134
def sample_updated?
@sample_updated || false
end
|
#specialised_fields ⇒ Object
71
72
73
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 71
def specialised_fields
@specialised_fields ||= create_specialised_fields
end
|
#transfer_aliquot ⇒ Object
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.
118
119
120
121
122
123
124
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 118
def transfer_aliquot
return unless valid?
asset.external_library_creation_requests.each do |request|
@aliquot_transferred = request.passed? || request.manifest_processed!
end
end
|
108
109
110
111
112
113
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 108
def update_metadata_fields
columns.with_metadata_fields.each do |column|
value = at(column.number)
column.update_metadata(metadata, 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 asset, metadata and sample
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 81
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)
asset.save!
metadata.save!
sample.updated_by_manifest = true
sample.empty_supplier_sample_name = false
@sample_updated = sample.save
end
end
|
#update_specialised_fields(tag_group) ⇒ Object
102
103
104
105
106
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 102
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
|