Class: Cytogenetics::Aberration
- Inherits:
-
Object
- Object
- Cytogenetics::Aberration
show all
- Defined in:
- lib/cytogenetics/aberration.rb
Direct Known Subclasses
ChromosomeAberrations::Addition, ChromosomeAberrations::ChromosomeFragment, ChromosomeAberrations::ChromosomeGain, ChromosomeAberrations::ChromosomeLoss, ChromosomeAberrations::Deletion, ChromosomeAberrations::Derivative, ChromosomeAberrations::DicentricChromosome, ChromosomeAberrations::Duplication, ChromosomeAberrations::Insertion, ChromosomeAberrations::Inversion, ChromosomeAberrations::Isochromosome, ChromosomeAberrations::Translocation
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Aberration.
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/cytogenetics/aberration.rb', line 55
def initialize(str)
config_logging()
@abr = str
@breakpoints = []; @fragments = []
get_breakpoints() @breakpoints.flatten!
end
|
Instance Attribute Details
#ab_objs ⇒ Object
Returns the value of attribute ab_objs.
7
8
9
|
# File 'lib/cytogenetics/aberration.rb', line 7
def ab_objs
@ab_objs
end
|
#abr ⇒ Object
Returns the value of attribute abr.
7
8
9
|
# File 'lib/cytogenetics/aberration.rb', line 7
def abr
@abr
end
|
#breakpoints ⇒ Object
Returns the value of attribute breakpoints.
6
7
8
|
# File 'lib/cytogenetics/aberration.rb', line 6
def breakpoints
@breakpoints
end
|
#fragments ⇒ Object
Returns the value of attribute fragments.
7
8
9
|
# File 'lib/cytogenetics/aberration.rb', line 7
def fragments
@fragments
end
|
Class Method Details
.aberration_objs ⇒ Object
38
39
40
|
# File 'lib/cytogenetics/aberration.rb', line 38
def self.aberration_objs
@ab_objs ||= self.instantiate_aberrations
end
|
.aberration_type ⇒ Object
42
43
44
45
46
|
# File 'lib/cytogenetics/aberration.rb', line 42
def self.aberration_type
abr_breaks = Aberration.all_regex.keys
abr_breaks.delete_if { |c| c.to_s.match(/gain|loss/) }
return abr_breaks
end
|
.all_regex ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/cytogenetics/aberration.rb', line 28
def self.all_regex
rx = {}
ChromosomeAberrations.constants.each do |ca|
ca_obj = ChromosomeAberrations.const_get(ca)
rx[ca_obj.type.to_sym] = ca_obj.regex
end
return rx
end
|
.classify_aberration(abr) ⇒ Object
48
49
50
51
52
53
|
# File 'lib/cytogenetics/aberration.rb', line 48
def self.classify_aberration(abr)
Aberration.all_regex.each_pair do |k, regex|
return k if abr.match(regex)
end
return "unk".to_sym
end
|
.instantiate_aberrations ⇒ Object
10
11
12
13
14
15
16
17
|
# File 'lib/cytogenetics/aberration.rb', line 10
def instantiate_aberrations
aberration_obj = {}
ChromosomeAberrations.constants.each do |ca|
abr_obj = ChromosomeAberrations.const_get(ca)
aberration_obj[abr_obj.type.to_sym] = abr_obj
end
return aberration_obj
end
|
.regex ⇒ Object
24
25
26
|
# File 'lib/cytogenetics/aberration.rb', line 24
def self.regex
return @rx
end
|
.type ⇒ Object
20
21
22
|
# File 'lib/cytogenetics/aberration.rb', line 20
def self.type
return @kt
end
|
Instance Method Details
#config_logging ⇒ Object
150
151
152
153
|
# File 'lib/cytogenetics/aberration.rb', line 150
def config_logging
@log = Cytogenetics.logger
end
|
#find_bands(str, index) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/cytogenetics/aberration.rb', line 112
def find_bands(str, index)
band_info = nil
if str.length.eql?(index+1)
@log.warn("No bands defined in #{str}, skipped.")
return
end
ei = str.index(/\(/, index)
if str.match(/(q|p)(\d+|\?)/) and str[ei-1..ei].eql?(")(") band_s = str.index(/\(/, index)
band_e = str.index(/\)/, band_s)
band_e = str.length-1 if band_e.nil?
bands = str[band_s+1..band_e-1].split(/;|:/)
if str[band_s+1..band_e-1].match(/::/)
@log.warn("Aberration defined using different language, not currently parsed skipping: #{@abr}")
return band_info
else
bands.map! { |b| b.sub(/-[q|p]\d+$/, "") } bands.each do |b|
unless b.match(/^[p|q]\d+(\.\d)?$/)
@log.warn("Bands incorrectly defined in #{str}")
return band_info
end
end
band_info = {:start_index => band_s, :end_index => band_e, :bands => bands}
end
end
return band_info
end
|
#find_chr(str) ⇒ Object
Parsing aberration strings to pull out the chromosome and band definitions These will result in breakpoint information
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/cytogenetics/aberration.rb', line 99
def find_chr(str)
chr_s = str.index(/\(/, 0)
chr_e = str.index(/\)/, chr_s)
chrs = str[chr_s+1..chr_e-1].split(/;|:/)
chrs.each do |chr|
unless chr.match(/^\d+|X|Y$/)
@log.warn("No chromosome defined from #{str}, skipped.")
return
end
end
return {:start_index => chr_s, :end_index => chr_e, :chr => chrs}
end
|
#find_fragments(str) ⇒ Object
sometimes bands are defined for a single chr as p13q22
145
146
147
|
# File 'lib/cytogenetics/aberration.rb', line 145
def find_fragments(str)
return str.scan(/([p|q]\d+)/).collect { |a| a[0] }
end
|
#get_breakpoints ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/cytogenetics/aberration.rb', line 80
def get_breakpoints
chr_i = find_chr(@abr)
return if chr_i.nil?
band_i = find_bands(@abr, chr_i[:end_index])
unless band_i.nil? chr_i[:chr].each_with_index do |c, i|
fragments = find_fragments(band_i[:bands][i])
fragments.each { |f| @breakpoints << Breakpoint.new(c, f, self.class.type) }
end
else
end
end
|
#remove_breakpoint(bp) ⇒ Object
68
69
70
71
72
|
# File 'lib/cytogenetics/aberration.rb', line 68
def remove_breakpoint(bp)
removed = @breakpoints.index(bp)
@breakpoints.delete_at(removed) if removed
return removed
end
|
#to_s ⇒ Object
74
75
76
|
# File 'lib/cytogenetics/aberration.rb', line 74
def to_s
"#{@abr}: #{@breakpoints.join(',')}"
end
|