Class: ProductCriteria::Basic

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

Overview

rubocop:todo Metrics/ClassLength

Direct Known Subclasses

Advanced

Defined Under Namespace

Classes: Comparison

Constant Summary collapse

SUPPORTED_WELL_ATTRIBUTES =

rubocop:todo Style/Documentation

%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

Class Method Summary collapse

Instance Method Summary collapse

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

#commentObject (readonly)

Returns the value of attribute comment.


32
33
34
# File 'app/models/product_criteria/basic.rb', line 32

def comment
  @comment
end

#paramsObject (readonly)

Returns the value of attribute params.


32
33
34
# File 'app/models/product_criteria/basic.rb', line 32

def params
  @params
end

#passedObject (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

#valuesObject (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_criteriaObject

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_normalizationObject


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_markersObject


74
75
76
# File 'app/models/product_criteria/basic.rb', line 74

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

#metricsObject


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_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.


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_barcodeObject


86
87
88
# File 'app/models/product_criteria/basic.rb', line 86

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

#qc_decisionObject


119
120
121
# File 'app/models/product_criteria/basic.rb', line 119

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


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_locationObject


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_microgramsObject


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_locationObject


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

def well_location
  @well_or_metric.map_description
end