Class: DeterminationsComparison::Comparison

Inherits:
Object
  • Object
show all
Defined in:
lib/determinations_comparison.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath_baseline, filepath_undertest, opts = {}) ⇒ Comparison

Returns a new instance of Comparison.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/determinations_comparison.rb', line 20

def initialize(filepath_baseline,filepath_undertest,opts={})

  @filepath_comparedeterminations = opts[:filepath_comparedeterminations]
  @filepath_cpplogreader =          opts[:filepath_cpplogreader]

  hashPropertyThresholds = opts[:hashPropertyThresholds] || {:area=>0,:apex_time=>0,:apex_intensity=>0}

  @folderpath_with_log = opts[:folderpath_with_log] || File.dirname(filepath_undertest)

  @filepath_baseline_origin = filepath_baseline
  @filepath_undertest_origin = filepath_undertest

  @filepath_keymapping = File.join( LIB_FOLDER,'..','config','key_mapping.yaml')

  @uuid = UUIDTools::UUID.random_create

  $log_detercomp = Logger.new File.join(LIB_FOLDER,'..',"log.txt")

  @hashDiffs = Hash.new
  differences 'Compound', hashCompoundUnderTest, hashCompoundBaseLine, @hashDiffs
  differences_extrapolated

  @hashCategory = categorize hashPropertyThresholds

end

Instance Attribute Details

#baseline_filepathObject

Returns the value of attribute baseline_filepath.



18
19
20
# File 'lib/determinations_comparison.rb', line 18

def baseline_filepath
  @baseline_filepath
end

#filepath_baseline_originObject

Returns the value of attribute filepath_baseline_origin.



18
19
20
# File 'lib/determinations_comparison.rb', line 18

def filepath_baseline_origin
  @filepath_baseline_origin
end

#filepath_undertest_originObject

Returns the value of attribute filepath_undertest_origin.



18
19
20
# File 'lib/determinations_comparison.rb', line 18

def filepath_undertest_origin
  @filepath_undertest_origin
end

#hashCategoryObject

Returns the value of attribute hashCategory.



18
19
20
# File 'lib/determinations_comparison.rb', line 18

def hashCategory
  @hashCategory
end

#hashStdObject

Returns the value of attribute hashStd.



18
19
20
# File 'lib/determinations_comparison.rb', line 18

def hashStd
  @hashStd
end

#hashTgtObject

Returns the value of attribute hashTgt.



18
19
20
# File 'lib/determinations_comparison.rb', line 18

def hashTgt
  @hashTgt
end

#html_filepathObject

Returns the value of attribute html_filepath.



18
19
20
# File 'lib/determinations_comparison.rb', line 18

def html_filepath
  @html_filepath
end

#png_filepathObject

Returns the value of attribute png_filepath.



18
19
20
# File 'lib/determinations_comparison.rb', line 18

def png_filepath
  @png_filepath
end

#undertest_filepathObject

Returns the value of attribute undertest_filepath.



18
19
20
# File 'lib/determinations_comparison.rb', line 18

def undertest_filepath
  @undertest_filepath
end

Instance Method Details

#as_hashObject



167
168
169
# File 'lib/determinations_comparison.rb', line 167

def as_hash
  @hashDiffs
end

#to_html(folderpath_output) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/determinations_comparison.rb', line 46

def to_html(folderpath_output)

  FileUtils.mkdir_p folderpath_output

  html_filepath = File.join      folderpath_output, "#{@uuid}.html"
  png_filepath = File.join       folderpath_output, "#{@uuid}.png"
  baseline_filepath = File.join  folderpath_output, "#{@uuid}_baseline.json"
  undertest_filepath = File.join folderpath_output, "#{@uuid}_undertest.json"

  # these are necessary for cpplogreader
  @sample_index = hashCompoundBaseLine['Sample_Index']
  @analyte_name = hashCompoundBaseLine['Analyte']

  begin

    #coder = HTMLEntities.new

    FileUtils.copy_file @filepath_baseline_origin, baseline_filepath
    FileUtils.copy_file @filepath_undertest_origin, undertest_filepath

    # html for file links
      strFiles = "<p>baseline file: <a href=#{File.basename(baseline_filepath)}>#{File.basename(@filepath_baseline_origin)}</a></p>"
      strFiles += "<p>undertest file: <a href=#{File.basename(undertest_filepath)}>#{File.basename(@filepath_undertest_origin)}</a></p>"

    # html for plot
      strPlot = nil
      @plotter = Exe_CompareDeterminations.new @filepath_baseline_origin, @filepath_undertest_origin, @filepath_comparedeterminations
      retcodePNG,rundetailsPNG = @plotter.generate_png png_filepath
      if retcodePNG
        strPlot = "<img src='#{File.basename(png_filepath)}' alt='chromatogram' height='500' width='800' align='top'>"
      end

    # html for peak picking logs
      hashChromHTML = Hash.new

      @hashDiffs.each_pair do |k,v|

        chrom_type = k

        ht = HTML_Table_of_Peak_Picking_Log.new(@folderpath_with_log,@sample_index,@analyte_name,k)
        str_pp = ht.render
        unless str_pp.nil?

          peak_picked = "unknown"
          arrPP = v.select { |h| h['peak_picked'] }
          unless arrPP.empty?
            peak_picked = "#{arrPP.first[0]} #{arrPP.first[1]}"
          end

          strChrom = "<p><b>#{chrom_type}</b> - #{peak_picked}</p>"
          strChrom += str_pp
        end

        hashChromHTML[k] = strChrom

      end

    # html for property differences
      arr = Array.new

      @hashDiffs.each_pair do |k,v|

        chrom_type = k

        v.each_pair do |k,v|
          if k == 'peak'
            v.each_pair do |k,v|
              arr << property_diff_to_hash(chrom_type,k,v)
            end
          else
            unless k == 'peak_picked'
              arr << property_diff_to_hash(chrom_type,k,v)
            end
          end

        end

      end

    strProps = nil

    ht = HTML_Table_of_Property_Differences.new(arr)
    str_p = ht.render
    unless str_p.nil?
      strProps = str_p
    end

    strFull = strFiles
    strFull += strPlot unless strPlot.nil?

    hashGroups = Hash.new
    hashGroups['Properties'] = strProps
    hashChromHTML.each_pair do |k,v|
      hashGroups["Pick Log - #{k.to_s}"] = v
    end

    jt = Jquery_Tabs.new hashGroups
    strFull += jt.render


    File.open(html_filepath, "w") do |f|
      f.write(strFull)
    end

    retcode = true

  rescue Exception => e
    retcode = false
    $log_detercomp.error "unable to render html"
  end

  @html_filepath = html_filepath
  @png_filepath = png_filepath
  @baseline_filepath = baseline_filepath
  @undertest_filepath = undertest_filepath


  return retcode

end