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
150
151
152
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 150
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
103
104
105
106
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 103
def changed?
(@sample_updated && sample.previous_changes.present?) || metadata.previous_changes.present? ||
aliquots.any? { |a| a.previous_changes.present? }
end
|
#empty? ⇒ Boolean
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 154
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
169
170
171
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 169
def labware
sample.primary_receptacle.labware
end
|
68
69
70
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 68
def metadata
@metadata ||= sample.sample_metadata
end
|
#reuploaded? ⇒ Boolean
130
131
132
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 130
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
134
135
136
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 134
def sample
@sample ||= manifest_asset&.find_or_create_sample if sanger_sample_id.present? && !empty?
end
|
#sample_created? ⇒ Boolean
146
147
148
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 146
def sample_created?
sample_updated? && !reuploaded?
end
|
#sample_skipped_or_updated? ⇒ Boolean
142
143
144
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 142
def sample_skipped_or_updated?
@sample_skipped || sample_updated?
end
|
#sample_updated? ⇒ Boolean
138
139
140
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 138
def sample_updated?
@sample_updated || false
end
|
#specialised_fields ⇒ Object
72
73
74
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 72
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.
122
123
124
125
126
127
128
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 122
def transfer_aliquot
return unless valid?
asset.external_library_creation_requests.each do |request|
@aliquot_transferred = request.passed? || request.manifest_processed!
end
end
|
112
113
114
115
116
117
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 112
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 83
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
108
109
110
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 108
def update_specialised_fields(tag_group)
specialised_fields.each { |specialised_field| specialised_field.update(tag_group:) }
end
|
#validate_sample ⇒ Object
173
174
175
176
177
|
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 173
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
|