Class: BioVcf::VcfRecord
Instance Attribute Summary collapse
Instance Method Summary
collapse
#call_diff, #call_normal_count, #call_nuc, #call_tumor_count, #call_tumor_relative_count, #get_gt, #index
Constructor Details
#initialize(fields, header) ⇒ VcfRecord
Returns a new instance of VcfRecord.
129
130
131
132
133
|
# File 'lib/bio-vcf/vcfrecord.rb', line 129
def initialize fields,
@fields = fields
@header =
@sample_by_index = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
314
315
316
317
318
319
320
321
322
323
|
# File 'lib/bio-vcf/vcfrecord.rb', line 314
def method_missing(m, *args, &block)
name = m.to_s
if name =~ /\?$/
@sample_index ||= @header.sample_index
return !VcfSample::empty?(@fields[@sample_index[name.chop]])
else
sample[name]
end
end
|
Instance Attribute Details
Returns the value of attribute header.
127
128
129
|
# File 'lib/bio-vcf/vcfrecord.rb', line 127
def
@header
end
|
Instance Method Details
#add_to_filter_field(str) ⇒ Object
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
# File 'lib/bio-vcf/vcfrecord.rb', line 298
def add_to_filter_field str
filter = @fields[6]
if not filter or filter == '.' or filter == 'PASS'
filter = str
else
values = filter.split(/;/)
if not values.include?(str)
filter = filter +';'+str
end
end
filter = '.' if filter == nil or filter == ''
@fields[6] = filter
filter
end
|
#alt ⇒ Object
157
158
159
|
# File 'lib/bio-vcf/vcfrecord.rb', line 157
def alt
@alt ||= @fields[4].split(/,/)
end
|
#chrom ⇒ Object
Also known as:
chr
135
136
137
|
# File 'lib/bio-vcf/vcfrecord.rb', line 135
def chrom
@fields[0]
end
|
#each_sample(list = nil) ⇒ Object
Walk the samples. list contains an Array of int (the index)
207
208
209
210
211
|
# File 'lib/bio-vcf/vcfrecord.rb', line 207
def each_sample(list = nil)
@header.sample_subset_index(list).each { |i|
yield VcfSample::Sample.new(self,sample_by_index(i))
}
end
|
#eval(expr, ignore_missing_data: true, quiet: false) ⇒ Object
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
# File 'lib/bio-vcf/vcfrecord.rb', line 230
def eval expr, ignore_missing_data: true, quiet: false
begin
if not respond_to?(:call_cached_eval)
code =
"""
def call_cached_eval(rec,fields)
r = rec
#{expr}
end
"""
self.class.class_eval(code)
end
res = call_cached_eval(self,@fields)
if res.kind_of?(Array)
res.join("\t")
else
res
end
rescue NoMethodError => e
if not quiet
$stderr.print "RECORD ERROR!\n"
$stderr.print [@fields],"\n"
$stderr.print expr,"\n"
$stderr.print "To ignore this error use the -i switch!\n"
end
if ignore_missing_data
$stderr.print e.message if not quiet
return false
else
raise
end
end
end
|
#filter ⇒ Object
165
166
167
|
# File 'lib/bio-vcf/vcfrecord.rb', line 165
def filter
@filter ||= @fields[6]
end
|
#first ⇒ Object
Return the first (single) sample (used in one sample VCF)
178
179
180
|
# File 'lib/bio-vcf/vcfrecord.rb', line 178
def first
@first ||= VcfGenotypeField.new(@fields[9],format,@header,ref,alt)
end
|
#gfilter(expr, ignore_missing_data: true, quiet: false) ⇒ Object
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
# File 'lib/bio-vcf/vcfrecord.rb', line 264
def gfilter expr, ignore_missing_data: true, quiet: false
begin
if not respond_to?(:call_cached_filter)
code =
"""
def call_cached_gfilter(rec,fields)
r = rec
#{expr}
end
"""
self.class.class_eval(code)
end
res = call_cached_gfilter(self,@fields)
if res.kind_of?(Array)
res.join("\t")
else
res
end
rescue NoMethodError => e
if not quiet
$stderr.print "RECORD ERROR!\n"
$stderr.print [@fields],"\n"
$stderr.print expr,"\n"
$stderr.print "To ignore this error use the -i switch!\n"
end
if ignore_missing_data
$stderr.print e.message if not quiet
return false
else
raise
end
end
end
|
#id ⇒ Object
149
150
151
|
# File 'lib/bio-vcf/vcfrecord.rb', line 149
def id
ids[0]
end
|
#ids ⇒ Object
145
146
147
|
# File 'lib/bio-vcf/vcfrecord.rb', line 145
def ids
@ids ||= @fields[2].split(';')
end
|
#info ⇒ Object
169
170
171
|
# File 'lib/bio-vcf/vcfrecord.rb', line 169
def info
@info ||= VcfRecordParser.get_info(@fields[7])
end
|
#missing_samples? ⇒ Boolean
219
220
221
222
223
224
|
# File 'lib/bio-vcf/vcfrecord.rb', line 219
def missing_samples?
@fields[9..-1].each { |sample|
return true if VcfSample::empty?(sample)
}
false
end
|
#normal ⇒ Object
Return the normal sample (used in two sample VCF)
183
184
185
|
# File 'lib/bio-vcf/vcfrecord.rb', line 183
def normal
first
end
|
#pos ⇒ Object
141
142
143
|
# File 'lib/bio-vcf/vcfrecord.rb', line 141
def pos
@pos ||= @fields[1].to_i
end
|
#qual ⇒ Object
161
162
163
|
# File 'lib/bio-vcf/vcfrecord.rb', line 161
def qual
@qual ||= @fields[5].to_f
end
|
#ref ⇒ Object
153
154
155
|
# File 'lib/bio-vcf/vcfrecord.rb', line 153
def ref
@refs ||= @fields[3]
end
|
#sample ⇒ Object
Return the sample as a named hash
193
194
195
|
# File 'lib/bio-vcf/vcfrecord.rb', line 193
def sample
@sample ||= VcfGenotypeFields.new(@fields,format,@header,ref,alt)
end
|
#sample_by_index(i) ⇒ Object
201
202
203
204
|
# File 'lib/bio-vcf/vcfrecord.rb', line 201
def sample_by_index i
raise "Can not index sample on parameter <#{i}>" if not i.kind_of?(Integer)
@sample_by_index[i] ||= VcfGenotypeField.new(@fields[i+9],format,@header,ref,alt)
end
|
#sample_by_name(name) ⇒ Object
197
198
199
|
# File 'lib/bio-vcf/vcfrecord.rb', line 197
def sample_by_name name
sample[name]
end
|
#samples ⇒ Object
213
214
215
216
217
|
# File 'lib/bio-vcf/vcfrecord.rb', line 213
def samples
list = []
each_sample { |s| list << s }
list
end
|
#tumor ⇒ Object
Return the tumor sample (used in two sample VCF)
188
189
190
|
# File 'lib/bio-vcf/vcfrecord.rb', line 188
def tumor
@tumor ||= VcfGenotypeField.new(@fields[10],format,@header,ref,alt)
end
|
#valid? ⇒ Boolean
226
227
228
|
# File 'lib/bio-vcf/vcfrecord.rb', line 226
def valid?
@fields.size == @header.column_names.size
end
|