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
	 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



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

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

#around_thrObject



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

#fpsObject



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

def fps() hits - tps end

#lengthObject



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

def length() to - from + 1 end

#load_hitsObject



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

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

#nextObject



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

def next() (to == data.aln.cols) ? nil : data.win_at_col(to + 1) end

#previousObject



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_notnilObject



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

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

#to_sObject



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

def to_s() [from, to, hits, tps, thr_notnil].join("\t") + "\n" end