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
63
64
65
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 63
def aliquot
@aliquot ||= manifest_asset.aliquot
end
|
#aliquot_transferred? ⇒ Boolean
151
152
153
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 151
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
rubocop:enable Metrics/MethodLength
104
105
106
107
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 104
def changed?
(@sample_updated && sample.previous_changes.present?) || metadata.previous_changes.present? ||
aliquots.any? { |a| a.previous_changes.present? }
end
|
#empty? ⇒ Boolean
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 155
def empty?
primary_column_names = %w[supplier_name bioscan_supplier_name]
unless columns.present? && columns.valid? &&
(primary_column_names.any? { |column_name| columns.names.include? column_name })
return true
end
return true if primary_column_names.all? { |column_name| value(column_name).blank? }
false
end
|
#first? ⇒ Boolean
53
54
55
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 53
def first?
number == 1
end
|
#labware ⇒ Object
170
171
172
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 170
def labware
sample.primary_receptacle.labware
end
|
69
70
71
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 69
def metadata
@metadata ||= sample.sample_metadata
end
|
#reuploaded? ⇒ Boolean
131
132
133
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 131
def reuploaded?
@reuploaded || false
end
|
#row_title ⇒ Object
59
60
61
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 59
def row_title
"Row #{number} -"
end
|
#sample ⇒ Object
135
136
137
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 135
def sample
@sample ||= manifest_asset&.find_or_create_sample if sanger_sample_id.present? && !empty?
end
|
#sample_created? ⇒ Boolean
147
148
149
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 147
def sample_created?
sample_updated? && !reuploaded?
end
|
#sample_skipped_or_updated? ⇒ Boolean
143
144
145
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 143
def sample_skipped_or_updated?
@sample_skipped || sample_updated?
end
|
#sample_updated? ⇒ Boolean
139
140
141
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 139
def sample_updated?
@sample_updated || false
end
|
#specialised_fields ⇒ Object
73
74
75
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 73
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.
123
124
125
126
127
128
129
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 123
def transfer_aliquot
return unless valid?
asset.external_library_creation_requests.each do |request|
@aliquot_transferred = request.passed? || request.manifest_processed!
end
end
|
113
114
115
116
117
118
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 113
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 rubocop:todo Metrics/MethodLength
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 84
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!
update_metadata_fields
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
109
110
111
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 109
def update_specialised_fields(tag_group)
specialised_fields.each { |specialised_field| specialised_field.update(tag_group:) }
end
|
#validate_sample ⇒ Object
174
175
176
177
178
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 174
def validate_sample
check_sample_present
sample_can_be_updated
errors.empty?
end
|
#value(key) ⇒ Object
Find a value based on a column name
45
46
47
48
49
50
51
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 45
def value(key)
column_number = columns.find_column_or_null(:name, key).number
return nil if column_number.negative?
at(column_number)
end
|