Class: SampleManifestExcel::Upload::Row
- Inherits:
-
Object
- Object
- SampleManifestExcel::Upload::Row
- 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
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#data ⇒ Object
Returns the value of attribute data.
-
#number ⇒ Object
Returns the value of attribute number.
-
#sanger_sample_id ⇒ Object
readonly
Returns the value of attribute sanger_sample_id.
Instance Method Summary collapse
- #aliquot ⇒ Object
- #aliquot_transferred? ⇒ Boolean
-
#at(col_num) ⇒ Object
Finds the data value for a particular column.
-
#changed? ⇒ Boolean
rubocop:enable Metrics/MethodLength.
- #empty? ⇒ Boolean
- #first? ⇒ Boolean
-
#i5_present ⇒ Object
Ensure i5 column is not blank if it exists in the manifest.
-
#i7_present ⇒ Object
Ensure i7 column is not blank if it exists in the manifest.
-
#initialize(attributes = {}) ⇒ Row
constructor
Finds a sample based on the sanger_sample_id column.
- #labware ⇒ Object
- #metadata ⇒ Object
- #reuploaded? ⇒ Boolean
-
#row_title ⇒ Object
Used for errors.
- #sample ⇒ Object
- #sample_created? ⇒ Boolean
- #sample_skipped_or_updated? ⇒ Boolean
- #sample_updated? ⇒ Boolean
- #specialised_fields ⇒ Object
-
#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.
- #update_metadata_fields ⇒ Object
-
#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.
- #update_specialised_fields(tag_group) ⇒ Object
- #validate_sample ⇒ Object
-
#value(key) ⇒ Object
Find a value based on a column name.
- #warnings ⇒ Object
Methods included from Converters
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
51 52 53 54 55 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 51 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 (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
#aliquot ⇒ Object
86 87 88 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 86 def aliquot @aliquot ||= manifest_asset.aliquot end |
#aliquot_transferred? ⇒ Boolean
174 175 176 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 174 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
60 61 62 63 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 60 def at(col_num) val = data[col_num - 1] strip_all_blanks(val) end |
#changed? ⇒ Boolean
rubocop:enable Metrics/MethodLength
127 128 129 130 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 127 def changed? (@sample_updated && sample.previous_changes.present?) || .previous_changes.present? || aliquots.any? { |a| a.previous_changes.present? } end |
#empty? ⇒ Boolean
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 178 def empty? # a row must have one of the primary column options primary_column_names = %w[supplier_name bioscan_supplier_name] # check the columns exist, are valid, and at least one of the primary column options are present unless columns.present? && columns.valid? && primary_column_names.any? { |column_name| columns.names.include? column_name } return true end # it is mandatory to have a value in the primary column return true if primary_column_names.all? { |column_name| value(column_name).blank? } false end |
#first? ⇒ Boolean
76 77 78 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 76 def first? number == 1 end |
#i5_present ⇒ Object
Ensure i5 column is not blank if it exists in the manifest
39 40 41 42 43 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 39 def i5_present return unless columns.present? && data.present? && columns.names.include?('i5') && value('i5').blank? warnings.add(:base, "#{row_title} i5 is blank! ") end |
#i7_present ⇒ Object
Ensure i7 column is not blank if it exists in the manifest
31 32 33 34 35 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 31 def i7_present return unless columns.present? && data.present? && columns.names.include?('i7') && value('i7').blank? warnings.add(:base, "#{row_title} i7 is blank! ") end |
#labware ⇒ Object
194 195 196 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 194 def labware sample.primary_receptacle.labware end |
#metadata ⇒ Object
92 93 94 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 92 def @metadata ||= sample. end |
#reuploaded? ⇒ Boolean
154 155 156 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 154 def reuploaded? @reuploaded || false end |
#row_title ⇒ Object
Used for errors
82 83 84 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 82 def row_title "Row #{number} -" end |
#sample ⇒ Object
158 159 160 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 158 def sample @sample ||= manifest_asset&.find_or_create_sample if sanger_sample_id.present? && !empty? end |
#sample_created? ⇒ Boolean
170 171 172 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 170 def sample_created? sample_updated? && !reuploaded? end |
#sample_skipped_or_updated? ⇒ Boolean
166 167 168 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 166 def sample_skipped_or_updated? @sample_skipped || sample_updated? end |
#sample_updated? ⇒ Boolean
162 163 164 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 162 def sample_updated? @sample_updated || false end |
#specialised_fields ⇒ Object
96 97 98 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 96 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.
146 147 148 149 150 151 152 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 146 def transfer_aliquot return unless valid? asset.external_library_creation_requests.each do |request| @aliquot_transferred = request.passed? || request.manifest_processed! end end |
#update_metadata_fields ⇒ Object
136 137 138 139 140 141 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 136 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 asset, metadata and sample rubocop:todo Metrics/MethodLength
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 107 def update_sample(tag_group, override) # rubocop:todo Metrics/AbcSize 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! .save! sample.updated_by_manifest = true sample.empty_supplier_sample_name = false @sample_updated = sample.save end end |
#update_specialised_fields(tag_group) ⇒ Object
132 133 134 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 132 def update_specialised_fields(tag_group) specialised_fields.each { |specialised_field| specialised_field.update(tag_group:) } end |
#validate_sample ⇒ Object
198 199 200 201 202 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 198 def validate_sample check_sample_present sample_can_be_updated errors.empty? end |
#value(key) ⇒ Object
Find a value based on a column name
67 68 69 70 71 72 73 74 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 67 def value(key) column_number = columns.find_column_or_null(:name, key).number # column_number is -1 if no column found by this name (returns NullColumn object from find) return nil if column_number.negative? at(column_number) end |
#warnings ⇒ Object
19 20 21 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/row.rb', line 19 def warnings @warnings ||= ActiveModel::Errors.new(self) end |