Class: ROCWindow

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

Overview

Author:

  • Luis M. Rodriguez-R <lmrodriguezr at gmail dot com>

  • Luis (Coto) Orellana

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



9
10
11
# File 'lib/rocker/rocwindow.rb', line 9

def data
  @data
end

#fromObject (readonly)

Returns the value of attribute from.



9
10
11
# File 'lib/rocker/rocwindow.rb', line 9

def from
  @from
end

#hitsObject (readonly)

Returns the value of attribute hits.



9
10
11
# File 'lib/rocker/rocwindow.rb', line 9

def hits
  @hits
end

#thrObject (readonly)

Returns the value of attribute thr.



9
10
11
# File 'lib/rocker/rocwindow.rb', line 9

def thr
  @thr
end

#toObject (readonly)

Returns the value of attribute to.



9
10
11
# File 'lib/rocker/rocwindow.rb', line 9

def to
  @to
end

#tpsObject (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_emptyObject



58
# File 'lib/rocker/rocwindow.rb', line 58

def almost_empty() self.fps < 3 or self.tps < 3 end

#around_thrObject



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

#fpsObject



57
# File 'lib/rocker/rocwindow.rb', line 57

def fps() self.hits - self.tps end

#lengthObject



59
# File 'lib/rocker/rocwindow.rb', line 59

def length() self.to - self.from + 1 end

#load_hitsObject



53
# File 'lib/rocker/rocwindow.rb', line 53

def load_hits() self.rrun "y <- x[x$V6>=#{self.from} & x$V6<=#{self.to},];" end

#nextObject



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

#previousObject



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_notnilObject



56
# File 'lib/rocker/rocwindow.rb', line 56

def thr_notnil() (@thr.nil? or @thr.infinite?) ? self.around_thr : @thr end

#to_sObject



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