Class: MutationSet::Line
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#above?, #below?, #center, #clone, #contains?, #dist, #intersect, #intersection_size, #nearest, #overlap, #overlaps?, #size, #strict_diff, #strict_overlap, #strict_union
Constructor Details
#initialize(fields, sample) ⇒ Line
Returns a new instance of Line.
33
34
35
36
37
38
39
40
|
# File 'lib/mutation_set.rb', line 33
def initialize(fields, sample)
if fields.is_a? Hash
@mutation = fields
else
@mutation = Hash[sample..zip(fields)]
end
@sample = sample
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
157
158
159
160
161
162
163
|
# File 'lib/mutation_set.rb', line 157
def method_missing(meth,*args,&block)
if meth.to_s =~ /(.*)=/
@mutation[$1.to_sym] = args.first
else
@mutation.has_key?(meth.to_sym) ? @mutation[meth.to_sym] : super
end
end
|
Instance Attribute Details
#invalid ⇒ Object
Returns the value of attribute invalid.
9
10
11
|
# File 'lib/mutation_set.rb', line 9
def invalid
@invalid
end
|
#sample ⇒ Object
Returns the value of attribute sample.
8
9
10
|
# File 'lib/mutation_set.rb', line 8
def sample
@sample
end
|
Class Method Details
.alias_key(sym1, sym2) ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'lib/mutation_set.rb', line 11
def self.alias_key sym1, sym2
define_method sym1 do
send sym2
end
define_method "#{sym1}=" do |v|
send "#{sym2}=", v
end
end
|
Instance Method Details
#copy ⇒ Object
20
21
22
|
# File 'lib/mutation_set.rb', line 20
def copy
self.class.new @mutation.clone, sample
end
|
#criteria_failed?(obj, name) ⇒ Boolean
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/mutation_set.rb', line 63
def criteria_failed? obj, name
return nil if !sample.mutation_config
name = [ name ] if !name.is_a? Array
crit = name.reduce(sample.mutation_config) do |h,n|
h.is_a?(Hash) ? h[n] : nil
end
return nil if !crit
crit.each do |attrib,value|
return true if !criterion_ok? obj, attrib, value
end
nil
end
|
#criterion_ok?(obj, attrib, value) ⇒ Boolean
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/mutation_set.rb', line 76
def criterion_ok? obj, attrib, value
case attrib
when /^min_(.*)/
v = obj.send($1.to_sym).to_f
return v >= value.to_f
when /^max_(.*)/
return obj.send($1.to_sym).to_f <= value.to_f
when /^exclude_(.*)/
v = obj.send($1.to_sym)
if value.is_a? Array
return value.none? { |r| v.match(/#{r}/) }
else
return v !~ /#{value}/
end
when /^has_(.*)/
v = obj.send($1.to_sym)
if value.is_a? Array
return value.include? v
elsif value == true
return v && (v.is_a?(String) ? v.size > 0 : v)
elsif value == false || value == "nil"
return !v
else
return value == v
end
when /^include_(.*)/
v = obj.send($1.to_sym)
if value.is_a? Array
return value.any? { |r| v.match(/#{r}/) }
else
return v =~ /#{value}/
end
when /^either.*/
v = nil
value.each do |attrib,val|
v = true if criterion_ok? obj, attrib, val
end
return v
when /^whitelisted/
whitelist = sample.whitelist value
return whitelist.intersect(self)
when /^blacklisted/
blacklist = sample.blacklist value
return !blacklist.intersect(self)
else
case value
when "nil", false, nil
return !obj.send(attrib.to_sym)
when true
return obj.send(attrib.to_sym)
end
end
true
end
|
#discard_onco ⇒ Object
137
138
139
|
# File 'lib/mutation_set.rb', line 137
def discard_onco
@onco = nil
end
|
#in_cosmic ⇒ Object
149
150
151
|
# File 'lib/mutation_set.rb', line 149
def in_cosmic
onco.Cosmic_overlapping_mutations ? "YES" : "NO"
end
|
#inspect ⇒ Object
145
146
147
|
# File 'lib/mutation_set.rb', line 145
def inspect
"#<#{self.class.name}:#{object_id} @mutation=#{@mutation}>"
end
|
#invalid? ⇒ Boolean
24
25
26
|
# File 'lib/mutation_set.rb', line 24
def invalid?
invalid
end
|
#invalidate! ⇒ Object
28
29
30
|
# File 'lib/mutation_set.rb', line 28
def invalidate!
@invalid = true
end
|
#key ⇒ Object
42
43
44
|
# File 'lib/mutation_set.rb', line 42
def key
"#{chrom}:#{start}:#{stop}"
end
|
#long_chrom ⇒ Object
46
47
48
|
# File 'lib/mutation_set.rb', line 46
def long_chrom
@long_chrom ||= "chr#{short_chrom}"
end
|
#onco ⇒ Object
132
133
134
135
|
# File 'lib/mutation_set.rb', line 132
def onco
raise ArgumentError, @onco_error unless valid_onco_input?
@onco ||= Oncotator.new :key => self.to_ot
end
|
#respond_to?(method) ⇒ Boolean
165
166
167
|
# File 'lib/mutation_set.rb', line 165
def respond_to? method
!@mutation[method.to_sym].nil? || super
end
|
#short_chrom ⇒ Object
50
51
52
|
# File 'lib/mutation_set.rb', line 50
def short_chrom
@short_chrom ||= chrom.sub(/^chr/,'')
end
|
#skip_oncotator?(criteria = nil) ⇒ Boolean
141
142
143
|
# File 'lib/mutation_set.rb', line 141
def skip_oncotator? criteria=nil
return true if !onco || onco.empty? || criteria_failed?(onco, criteria || :oncotator)
end
|
#to_hash ⇒ Object
58
59
60
61
|
# File 'lib/mutation_set.rb', line 58
def to_hash
@mutation
end
|
#to_ot ⇒ Object
153
154
155
|
# File 'lib/mutation_set.rb', line 153
def to_ot
[ short_chrom, start, stop, ref_allele, alt_allele ].join("_")
end
|
#to_s ⇒ Object
54
55
56
|
# File 'lib/mutation_set.rb', line 54
def to_s
sample..map{ |h| @mutation[h] }.join("\t")
end
|