-
Notifications
You must be signed in to change notification settings - Fork 2
/
NodeArray.rb
75 lines (61 loc) · 1.49 KB
/
NodeArray.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
# Class that extends Array to add functions useful
# when our array is full of nodes
require 'extArray'
require 'algSig'
require 'Matrix'
class NodeArray < Array
def setTotalGenes(num)
@numGenes = num
end
def setBgRate(num)
@bgRate = num
end
def names
return self.collect{|x| x.name}
end
# coverage is percentage of samples covered
def scoreCoverage
combined = Array.new(self[0].samples.length,0)
self.each{|node|
node.samples.each_index{|i|
if node.samples[i] == 1 || node.samples[i] == "1"
combined[i] = 1
end
}
}
return combined.sum.to_f/combined.length.to_f
end
# exclusivity is percentage XOR in covered area
def scoreExclusivity
covered = 0
xor = 0
self[0].samples.each_index{|i|
sum = 0
self.each{|node|
sum += node.samples[i].to_i
}
if sum == 1
xor += 1
covered += 1
elsif sum > 1
covered += 1
end
}
return xor.to_f/covered.to_f
end
#calculate algorithmic significance for each module
def eScore
#convert binary arrays for each gene to a matrix
twodArray = []
self.each{|node|
twodArray << Array.new(node.samples)
}
rowHead = Array.new(twodArray.length,"row")
colHead = Array.new(twodArray[0].length,"col")
matrix = Matrix.new(twodArray, colHead, rowHead)
return calcSignificance(matrix,@numGenes,@bgRate)
end
def score
return self.eScore
end
end