Class: ProductCriteria::Basic

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

Direct Known Subclasses

Advanced

Defined Under Namespace

Classes: Comparison

Constant Summary collapse

SUPPORTED_WELL_ATTRIBUTES =
[:gel_pass, :concentration, :rin, :current_volume, :pico_pass, :gender_markers, :measured_volume, :initial_volume, :molarity, :sequenom_count]
SUPPORTED_SAMPLE =
[:sanger_sample_id]
SUPPORTED_SAMPLE_METADATA =
[:gender, :sample_ebi_accession_number, :supplier_name]
EXTENDED_ATTRIBUTES =
[:total_micrograms, :conflicting_gender_markers, :sample_gender, :well_location, :plate_barcode, :concentration_from_normalization]
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')
}
GENDER_MARKER_MAPS =
{
  'male' => 'M',
  'female' => 'F'
}

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


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

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


12
13
14
# File 'app/models/product_criteria/basic.rb', line 12

def comment
  @comment
end

#paramsObject (readonly)

Returns the value of attribute params


12
13
14
# File 'app/models/product_criteria/basic.rb', line 12

def params
  @params
end

#passedObject (readonly) Also known as: passed?

Returns the value of attribute passed


12
13
14
# File 'app/models/product_criteria/basic.rb', line 12

def passed
  @passed
end

#valuesObject (readonly)

Returns the value of attribute values


12
13
14
# File 'app/models/product_criteria/basic.rb', line 12

def values
  @values
end

Class Method Details

.available_criteriaObject

Returns a list of possible criteria to either display or validate


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

def available_criteria
  SUPPORTED_WELL_ATTRIBUTES + EXTENDED_ATTRIBUTES + SUPPORTED_SAMPLE_METADATA + SUPPORTED_SAMPLE
end

.headers(configuration) ⇒ Object


37
38
39
# File 'app/models/product_criteria/basic.rb', line 37

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

Instance Method Details

#concentration_from_normalizationObject


80
81
82
# File 'app/models/product_criteria/basic.rb', line 80

def concentration_from_normalization
  most_recent_concentration_from_target_well_by_updating_date
end

#conflicting_gender_markersObject


57
58
59
# File 'app/models/product_criteria/basic.rb', line 57

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

#metricsObject


61
62
63
# File 'app/models/product_criteria/basic.rb', line 61

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.


76
77
78
# File 'app/models/product_criteria/basic.rb', line 76

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


69
70
71
# File 'app/models/product_criteria/basic.rb', line 69

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

#qc_decisionObject


107
108
109
# File 'app/models/product_criteria/basic.rb', line 107

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


100
101
102
103
104
105
# File 'app/models/product_criteria/basic.rb', line 100

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

#total_microgramsObject


51
52
53
54
55
# File 'app/models/product_criteria/basic.rb', line 51

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

  (current_volume * concentration) / 1000.0
end

#well_locationObject


65
66
67
# File 'app/models/product_criteria/basic.rb', line 65

def well_location
  @well_or_metric.map_description
end