-
Notifications
You must be signed in to change notification settings - Fork 10
/
analyze-psm.rb
executable file
·411 lines (363 loc) · 24 KB
/
analyze-psm.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
45
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
#! /usr/bin/env ruby
# Copyright (c) 2007-2008 Michael Specht
#
# This file is part of Proteomatic.
#
# Proteomatic is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Proteomatic is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Proteomatic. If not, see <http://www.gnu.org/licenses/>.
require './include/ruby/proteomatic'
require './include/ruby/ext/fastercsv'
require './include/ruby/misc'
require 'bigdecimal'
require 'set'
require 'yaml'
=begin
plot estimated fpr vs. score threshold (target/decoy only)
plot score histogram
plot mass accuracy histogram
=end
class AnalyzePsm < ProteomaticScript
def drawHistogram(ak_Out, ak_Parameters)
end
def scale(af_Value, af_Min, af_Max)
return (af_Value - af_Min) / (af_Max - af_Min) * (@mi_ClientWidth - 20) + 10
end
def scaley(af_Value, af_Min, af_Max)
return (af_Value - af_Min) / (af_Max - af_Min) * (@mi_ClientHeight - 20) + 10
end
def run()
if @output[:psmAnalysis]
File.open(@output[:psmAnalysis], 'w') do |lk_Out|
lk_Out.puts "<?xml version='1.0' encoding='utf-8' ?>"
lk_Out.puts "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>"
lk_Out.puts "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='de'>"
lk_Out.puts '<head>'
lk_Out.puts '<title>PSM Analysis</title>'
printStyleSheet(lk_Out)
lk_Out.puts '</head>'
lk_Out.puts '<body>'
lk_Out.puts "<h1>PSM Analysis</h1>"
@input[:omssaResults].each do |ls_Path|
lk_Out.puts "<h2>#{File.basename(ls_Path)}</h2>"
print "#{File.basename(ls_Path)}: "
lk_ScanHash = Hash.new
ld_ScoreMinimum = BigDecimal.new("1.0")
ld_ScoreMaximum = BigDecimal.new("0.0")
ld_PpmMaximum = 0.0
li_PsmCount = 0
File.open(ls_Path) do |lk_File|
lk_Header = mapCsvHeader(lk_File.readline)
lk_File.each_line do |ls_Line|
lk_Line = ls_Line.parse_csv
ls_ScanId = lk_Line[lk_Header['filenameid']].split('.').slice(0, 2).join('.')
lf_Mass = lk_Line[lk_Header['mass']].to_f
lf_TheoMass = lk_Line[lk_Header['theomass']].to_f
lf_Ppm = ((lf_Mass - lf_TheoMass).abs / lf_TheoMass) * 1000000.0
next unless lk_Line[lk_Header['defline']].index(@param[:targetEntryPrefix]) == 0 || lk_Line[lk_Header['defline']].index(@param[:decoyEntryPrefix]) == 0
li_PsmCount += 1
lk_Psm = {
:peptide => lk_Line[lk_Header['peptide']].upcase,
:score => BigDecimal.new(lk_Line[lk_Header['evalue']]),
:ppm => lf_Ppm,
:decoy => (lk_Line[lk_Header['defline']].index(@param[:decoyEntryPrefix]) == 0)
}
if (lk_ScanHash.include?(ls_ScanId))
lk_ScanHash[ls_ScanId] = lk_Psm if (lk_Psm[:score] < lk_ScanHash[ls_ScanId][:score])
else
lk_ScanHash[ls_ScanId] = lk_Psm
end
ld_ScoreMinimum = lk_Psm[:score] if lk_Psm[:score] < ld_ScoreMinimum
ld_ScoreMaximum = lk_Psm[:score] if lk_Psm[:score] > ld_ScoreMaximum
ld_PpmMaximum = lf_Ppm if lf_Ppm > ld_PpmMaximum
end
end
puts "There were #{li_PsmCount} PSM in #{lk_ScanHash.size} scans."
ld_ScaleMinimum = Math.log10(ld_ScoreMinimum).floor
@mi_Width = 800
@mi_Height = 400
@mi_Left = 35.0
@mi_Top = 0.0
@mi_Right = 0.0
@mi_Bottom = 20.0
@mi_ClientWidth = @mi_Width.to_f - @mi_Left - @mi_Right
@mi_ClientHeight = @mi_Height.to_f - @mi_Top - @mi_Bottom
lk_Out.puts "<h3>Score histogram</h3>"
lk_Histogram = Array.new
@mi_ClientWidth.to_i.times { lk_Histogram << 0 }
li_HistogramMax = 0
lk_ScanHash.each do |ls_Key, lk_Psm|
ld_Scale = Math.log10(lk_Psm[:score])
li_Bucket = scale(ld_Scale, ld_ScaleMinimum, 0.0).to_i
li_Bucket = 0 if li_Bucket < 0
li_Bucket = @mi_ClientWidth - 1 if li_Bucket > @mi_ClientWidth - 1
lk_Histogram[li_Bucket] += 1
li_HistogramMax = lk_Histogram[li_Bucket] if lk_Histogram[li_Bucket] > li_HistogramMax
end
lk_Out.puts "<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:ev='http://www.w3.org/2001/xml-events' version='1.1' baseProfile='full' width='#{@mi_Width}px' height='#{@mi_Height}px'><rect x='0' y='0' width='#{@mi_Width}px' height='#{@mi_Height}px' fill='#fff' />"
lk_Out.puts "<rect x='#{@mi_Left}' y='#{@mi_Top}' width='#{@mi_ClientWidth}' height='#{@mi_ClientHeight}' stroke='#888a85' fill='#eeeeec' />"
lk_Out.print "<polyline points='"
lk_Out.print "#{@mi_Left} #{@mi_Height - @mi_Bottom} "
(0...@mi_ClientWidth - 1).each do |i|
lk_Out.print "#{i + @mi_Left} #{@mi_Height - @mi_Bottom - (lk_Histogram[i].to_f / li_HistogramMax) * @mi_ClientHeight} "
end
lk_Out.print "#{@mi_Left + @mi_ClientWidth - 1} #{@mi_Height - @mi_Bottom} "
lk_Out.puts "' fill='#729fcf' stroke='none' stroke-width='0.75px'/>"
# draw lower legend
ld_ScaleStart = ld_ScaleMinimum
ld_ScaleEnd = 1.0
li_CurrentScale = 0
li_ScaleSkip = 1
ld_Distance = 0.0
begin
ld_Distance = (scale(li_CurrentScale, ld_ScaleMinimum, 0.0) -
scale(li_CurrentScale - li_ScaleSkip, ld_ScaleMinimum, 0.0)).abs
break unless ld_Distance < 32.0
li_ScaleSkip += 1
end while ld_Distance < 32.0
while (li_CurrentScale >= ld_ScaleMinimum)
x = scale(li_CurrentScale, ld_ScaleMinimum, 0.0) + @mi_Left
ls_Label = li_CurrentScale == 0 ? '1.0' : "1e#{li_CurrentScale}"
lk_Out.puts "<polyline points='#{x} #{@mi_Height - @mi_Bottom} #{x} #{@mi_Height - @mi_Bottom + 4.0}' stroke='#555753' stroke-width='1.0px' />"
lk_Out.puts "<text x='#{x}' y='#{@mi_Height - @mi_Bottom + 12}' style='font-size: 6pt; text-anchor: middle;'>#{ls_Label}</text>"
li_CurrentScale -= li_ScaleSkip
end
# draw left legend
li_CurrentScale = 0
lk_ScaleSkips = [1, 2, 5]
li_ScaleSkipIndex = 0
li_ScaleExponent = 0
ld_Distance = 0.0
begin
li_ScaleSkip = lk_ScaleSkips[li_ScaleSkipIndex] * (10 ** li_ScaleExponent)
ld_Distance = (((li_CurrentScale.to_f / li_HistogramMax) * @mi_ClientHeight) -
(((li_CurrentScale + li_ScaleSkip).to_f / li_HistogramMax) * @mi_ClientHeight)).abs
break unless ld_Distance < 16.0
li_ScaleSkipIndex += 1
if (li_ScaleSkipIndex > lk_ScaleSkips.size - 1)
li_ScaleSkipIndex = 0
li_ScaleExponent += 1
end
end while ld_Distance < 16.0
li_ScaleSkip = lk_ScaleSkips[li_ScaleSkipIndex] * (10 ** li_ScaleExponent)
while (li_CurrentScale <= li_HistogramMax)
ld_Position = @mi_Height.to_f - @mi_Bottom - (li_CurrentScale.to_f / li_HistogramMax) * @mi_ClientHeight
ls_Label = "#{li_CurrentScale}"
lk_Out.puts "<polyline points='#{@mi_Left - 4} #{ld_Position} #{@mi_Left} #{ld_Position}' stroke='#555753' stroke-width='1.0px' />"
lk_Out.puts "<text x='#{@mi_Left - 6}' y='#{ld_Position + 4}' style='font-size: 6pt; text-anchor: end;'>#{ls_Label}</text>"
li_CurrentScale += li_ScaleSkip
end
lk_Out.puts "</svg>"
lk_Out.puts "<h3>Mass accuracy histogram</h3>"
lk_Histogram = Array.new
@mi_ClientWidth.to_i.times { lk_Histogram << 0 }
lk_ScanHash.each do |ls_Key, lk_Psm|
li_Bucket = scale(lk_Psm[:ppm], 0.0, ld_PpmMaximum).to_i
li_Bucket = 0 if li_Bucket < 0
li_Bucket = @mi_ClientWidth - 1 if li_Bucket > @mi_ClientWidth - 1
lk_Histogram[li_Bucket] += 1
li_HistogramMax = lk_Histogram[li_Bucket] if lk_Histogram[li_Bucket] > li_HistogramMax
end
lk_Out.puts "<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:ev='http://www.w3.org/2001/xml-events' version='1.1' baseProfile='full' width='#{@mi_Width}px' height='#{@mi_Height}px'><rect x='0' y='0' width='#{@mi_Width}px' height='#{@mi_Height}px' fill='#fff' />"
lk_Out.puts "<rect x='#{@mi_Left}' y='#{@mi_Top}' width='#{@mi_ClientWidth}' height='#{@mi_ClientHeight}' stroke='#888a85' fill='#eeeeec' />"
lk_Out.print "<polyline points='"
lk_Out.print "#{@mi_Left} #{@mi_Height - @mi_Bottom} "
(0...@mi_ClientWidth).each do |i|
lk_Out.print "#{i + @mi_Left} #{@mi_Height - @mi_Bottom - ((lk_Histogram[i].to_f / li_HistogramMax)) * @mi_ClientHeight} "
end
lk_Out.print "#{@mi_ClientWidth + @mi_Left} #{@mi_Height - @mi_Bottom} "
lk_Out.puts "' fill='#729fcf' stroke='none' stroke-width='0.75px'/>"
# draw lower legend
li_CurrentScale = 0.0
lk_ScaleSkips = [1, 2, 5]
li_ScaleSkipIndex = 0
li_ScaleExponent = -2
ld_Distance = 0.0
begin
li_ScaleSkip = lk_ScaleSkips[li_ScaleSkipIndex] * (10 ** li_ScaleExponent)
ld_Distance = (scale(li_CurrentScale, 0.0, ld_PpmMaximum) -
scale(li_CurrentScale + li_ScaleSkip, 0.0, ld_PpmMaximum)).abs
break unless ld_Distance < 32.0
li_ScaleSkipIndex += 1
if (li_ScaleSkipIndex > lk_ScaleSkips.size - 1)
li_ScaleSkipIndex = 0
li_ScaleExponent += 1
end
end while ld_Distance < 32.0
li_ScaleSkip = lk_ScaleSkips[li_ScaleSkipIndex] * (10 ** li_ScaleExponent)
while (li_CurrentScale <= ld_PpmMaximum)
ld_Position = scale(li_CurrentScale, 0.0, ld_PpmMaximum) + @mi_Left
ls_Label = "#{li_CurrentScale}"
lk_Out.puts "<polyline points='#{ld_Position} #{@mi_Height - @mi_Bottom} #{ld_Position} #{@mi_Height - @mi_Bottom + 4.0}' stroke='#555753' stroke-width='1.0px' />"
lk_Out.puts "<text x='#{ld_Position}' y='#{@mi_Height - @mi_Bottom + 12}' style='font-size: 6pt; text-anchor: middle;'>#{ls_Label}</text>"
li_CurrentScale += li_ScaleSkip
end
# draw left legend
li_CurrentScale = 0
lk_ScaleSkips = [1, 2, 5]
li_ScaleSkipIndex = 0
li_ScaleExponent = 0
ld_Distance = 0.0
begin
li_ScaleSkip = lk_ScaleSkips[li_ScaleSkipIndex] * (10 ** li_ScaleExponent)
ld_Distance = (((li_CurrentScale.to_f / li_HistogramMax) * @mi_ClientHeight) -
(((li_CurrentScale + li_ScaleSkip).to_f / li_HistogramMax) * @mi_ClientHeight)).abs
break unless ld_Distance < 16.0
li_ScaleSkipIndex += 1
if (li_ScaleSkipIndex > lk_ScaleSkips.size - 1)
li_ScaleSkipIndex = 0
li_ScaleExponent += 1
end
end while ld_Distance < 16.0
li_ScaleSkip = lk_ScaleSkips[li_ScaleSkipIndex] * (10 ** li_ScaleExponent)
while (li_CurrentScale <= li_HistogramMax)
ld_Position = @mi_Height.to_f - @mi_Bottom - (li_CurrentScale.to_f / li_HistogramMax) * @mi_ClientHeight
ls_Label = "#{li_CurrentScale}"
lk_Out.puts "<polyline points='#{@mi_Left - 4} #{ld_Position} #{@mi_Left} #{ld_Position}' stroke='#555753' stroke-width='1.0px' />"
lk_Out.puts "<text x='#{@mi_Left - 6}' y='#{ld_Position + 4}' style='font-size: 6pt; text-anchor: end;'>#{ls_Label}</text>"
li_CurrentScale += li_ScaleSkip
end
lk_Out.puts "</svg>"
@mi_Left = 35.0
@mi_Top = 20.0
@mi_Right = 35.0
@mi_Bottom = 20.0
@mi_ClientWidth = @mi_Width.to_f - @mi_Left - @mi_Right
@mi_ClientHeight = @mi_Height.to_f - @mi_Top - @mi_Bottom
lk_Out.puts "<h3>FPR plot</h3>"
lk_SortedByScore = lk_ScanHash.keys.sort { |a, b| lk_ScanHash[a][:score] <=> lk_ScanHash[b][:score] }
lk_Histogram = Array.new
lf_LogScale = 0.4
lf_TotalCount = 0.0
li_TargetCount = 0
li_DecoyCountUnweighted = 0
lf_DecoyCount = 0.0
lk_SortedByScore.each do |ls_Key|
lk_Psm = lk_ScanHash[ls_Key]
if lk_Psm[:decoy]
li_DecoyCountUnweighted += 1
lf_DecoyCount = li_DecoyCountUnweighted.to_f / @param[:decoyAmount]
else
li_TargetCount += 1
end
lf_TotalCount = lf_DecoyCount + li_TargetCount
lf_Fpr = 2.0
if @param[:fprCalculation] == 'd_t'
if li_TargetCount > 0
lf_Fpr = li_DecoyCountUnweighted.to_f / li_TargetCount
end
else
lf_Fpr = lf_DecoyCount * 2.0 / lf_TotalCount
end
lf_Fpr *= 0.5
lk_Histogram << {:fpr => lf_Fpr, :score => lk_Psm[:score], :decoyCount => lf_DecoyCount / lk_SortedByScore.size, :targetCount => (lf_TotalCount - lf_DecoyCount).to_f / lk_SortedByScore.size }
end
lk_Out.puts "<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:ev='http://www.w3.org/2001/xml-events' version='1.1' baseProfile='full' width='#{@mi_Width}px' height='#{@mi_Height}px'><rect x='0' y='0' width='#{@mi_Width}px' height='#{@mi_Height}px' fill='#fff' />"
li_Shift = 0
lk_Out.puts "<polyline points='#{@mi_Left} 8 #{@mi_Left + 16} 8' fill='none' stroke='#729fcf' stroke-width='1.5px' />"
lk_Out.puts "<text x='#{@mi_Left + 20}' y='12' style='font-size: 8pt;'>estimated FPR</text>"
li_Shift += 110
lk_Out.puts "<polyline points='#{@mi_Left + li_Shift} 8 #{@mi_Left + 16 + li_Shift} 8' fill='none' stroke='#8ae234' stroke-width='1.5px' />"
lk_Out.puts "<text x='#{@mi_Left + 20 + li_Shift}' y='12' style='font-size: 8pt;'>score</text>"
li_Shift += 65
lk_Out.puts "<rect x='#{@mi_Left + li_Shift}' y='5' width='16' height='6' fill='#8ae234' fill-opacity='0.3' stroke='#73d216' stroke-width='0.75px' />"
lk_Out.puts "<text x='#{@mi_Left + 20 + li_Shift}' y='12' style='font-size: 8pt;'>target hits</text>"
li_Shift += 90
lk_Out.puts "<rect x='#{@mi_Left + li_Shift}' y='5' width='16' height='6' fill='#ef2929' fill-opacity='0.3' stroke='#cc0000' stroke-width='0.75px' />"
lk_Out.puts "<text x='#{@mi_Left + 20 + li_Shift}' y='12' style='font-size: 8pt;'>decoy hits</text>"
lk_Out.puts "<rect x='#{@mi_Left}' y='#{@mi_Top}' width='#{@mi_ClientWidth}' height='#{@mi_ClientHeight}' stroke='#888a85' fill='#eeeeec' />"
# draw target background triangle
lk_Out.print "<polyline points='"
lk_Out.print "#{@mi_Left} #{@mi_Height - @mi_Bottom} "
lk_Out.print "#{@mi_Width - @mi_Right} #{@mi_Height - @mi_Bottom} "
lk_Out.print "#{@mi_Width - @mi_Right} #{@mi_Top} "
lk_Out.print "#{@mi_Left} #{@mi_Height - @mi_Bottom} "
lk_Out.puts "' fill='#8ae234' fill-opacity='0.3' stroke='#73d216' stroke-width='0.75px'/>"
# draw decoy amount
lk_Out.print "<polyline points='"
lk_Out.print "#{@mi_Left} #{@mi_Height - @mi_Bottom} "
(0...lk_Histogram.size).each do |i|
lk_Out.print "#{i.to_f / (lk_Histogram.size) * @mi_ClientWidth + @mi_Left} #{@mi_Height - @mi_Bottom - (lk_Histogram[i][:decoyCount]) * @mi_ClientHeight} "
end
lk_Out.print "#{@mi_Width - @mi_Right} #{@mi_Height - @mi_Bottom} "
lk_Out.puts "' fill='#ef2929' fill-opacity='0.3' stroke='#cc0000' stroke-width='0.75px'/>"
[1.0, 0.1, 0.01, 0.001].each do |x|
lk_Out.puts "<polyline points='#{@mi_Left} #{@mi_Height - @mi_Bottom - (((x * 0.5) ** lf_LogScale)) * @mi_ClientHeight} #{@mi_Width - @mi_Right} #{@mi_Height - @mi_Bottom - (((x * 0.5) ** lf_LogScale)) * @mi_ClientHeight}' fill='none' stroke='#888a85' stroke-width='0.5px' />"
lk_Out.puts "<text style='text-anchor: end; font-size: 6pt;' x='#{@mi_Left - 4}' y='#{@mi_Height - @mi_Bottom - (((x * 0.5) ** lf_LogScale)) * @mi_ClientHeight}'>#{x < 0.01 ? x * 100.0: (x * 100.0).to_i}%</text>"
end
# draw estimated FPR
lk_Out.print "<polyline points='"
(0...lk_Histogram.size).each do |i|
lk_Out.print "#{i.to_f / (lk_Histogram.size) * @mi_ClientWidth + @mi_Left} #{@mi_Height - @mi_Bottom - (lk_Histogram[i][:fpr] ** lf_LogScale) * @mi_ClientHeight} " if lk_Histogram[i][:fpr] > 0.0
end
lk_Out.puts "' fill='none' stroke='#729fcf' stroke-width='1px'/>"
# draw score
ld_ScaleMinimum = Math.log10(ld_ScoreMinimum)
lk_Out.print "<polyline points='"
(0...lk_Histogram.size).each do |i|
lk_Out.print "#{i.to_f / (lk_Histogram.size) * @mi_ClientWidth + @mi_Left} #{scaley(Math.log10(lk_Histogram[i][:score]), 0.0, ld_ScaleMinimum) + @mi_Top} "
end
lk_Out.puts "' fill='none' stroke='#8ae234' stroke-width='1px'/>"
# draw lower legend
li_CurrentScale = 0
lk_ScaleSkips = [1, 2, 5]
li_ScaleSkipIndex = 0
li_ScaleExponent = 0
ld_Distance = 0.0
begin
li_ScaleSkip = lk_ScaleSkips[li_ScaleSkipIndex] * (10 ** li_ScaleExponent)
ld_Distance = (scale(li_CurrentScale.to_f, 0, lf_TotalCount) -
scale(li_CurrentScale.to_f + li_ScaleSkip, 0, lf_TotalCount)).abs
break unless ld_Distance < 32.0
li_ScaleSkipIndex += 1
if (li_ScaleSkipIndex > lk_ScaleSkips.size - 1)
li_ScaleSkipIndex = 0
li_ScaleExponent += 1
end
end while ld_Distance < 32.0
li_ScaleSkip = lk_ScaleSkips[li_ScaleSkipIndex] * (10 ** li_ScaleExponent)
while (li_CurrentScale <= lf_TotalCount)
ld_Position = scale(li_CurrentScale.to_f, 0, lf_TotalCount) + @mi_Left
ls_Label = "#{li_CurrentScale}"
lk_Out.puts "<polyline points='#{ld_Position} #{@mi_Height - @mi_Bottom} #{ld_Position} #{@mi_Height - @mi_Bottom + 4}' stroke='#555753' stroke-width='1.0px' />"
lk_Out.puts "<text x='#{ld_Position}' y='#{@mi_Height - @mi_Bottom + 12}' style='font-size: 6pt; text-anchor: middle;'>#{ls_Label}</text>"
li_CurrentScale += li_ScaleSkip
end
# draw right legend
ld_ScaleMinimum = Math.log10(ld_ScoreMinimum)
ld_ScaleStart = ld_ScaleMinimum
ld_ScaleEnd = 1.0
li_CurrentScale = 0
li_ScaleSkip = 1
ld_Distance = 0.0
begin
ld_Distance = (scaley(li_CurrentScale.to_f, 0.0, ld_ScaleMinimum) -
scaley(li_CurrentScale.to_f - li_ScaleSkip, 0.0, ld_ScaleMinimum)).abs
break unless ld_Distance < 16.0
li_ScaleSkip += 1
end while ld_Distance < 16.0
while (li_CurrentScale >= ld_ScaleMinimum)
ld_Position = scaley(li_CurrentScale.to_f, 0.0, ld_ScaleMinimum) + @mi_Top
ls_Label = li_CurrentScale == 0 ? '1.0' : "1e#{li_CurrentScale}"
lk_Out.puts "<polyline points='#{@mi_Width - @mi_Right} #{ld_Position} #{@mi_Width - @mi_Right + 4} #{ld_Position}' stroke='#555753' stroke-width='1.0px' />"
lk_Out.puts "<text x='#{@mi_Width - @mi_Right + 6.0}' y='#{ld_Position + 3.0}' style='font-size: 6pt; text-anchor: start;'>#{ls_Label}</text>"
li_CurrentScale -= li_ScaleSkip
end
lk_Out.puts "</svg>"
end
lk_Out.puts '</body>'
lk_Out.puts '</html>'
end
end
end
end
script = AnalyzePsm.new