Class: ROCWindow
- Inherits:
-
Object
- Object
- ROCWindow
- Defined in:
- lib/rocker/rocwindow.rb
Overview
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#hits ⇒ Object
readonly
Returns the value of attribute hits.
-
#thr ⇒ Object
readonly
Returns the value of attribute thr.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
-
#tps ⇒ Object
readonly
Returns the value of attribute tps.
Instance Method Summary collapse
- #almost_empty ⇒ Object
- #around_thr ⇒ Object
- #compute! ⇒ Object
- #fps ⇒ Object
-
#initialize(data, from = nil, to = nil) ⇒ ROCWindow
constructor
A new instance of ROCWindow.
- #length ⇒ Object
- #load_hits ⇒ Object
- #next ⇒ Object
- #previous ⇒ Object
- #rrun(cmd, type = nil) ⇒ Object
- #thr_notnil ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data, from = nil, to = nil) ⇒ ROCWindow
Returns a new instance of ROCWindow.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rocker/rocwindow.rb', line 10 def initialize(data, from=nil, to=nil) @data = data if from.is_a? String r = from.split(/\t/) @from = r[0].to_i @to = r[1].to_i @hits = r[2].to_i @tps = r[3].to_i @thr = r[4].to_f else a = from.nil? ? 1 : [from,1].max b = to.nil? ? data.aln.cols : [to,data.aln.cols].min @from = [a,b].min @to = [a,b].max @thr = nil compute! end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
9 10 11 |
# File 'lib/rocker/rocwindow.rb', line 9 def data @data end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
9 10 11 |
# File 'lib/rocker/rocwindow.rb', line 9 def from @from end |
#hits ⇒ Object (readonly)
Returns the value of attribute hits.
9 10 11 |
# File 'lib/rocker/rocwindow.rb', line 9 def hits @hits end |
#thr ⇒ Object (readonly)
Returns the value of attribute thr.
9 10 11 |
# File 'lib/rocker/rocwindow.rb', line 9 def thr @thr end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
9 10 11 |
# File 'lib/rocker/rocwindow.rb', line 9 def to @to end |
#tps ⇒ Object (readonly)
Returns the value of attribute tps.
9 10 11 |
# File 'lib/rocker/rocwindow.rb', line 9 def tps @tps end |
Instance Method Details
#almost_empty ⇒ Object
60 |
# File 'lib/rocker/rocwindow.rb', line 60 def almost_empty() fps < 3 or tps < 3 end |
#around_thr ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rocker/rocwindow.rb', line 41 def around_thr a = self.previous b = self.next while not a.nil? and a.thr.nil? a = a.previous end while not b.nil? and b.thr.nil? b = b.next end return nil if a.nil? and b.nil? return a.thr if b.nil? return b.thr if a.nil? return (b.thr*(from-a.from) - a.thr*(from-b.from))/(b.from-a.from) end |
#compute! ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rocker/rocwindow.rb', line 28 def compute! load_hits @hits = rrun("nrow(y);", :int) @tps = rrun("sum(y$V5==1);", :int) unless almost_empty rrun "rocobj <- roc(as.numeric(y$V5==1), y$V4);" thr = rrun("coords(rocobj, 'best', ret='threshold', " + "best.method='youden', " + "best.weights=c(0.5, sum(y$V5==1)/nrow(y)))[1];", :float) @thr = thr.to_f @thr = nil if @thr==0.0 or @thr.infinite? end end |
#fps ⇒ Object
59 |
# File 'lib/rocker/rocwindow.rb', line 59 def fps() hits - tps end |
#length ⇒ Object
61 |
# File 'lib/rocker/rocwindow.rb', line 61 def length() to - from + 1 end |
#load_hits ⇒ Object
55 |
# File 'lib/rocker/rocwindow.rb', line 55 def load_hits() self.rrun "y <- x[x$V6>=#{from} & x$V6<=#{to},];" end |
#next ⇒ Object
57 |
# File 'lib/rocker/rocwindow.rb', line 57 def next() (to == data.aln.cols) ? nil : data.win_at_col(to + 1) end |
#previous ⇒ Object
56 |
# File 'lib/rocker/rocwindow.rb', line 56 def previous() (from == 1) ? nil : data.win_at_col(from - 1) end |
#rrun(cmd, type = nil) ⇒ Object
62 |
# File 'lib/rocker/rocwindow.rb', line 62 def rrun(cmd, type=nil) data.rrun(cmd, type) end |
#thr_notnil ⇒ Object
58 |
# File 'lib/rocker/rocwindow.rb', line 58 def thr_notnil() (@thr.nil? or @thr.infinite?) ? around_thr : @thr end |
#to_s ⇒ Object
63 |
# File 'lib/rocker/rocwindow.rb', line 63 def to_s() [from, to, hits, tps, thr_notnil].join("\t") + "\n" end |