Class: ProductCriteria::Basic
- Inherits:
-
Object
- Object
- ProductCriteria::Basic
- Defined in:
- app/models/product_criteria/basic.rb
Overview
rubocop:todo Metrics/ClassLength
Direct Known Subclasses
Defined Under Namespace
Classes: Comparison
Constant Summary collapse
- SUPPORTED_WELL_ATTRIBUTES =
%i[ gel_pass concentration rin current_volume pico_pass gender_markers measured_volume initial_volume molarity sequenom_count ].freeze
- SUPPORTED_SAMPLE =
[:sanger_sample_id].freeze
- SUPPORTED_SAMPLE_METADATA =
%i[gender sample_ebi_accession_number supplier_name phenotype sample_description].freeze
- EXTENDED_ATTRIBUTES =
%i[ total_micrograms conflicting_gender_markers sample_gender well_location plate_barcode concentration_from_normalization ].freeze
- PASSSED_STATE =
'passed'
- FAILED_STATE =
'failed'
- UnknownSpecification =
Class.new(StandardError)
- METHOD_ALIAS =
{ greater_than: Comparison.new(:>, '%s too low'), less_than: Comparison.new(:<, '%s too high'), at_least: Comparison.new(:>=, '%s too low'), at_most: Comparison.new(:<=, '%s too high'), equals: Comparison.new(:==, '%s not suitable'), not_equal: Comparison.new(:'!=', '%s not suitable') }.freeze
- GENDER_MARKER_MAPS =
{ 'male' => 'M', 'female' => 'F' }.freeze
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#passed ⇒ Object
(also: #passed?)
readonly
Returns the value of attribute passed.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Class Method Summary collapse
-
.available_criteria ⇒ Object
Returns a list of possible criteria to either display or validate.
- .headers(configuration) ⇒ Object
Instance Method Summary collapse
- #concentration_from_normalization ⇒ Object
- #conflicting_gender_markers ⇒ Object
-
#initialize(params, well, target_wells = nil) ⇒ Basic
constructor
A new instance of Basic.
- #metrics ⇒ Object
-
#most_recent_concentration_from_target_well_by_updating_date ⇒ Object
We sort in Ruby here as we’ve loaded the wells in bulk.
- #plate_barcode ⇒ Object
- #qc_decision ⇒ Object
-
#sample_gender ⇒ Object
Return the sample gender, returns nil if it can’t be determined ie.
- #storage_location ⇒ Object
- #total_micrograms ⇒ Object
- #well_location ⇒ Object
Constructor Details
#initialize(params, well, target_wells = nil) ⇒ Basic
Returns a new instance of Basic.
59 60 61 62 63 64 65 66 |
# File 'app/models/product_criteria/basic.rb', line 59 def initialize(params, well, target_wells = nil) @params = params @well_or_metric = well @comment = [] @values = {} @target_wells = target_wells assess! end |
Instance Attribute Details
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
32 33 34 |
# File 'app/models/product_criteria/basic.rb', line 32 def comment @comment end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
32 33 34 |
# File 'app/models/product_criteria/basic.rb', line 32 def params @params end |
#passed ⇒ Object (readonly) Also known as: passed?
Returns the value of attribute passed.
32 33 34 |
# File 'app/models/product_criteria/basic.rb', line 32 def passed @passed end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
32 33 34 |
# File 'app/models/product_criteria/basic.rb', line 32 def values @values end |
Class Method Details
.available_criteria ⇒ Object
Returns a list of possible criteria to either display or validate
50 51 52 |
# File 'app/models/product_criteria/basic.rb', line 50 def available_criteria SUPPORTED_WELL_ATTRIBUTES + EXTENDED_ATTRIBUTES + SUPPORTED_SAMPLE_METADATA + SUPPORTED_SAMPLE end |
.headers(configuration) ⇒ Object
54 55 56 |
# File 'app/models/product_criteria/basic.rb', line 54 def headers(configuration) configuration.keys + [:comment] end |
Instance Method Details
#concentration_from_normalization ⇒ Object
97 98 99 |
# File 'app/models/product_criteria/basic.rb', line 97 def concentration_from_normalization most_recent_concentration_from_target_well_by_updating_date end |
#conflicting_gender_markers ⇒ Object
74 75 76 |
# File 'app/models/product_criteria/basic.rb', line 74 def conflicting_gender_markers (gender_markers || []).count { |marker| conflicting_marker?(marker) } end |
#metrics ⇒ Object
78 79 80 |
# File 'app/models/product_criteria/basic.rb', line 78 def metrics values.merge(comment: @comment.join(';')) end |
#most_recent_concentration_from_target_well_by_updating_date ⇒ Object
We sort in Ruby here as we’ve loaded the wells in bulk. Performing this selection in the database is actually more tricky than it sounds as your trying to load the latest record from multiple different wells simultaneously.
93 94 95 |
# File 'app/models/product_criteria/basic.rb', line 93 def most_recent_concentration_from_target_well_by_updating_date @target_wells.max_by { |w| w.well_attribute.updated_at }.get_concentration if @target_wells end |
#plate_barcode ⇒ Object
86 87 88 |
# File 'app/models/product_criteria/basic.rb', line 86 def @well_or_metric.labware.try(:human_barcode) || 'Unknown' end |
#qc_decision ⇒ Object
119 120 121 |
# File 'app/models/product_criteria/basic.rb', line 119 def qc_decision passed? ? PASSSED_STATE : FAILED_STATE end |
#sample_gender ⇒ Object
Return the sample gender, returns nil if it can’t be determined ie. mixed input, or not male/female
111 112 113 114 115 116 117 |
# File 'app/models/product_criteria/basic.rb', line 111 def sample_gender markers = @well_or_metric.samples.map { |s| s..gender && s..gender.downcase.strip }.uniq return nil if markers.count > 1 GENDER_MARKER_MAPS[markers.first] end |
#storage_location ⇒ Object
123 124 125 |
# File 'app/models/product_criteria/basic.rb', line 123 def storage_location @well_or_metric.labware.try(:storage_location) || 'Unknown' end |
#total_micrograms ⇒ Object
68 69 70 71 72 |
# File 'app/models/product_criteria/basic.rb', line 68 def total_micrograms return nil if current_volume.nil? || concentration.nil? (current_volume * concentration) / 1000.0 end |
#well_location ⇒ Object
82 83 84 |
# File 'app/models/product_criteria/basic.rb', line 82 def well_location @well_or_metric.map_description end |