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 self.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
58 |
# File 'lib/rocker/rocwindow.rb', line 58 def almost_empty() self.fps < 3 or self.tps < 3 end |
#around_thr ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rocker/rocwindow.rb', line 39 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*(self.from-a.from) - a.thr*(self.from-b.from))/(b.from-a.from) end |
#compute! ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rocker/rocwindow.rb', line 28 def compute! self.load_hits @hits = self.rrun "nrow(y);", :int @tps = self.rrun "sum(y$V5);", :int unless self.almost_empty self.rrun "rocobj <- roc(y$V5, y$V4);" thr = self.rrun 'coords(rocobj, "best", ret="threshold", best.method="youden", best.weights=c(0.5, sum(y$V5)/nrow(y)))[1];', :float @thr = thr.to_f @thr = nil if @thr==0.0 or @thr.infinite? end end |
#fps ⇒ Object
57 |
# File 'lib/rocker/rocwindow.rb', line 57 def fps() self.hits - self.tps end |
#length ⇒ Object
59 |
# File 'lib/rocker/rocwindow.rb', line 59 def length() self.to - self.from + 1 end |
#load_hits ⇒ Object
53 |
# File 'lib/rocker/rocwindow.rb', line 53 def load_hits() self.rrun "y <- x[x$V6>=#{self.from} & x$V6<=#{self.to},];" end |
#next ⇒ Object
55 |
# File 'lib/rocker/rocwindow.rb', line 55 def next() (self.to == self.data.aln.cols) ? nil : self.data.win_at_col(self.to + 1) end |
#previous ⇒ Object
54 |
# File 'lib/rocker/rocwindow.rb', line 54 def previous() (self.from == 1) ? nil : self.data.win_at_col(self.from - 1) end |
#rrun(cmd, type = nil) ⇒ Object
60 |
# File 'lib/rocker/rocwindow.rb', line 60 def rrun(cmd, type=nil) self.data.rrun cmd, type end |
#thr_notnil ⇒ Object
56 |
# File 'lib/rocker/rocwindow.rb', line 56 def thr_notnil() (@thr.nil? or @thr.infinite?) ? self.around_thr : @thr end |
#to_s ⇒ Object
61 |
# File 'lib/rocker/rocwindow.rb', line 61 def to_s() [self.from, self.to, self.hits, self.tps, self.thr_notnil].join("\t") + "\n" end |