Class: ProductCriteria::Basic

Inherits:
Object
  • Object
show all
Defined in:
app/models/product_criteria/basic.rb

Overview

rubocop:todo Style/Documentation

Direct Known Subclasses

Advanced

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'.freeze
FAILED_STATE =
'failed'.freeze
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, well, target_wells = nil) ⇒ Basic

Returns a new instance of Basic.


44
45
46
47
48
49
50
51
# File 'app/models/product_criteria/basic.rb', line 44

def initialize(params, well, target_wells = nil)
  @params = params
  @well_or_metric = well
  @comment = []
  @values = {}
  @target_wells = target_wells
  assess!
end

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment


14
15
16
# File 'app/models/product_criteria/basic.rb', line 14

def comment
  @comment
end

#paramsObject (readonly)

Returns the value of attribute params


14
15
16
# File 'app/models/product_criteria/basic.rb', line 14

def params
  @params
end

#passedObject (readonly) Also known as: passed?

Returns the value of attribute passed


14
15
16
# File 'app/models/product_criteria/basic.rb', line 14

def passed
  @passed
end

#valuesObject (readonly)

Returns the value of attribute values


14
15
16
# File 'app/models/product_criteria/basic.rb', line 14

def values
  @values
end

Class Method Details

.available_criteriaObject

Returns a list of possible criteria to either display or validate


35
36
37
# File 'app/models/product_criteria/basic.rb', line 35

def available_criteria
  SUPPORTED_WELL_ATTRIBUTES + EXTENDED_ATTRIBUTES + SUPPORTED_SAMPLE_METADATA + SUPPORTED_SAMPLE
end

.headers(configuration) ⇒ Object


39
40
41
# File 'app/models/product_criteria/basic.rb', line 39

def headers(configuration)
  configuration.keys + [:comment]
end

Instance Method Details

#concentration_from_normalizationObject


82
83
84
# File 'app/models/product_criteria/basic.rb', line 82

def concentration_from_normalization
  most_recent_concentration_from_target_well_by_updating_date
end

#conflicting_gender_markersObject


59
60
61
# File 'app/models/product_criteria/basic.rb', line 59

def conflicting_gender_markers
  (gender_markers || []).count { |marker| conflicting_marker?(marker) }
end

#metricsObject


63
64
65
# File 'app/models/product_criteria/basic.rb', line 63

def metrics
  values.merge(comment: @comment.join(';'))
end

#most_recent_concentration_from_target_well_by_updating_dateObject

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.


78
79
80
# File 'app/models/product_criteria/basic.rb', line 78

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_barcodeObject


71
72
73
# File 'app/models/product_criteria/basic.rb', line 71

def plate_barcode
  @well_or_metric.labware.try(:human_barcode) || 'Unknown'
end

#qc_decisionObject


111
112
113
# File 'app/models/product_criteria/basic.rb', line 111

def qc_decision
  passed? ? PASSSED_STATE : FAILED_STATE
end

#sample_genderObject

Return the sample gender, returns nil if it can't be determined ie. mixed input, or not male/female


102
103
104
105
106
107
108
109
# File 'app/models/product_criteria/basic.rb', line 102

def sample_gender
  markers = @well_or_metric.samples.map do |s|
    s..gender && s..gender.downcase.strip
  end.uniq
  return nil if markers.count > 1

  GENDER_MARKER_MAPS[markers.first]
end

#storage_locationObject


115
116
117
# File 'app/models/product_criteria/basic.rb', line 115

def storage_location
  @well_or_metric.labware.try(:storage_location) || 'Unknown'
end

#total_microgramsObject


53
54
55
56
57
# File 'app/models/product_criteria/basic.rb', line 53

def total_micrograms
  return nil if current_volume.nil? || concentration.nil?

  (current_volume * concentration) / 1000.0
end

#well_locationObject


67
68
69
# File 'app/models/product_criteria/basic.rb', line 67

def well_location
  @well_or_metric.map_description
end