-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNode.rb
66 lines (54 loc) · 1.32 KB
/
Node.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
require 'fileTools'
require 'extArray'
class Node
# contains the name of the node
# the binary array representing samples
# and links to the connected nodes (ORs)
attr_accessor :name, :samples, :conns
def initialize(samples,name)
@samples = samples
@name = name
@conns = []
@ands = []
end
def eql?(node2)
unless node2.is_a?(Node)
raise "both objects need to be the same type (Node) in order to test for equality"
end
if self.samples == node2.samples &&
self.name == node2.name &&
self.conns == node2.conns
return true
end
return false
end
# return the names of the top N OR-connected nodes
def topConns(num)
return conns[0..(num-1)].collect{|genescore| genescore.name}
end
# return the name of a random OR-connected node
def randConn
return conns[rand(conns.length)].name
end
# return an array containing the names of all OR-connected
# nodes, randomly ordered
def randConns()
return conns.shuffle
end
#is the or list non-empty?
def hasConns?
if conns.length > 0
return true
end
return false
end
end
#-----------------------------------
# stores a name/score combo
class GeneScore
attr_accessor :name, :score
def initialize(name,score)
@name = name
@score = score
end
end