determinations_comparison 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15755c7425cabdc1a71feb14e6b1b3832f5f84d1
4
- data.tar.gz: 6501200475ed355b8cdbd04fd4fc9f0525ede3d2
3
+ metadata.gz: 0a0f9ca9f006e31daea83ccdb02443074130871b
4
+ data.tar.gz: 68658f42da8933ba16e841168918523928d18dd6
5
5
  SHA512:
6
- metadata.gz: 4671c104f6650f927717a11a23a7027a05803de1ae91393233d68226e644c16339478142d25441f71072147de2056468991d57a5d93a5bfa73220849ca082407
7
- data.tar.gz: 97fe968806cd43cc53f35d0d0842d3ca7926a8f736b6c86b6ebc69b00e10f838cac2fe2f2651109f53ee6d85b6bd9d3192fcf8ff8da60d5c52714fe75aa77618
6
+ metadata.gz: 75bc295c243700be46a4007d4671db6a0f9f9cd47175eadb4841e064a9ecb9411b54bb2da15f7c3c2371a9a4d7dbb0006a56bd21565fbd0b3134d517db4ca874
7
+ data.tar.gz: 063e2c27011dc96996b4f6ea5eed4e0775eaa035f793d2885e7b22cf99e00eedee80287fc9994e150064f4f617960f961e999cb9dc3ec771c971808f746afe5e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- determinations_comparison (0.0.5)
4
+ determinations_comparison (0.0.7)
5
5
  htmlentities
6
6
  uuidtools
7
7
 
data/README.md CHANGED
@@ -48,10 +48,25 @@ cmp.png_filepath # => location of PNG plot file
48
48
  cmp.baseline_filepath # => location of baseline file (copied to output folder)
49
49
  cmp.undertest_filepath # => location of undertest file (copied to output folder)
50
50
 
51
+ # a summary categorizing worst discrepancy within determination (if any)
52
+ cmp.hashCategory # => e.g. {:desc=>'difference with apex_intensity',:per_diff=>5}
53
+
51
54
  ```
52
55
 
53
56
  ##Special Options
54
57
 
58
+ The hashCategory property uses pre-set thresholds of 1% to determine whether a variation is considered a discrepancy.
59
+ However, these thresholds can be over-ridden by passing in an opt parameter like so:
60
+ ```ruby
61
+ baseline_file = 'path/to/baseline/file.po'
62
+ undertest_file = 'path/to/undertest/file.json'
63
+ opts = Hash.new
64
+ opts[:hashPropertyThresholds] = {:area=>3,:apex_time=>1,:apex_intensity=>5}
65
+ cmp = DeterminationsComparison::Comparison.new baseline_filepath , undertest_filepath, opts}
66
+
67
+ cmp.hashCategory # this will use thresholds described by hashPropertyThresholds parameter above
68
+ ```
69
+
55
70
  If you have ComputeDeterminations.py and/or CppLogReader.py libraries installed (see prerequisites), then Plot charts and pertinent peak-peaking information will be included in the HTML report.
56
71
 
57
72
  However, these must be within your system path. If they are not, you can specify the locations using the optional opts parameter like so:
@@ -76,6 +91,7 @@ opts[:folderpath_with_log] = '/path/to/folder/containing/logfile'
76
91
 
77
92
  cmp = DeterminationsComparison::Comparison.new baseline_filepath , undertest_filepath, opts}
78
93
  ```
94
+
79
95
  ##Key Mapping File (key_mapping.yaml)
80
96
 
81
97
  Assumption is made that all keys within .po files follow lower camel-case naming convention (e.g. myKey) and that keys within .json (compound) files follow snake-case naming convention and therefore a simple conversion from one key name is another is possible. However, there are cases where the naming conventions are not followed.
@@ -14,13 +14,15 @@ LIB_FOLDER = File.dirname(__FILE__)
14
14
  module DeterminationsComparison
15
15
 
16
16
  class Comparison
17
- attr_accessor :hashStd, :hashTgt, :html_filepath, :png_filepath, :baseline_filepath, :undertest_filepath
17
+ attr_accessor :hashStd, :hashTgt, :html_filepath, :png_filepath, :baseline_filepath, :undertest_filepath, :hashCategory
18
18
 
19
19
  def initialize(filepath_baseline,filepath_undertest,opts={})
20
20
 
21
21
  @filepath_comparedeterminations = opts[:filepath_comparedeterminations]
22
22
  @filepath_cpplogreader = opts[:filepath_cpplogreader]
23
23
 
24
+ hashPropertyThresholds = opts[:hashPropertyThresholds] || {:area=>1,:apex_time=>1,:apex_intensity=>1}
25
+
24
26
  @folderpath_with_log = opts[:folderpath_with_log] || File.dirname(filepath_baseline)
25
27
 
26
28
  @filepath_baseline_origin = filepath_baseline
@@ -36,8 +38,174 @@ module DeterminationsComparison
36
38
  differences 'Compound', hashCompoundUnderTest, hashCompoundBaseLine, @hashDiffs
37
39
  differences_extrapolated
38
40
 
41
+ @hashCategory = categorize hashPropertyThresholds
42
+
43
+ end
44
+
45
+ def to_html(folderpath_output)
46
+
47
+ FileUtils.mkdir_p folderpath_output
48
+
49
+ html_filepath = File.join folderpath_output, "#{@uuid}.html"
50
+ png_filepath = File.join folderpath_output, "#{@uuid}.png"
51
+ baseline_filepath = File.join folderpath_output, "#{@uuid}_baseline.json"
52
+ undertest_filepath = File.join folderpath_output, "#{@uuid}_undertest.json"
53
+
54
+ @plotter = Exe_CompareDeterminations.new @filepath_baseline_origin, @filepath_undertest_origin, @filepath_comparedeterminations
55
+
56
+ # these are necessary for cpplogreader
57
+ @sample_index = hashCompoundBaseLine['Sample_Index']
58
+ @analyte_name = hashCompoundBaseLine['Analyte']
59
+
60
+
61
+ str = ""
62
+ arr = Array.new
63
+
64
+ begin
65
+ coder = HTMLEntities.new
66
+ retcodePNG,rundetailsPNG = @plotter.generate_png png_filepath
67
+
68
+ FileUtils.copy_file @filepath_baseline_origin, baseline_filepath
69
+ FileUtils.copy_file @filepath_undertest_origin, undertest_filepath
70
+
71
+ str += "<p>baseline file: <a href=#{File.basename(baseline_filepath)}>#{File.basename(@filepath_baseline_origin)}</a></p>"
72
+ str += "<p>undertest file: <a href=#{File.basename(undertest_filepath)}>#{File.basename(@filepath_undertest_origin)}</a></p>"
73
+
74
+ if retcodePNG
75
+ str += "<p><p><p><img src='#{File.basename(png_filepath)}' alt='chromatogram' height='500' width='800' align='top'></p>"
76
+ end
77
+
78
+ @hashDiffs.each_pair do |k,v|
79
+
80
+ chrom_type = k
81
+
82
+ v.each_pair do |k,v|
83
+ if k == 'peak'
84
+ v.each_pair do |k,v|
85
+ arr << property_diff_to_hash(chrom_type,k,v)
86
+ end
87
+ else
88
+ unless k == 'peak_picked'
89
+ arr << property_diff_to_hash(chrom_type,k,v)
90
+ end
91
+ end
92
+
93
+ end
94
+
95
+ peak_picked = "unknown"
96
+ arrPP = v.select { |h| h['peak_picked'] }
97
+ unless arrPP.empty?
98
+ peak_picked = "#{arrPP.first[0]} #{arrPP.first[1]}"
99
+ end
100
+
101
+ str += "<p><p>"
102
+ str += "<p><b>#{k}</b> - #{peak_picked}</p>"
103
+
104
+ ht = HTML_Table_of_Peak_Picking_Log.new(@folderpath_with_log,@sample_index,@analyte_name,k)
105
+ str_pp = ht.render
106
+ unless str_pp.nil?
107
+ str += "<p><p>"
108
+ str += str_pp
109
+ str += "</p>"
110
+ end
111
+
112
+ end
113
+
114
+ ht = HTML_Table_of_Property_Differences.new(arr)
115
+ str_p = ht.render
116
+ unless str_p.nil?
117
+ str += "<p><p>"
118
+ str += str_p
119
+ str += "</p>"
120
+ end
121
+
122
+ File.open(html_filepath, "w") do |f|
123
+ f.write(str)
124
+ end
125
+
126
+ retcode = true
127
+
128
+ rescue Exception => e
129
+ retcode = false
130
+ $log_detercomp.error "unable to render html"
131
+ end
132
+
133
+ @html_filepath = html_filepath
134
+ @png_filepath = png_filepath
135
+ @baseline_filepath = baseline_filepath
136
+ @undertest_filepath = undertest_filepath
137
+
138
+
139
+ return retcode
140
+
141
+ end
142
+
143
+ def as_hash
144
+ @hashDiffs
145
+ end
146
+
147
+ private
148
+
149
+ def categorize(hashPropertyThresholds)
150
+
151
+ hashCategory = Hash.new
152
+
153
+ @hashDiffs.each_pair do |chrom,hashChrom|
154
+
155
+ # peak picked by baseline and not undertest?
156
+ if hashChrom['peak_picked'] == 'by baseline but not by undertest'
157
+ hashCategory[:desc] = "peak picked #{hashChrom['peak_picked']}"
158
+ end
159
+
160
+ break unless hashCategory.empty?
161
+
162
+ if hashChrom['peak_picked'] == 'by baseline (simpsons rule) but not by undertest'
163
+ hashCategory[:desc] = "peak picked #{hashChrom['peak_picked']}"
164
+ end
165
+
166
+ break unless hashCategory.empty?
167
+
168
+ # area within threshold?
169
+ per_diff = hashChrom['peak']['area'][:percent_diff]
170
+ threshold = hashPropertyThresholds[:area]
171
+ if per_diff > threshold
172
+ hashCategory[:desc] = 'difference in area'
173
+ hashCategory[:per_diff] = per_diff
174
+ end
175
+
176
+ break unless hashCategory.empty?
177
+
178
+ # apex time within threshold
179
+ per_diff = hashChrom['peak']['apex_time'][:percent_diff]
180
+ threshold = hashPropertyThresholds[:apex_time]
181
+ if per_diff > threshold
182
+ hashCategory[:desc] = 'difference in apex_time'
183
+ hashCategory[:per_diff] = per_diff
184
+ end
185
+
186
+ break unless hashCategory.empty?
187
+
188
+ # apex intensity within threshould
189
+ per_diff = hashChrom['peak']['apex_intensity'][:percent_diff]
190
+ threshold = hashPropertyThresholds[:apex_intensity]
191
+ if per_diff > threshold
192
+ hashCategory[:desc] = 'difference in apex_intensity'
193
+ hashCategory[:per_diff] = per_diff
194
+ end
195
+
196
+ break unless hashCategory.empty?
197
+
198
+ end
199
+
200
+ if hashCategory.empty?
201
+ hashCategory[:desc] = 'match within thresholds'
202
+ end
203
+
204
+ return hashCategory
205
+
39
206
  end
40
207
 
208
+
41
209
  def differences(item, hashUnderTest, hashBaseLine, hashDifferences)
42
210
 
43
211
  hashUnderTest.each_pair do |k_undertest,v_undertest|
@@ -59,7 +227,7 @@ module DeterminationsComparison
59
227
  @hashChromUnderTest = hashChromUnderTest
60
228
 
61
229
  chromtype_key_undertest =
62
- filetype_undertest == 'json' ? 'classifier' : 'SampleType'
230
+ filetype_undertest == 'json' ? 'classifier' : 'SampleType'
63
231
 
64
232
  chromtype_undertest = hashChromUnderTest[chromtype_key_undertest]
65
233
 
@@ -82,12 +250,12 @@ module DeterminationsComparison
82
250
  $log_detercomp.info "'#{k_undertest}' - comparing traces not supported yet"
83
251
  elsif(k_undertest == 'Peaks' || k_undertest == 'peak')
84
252
 
85
- @hashPeakUnderTest = v_undertest
86
- @hashPeakBaseLine = v_baseline
253
+ @hashPeakUnderTest = v_undertest
254
+ @hashPeakBaseLine = v_baseline
87
255
 
88
- hashDiff_Peak = Hash.new
89
- hashDifferences['peak'] = hashDiff_Peak
90
- differences 'Peak', @hashPeakUnderTest, @hashPeakBaseLine, hashDiff_Peak
256
+ hashDiff_Peak = Hash.new
257
+ hashDifferences['peak'] = hashDiff_Peak
258
+ differences 'Peak', @hashPeakUnderTest, @hashPeakBaseLine, hashDiff_Peak
91
259
 
92
260
  elsif v_undertest.respond_to? :each
93
261
  $log_detercomp.info "'#{k_undertest}' - comparison not supported"
@@ -111,8 +279,8 @@ module DeterminationsComparison
111
279
  end
112
280
 
113
281
  end
114
-
115
-
282
+
283
+
116
284
  end
117
285
 
118
286
  def differences_extrapolated
@@ -120,13 +288,13 @@ module DeterminationsComparison
120
288
  @hashDiffs.each_pair do |k,v|
121
289
 
122
290
  boolPeakPickedByBaseline =
123
- v['peak']['area'][:baseline] == 0 ? false:true
291
+ v['peak']['area'][:baseline] == 0 ? false:true
124
292
 
125
293
  boolPeakPickedByUnderTest =
126
- v['peak']['area'][:undertest] == 0 ? false:true
294
+ v['peak']['area'][:undertest] == 0 ? false:true
127
295
 
128
296
  boolSimpsonsRuleByBaseLine =
129
- v['peak']['nls_amp'][:baseline] == 0
297
+ v['peak']['nls_amp'][:baseline] == 0
130
298
 
131
299
  if boolPeakPickedByBaseline && !(boolPeakPickedByUnderTest)
132
300
 
@@ -153,107 +321,9 @@ module DeterminationsComparison
153
321
 
154
322
  end
155
323
 
156
- def to_html(folderpath_output)
157
-
158
- FileUtils.mkdir_p folderpath_output
159
-
160
- html_filepath = File.join folderpath_output, "#{@uuid}.html"
161
- png_filepath = File.join folderpath_output, "#{@uuid}.png"
162
- baseline_filepath = File.join folderpath_output, "#{@uuid}_baseline.json"
163
- undertest_filepath = File.join folderpath_output, "#{@uuid}_undertest.json"
164
-
165
- @plotter = Exe_CompareDeterminations.new @filepath_baseline_origin, @filepath_undertest_origin, @filepath_comparedeterminations
166
-
167
- # these are necessary for cpplogreader
168
- @sample_index = hashCompoundBaseLine['Sample_Index']
169
- @analyte_name = hashCompoundBaseLine['Analyte']
170
-
171
-
172
- str = ""
173
- arr = Array.new
174
-
175
- begin
176
- coder = HTMLEntities.new
177
- retcodePNG,rundetailsPNG = @plotter.generate_png png_filepath
178
-
179
- FileUtils.copy_file @filepath_baseline_origin, baseline_filepath
180
- FileUtils.copy_file @filepath_undertest_origin, undertest_filepath
181
-
182
- str += "<p>baseline file: <a href=#{File.basename(baseline_filepath)}>#{File.basename(@filepath_baseline_origin)}</a></p>"
183
- str += "<p>undertest file: <a href=#{File.basename(undertest_filepath)}>#{File.basename(@filepath_undertest_origin)}</a></p>"
184
-
185
- if retcodePNG
186
- str += "<p><p><p><img src='#{File.basename(png_filepath)}' alt='chromatogram' height='500' width='800' align='top'></p>"
187
- end
188
-
189
- @hashDiffs.each_pair do |k,v|
190
-
191
- chrom_type = k
192
-
193
- v.each_pair do |k,v|
194
- if k == 'peak'
195
- v.each_pair do |k,v|
196
- arr << property_diff_to_hash(chrom_type,k,v)
197
- end
198
- else
199
- unless k == 'peak_picked'
200
- arr << property_diff_to_hash(chrom_type,k,v)
201
- end
202
- end
203
-
204
- end
205
-
206
- peak_picked = "unknown"
207
- arrPP = v.select { |h| h['peak_picked'] }
208
- unless arrPP.empty?
209
- peak_picked = "#{arrPP.first[0]} #{arrPP.first[1]}"
210
- end
211
-
212
- str += "<p><p>"
213
- str += "<p><b>#{k}</b> - #{peak_picked}</p>"
214
-
215
- ht = HTML_Table_of_Peak_Picking_Log.new(@folderpath_with_log,@sample_index,@analyte_name,k)
216
- str_pp = ht.render
217
- unless str_pp.nil?
218
- str += "<p><p>"
219
- str += str_pp
220
- str += "</p>"
221
- end
222
-
223
- end
224
-
225
- ht = HTML_Table_of_Property_Differences.new(arr)
226
- str_p = ht.render
227
- unless str_p.nil?
228
- str += "<p><p>"
229
- str += str_p
230
- str += "</p>"
231
- end
232
-
233
- File.open(html_filepath, "w") do |f|
234
- f.write(str)
235
- end
236
-
237
- retcode = true
238
-
239
- rescue Exception => e
240
- retcode = false
241
- $log_detercomp.error "unable to render html"
242
- end
243
-
244
- @html_filepath = html_filepath
245
- @png_filepath = png_filepath
246
- @baseline_filepath = baseline_filepath
247
- @undertest_filepath = undertest_filepath
248
-
249
-
250
- return retcode
251
-
252
- end
253
-
254
324
  def get_baseline_and_undertest_values(item, hashParent, opts)
255
-
256
- k_baseline = opts[:k_baseline]
325
+
326
+ k_baseline = opts[:k_baseline]
257
327
  k_undertest = opts[:k_undertest]
258
328
  k_generic = opts[:k_generic]
259
329
 
@@ -272,37 +342,37 @@ module DeterminationsComparison
272
342
  end
273
343
 
274
344
  return val
275
-
276
-
345
+
346
+
277
347
  end
278
-
348
+
279
349
  def get_corresponding_key_value_from_other_file(file_type_to_get_key_value_for, item, unknown_hashParent, k_known)
280
350
 
281
351
  # guess at name of corresponding baseline key based on convention (i.e. convert snakecase to camelcase or vice-versa)
282
- if file_type_to_get_key_value_for == 'baseline'
283
- naming_convention_of_unknown = naming_convention_baseline
284
- naming_convention_of_known = naming_convention_undertest
285
- #naming_convention = naming_convention_baseline
286
- keytype_unknown = "#{filetype_baseline}_key"
287
- keytype_known = "#{filetype_undertest}_key"
352
+ if file_type_to_get_key_value_for == 'baseline'
353
+ naming_convention_of_unknown = naming_convention_baseline
354
+ naming_convention_of_known = naming_convention_undertest
355
+ #naming_convention = naming_convention_baseline
356
+ keytype_unknown = "#{filetype_baseline}_key"
357
+ keytype_known = "#{filetype_undertest}_key"
288
358
 
289
- else
290
- naming_convention_of_unknown = naming_convention_undertest
291
- naming_convention_of_known = naming_convention_baseline
359
+ else
360
+ naming_convention_of_unknown = naming_convention_undertest
361
+ naming_convention_of_known = naming_convention_baseline
292
362
 
293
- #naming_convention = naming_convention_undertest
294
- keytype_unknown = "#{filetype_undertest}_key"
295
- keytype_known = "#{filetype_baseline}_key"
363
+ #naming_convention = naming_convention_undertest
364
+ keytype_unknown = "#{filetype_undertest}_key"
365
+ keytype_known = "#{filetype_baseline}_key"
296
366
 
297
- end
367
+ end
298
368
 
299
369
  #convert known key to naming convention used by unknown file
300
370
  k_unknown =
301
- if naming_convention_of_unknown == 'snakecase'
302
- k_known.to_snakecase
303
- else
304
- k_known.to_camelcase_lower
305
- end
371
+ if naming_convention_of_unknown == 'snakecase'
372
+ k_known.to_snakecase
373
+ else
374
+ k_known.to_camelcase_lower
375
+ end
306
376
 
307
377
  if unknown_hashParent.has_key? k_unknown
308
378
  v_unknown = unknown_hashParent[k_unknown]
@@ -362,9 +432,9 @@ module DeterminationsComparison
362
432
  chg = diff / a.to_f
363
433
  calc = "#{b} - #{a} / #{a}"
364
434
  else a.to_f == 0
365
- diff = a.to_f - b.to_f
366
- chg = diff / b.to_f
367
- calc = "#{a} - #{b} / #{b}"
435
+ diff = a.to_f - b.to_f
436
+ chg = diff / b.to_f
437
+ calc = "#{a} - #{b} / #{b}"
368
438
  end
369
439
 
370
440
  diff = (chg * 100.0).round(2)
@@ -402,12 +472,6 @@ module DeterminationsComparison
402
472
 
403
473
  end
404
474
 
405
- def as_hash
406
- @hashDiffs
407
- end
408
-
409
- private
410
-
411
475
  def generic_key(key)
412
476
 
413
477
  unless key.downcase == key
@@ -1,3 +1,3 @@
1
1
  module DeterminationsComparison
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -29,6 +29,12 @@ describe 'determinations_comparison' do
29
29
  expect(hash.size).to eq(2)
30
30
  end
31
31
 
32
+ it 'should categorize determination' do
33
+ comparison = DeterminationsComparison::Comparison.new( baseline_file, undertest_file, {:folderpath_output=>folderpath_output})
34
+
35
+ expect(comparison.hashCategory[:desc]).to eq('peak picked by baseline but not by undertest')
36
+ end
37
+
32
38
  it 'should show differences in html table and peak plots' do
33
39
  comparison = DeterminationsComparison::Comparison.new( baseline_file, undertest_file)
34
40
 
@@ -18,7 +18,7 @@ describe 'generating html table of differences' do
18
18
  end
19
19
 
20
20
  after :each do
21
- # FileUtils.remove file
21
+ FileUtils.remove file
22
22
  end
23
23
 
24
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: determinations_comparison
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shawn Hooper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-05 00:00:00.000000000 Z
11
+ date: 2013-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler