class BioVcf::VcfRecord
Attributes
header[R]
Public Class Methods
new(fields, header)
click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 129 def initialize fields, header @fields = fields @header = header @sample_by_index = [] end
Public Instance Methods
add_to_filter_field(str)
click to toggle source
# 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()
click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 157 def alt @alt ||= @fields[4].split(/,/) end
chrom()
click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 135 def chrom @fields[0] end
Also aliased as: chr
each_sample(list = nil) { |sample(self,sample_by_index(i))| ... }
click to toggle source
Walk the samples. list contains an Array of int (the index)
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 165 def filter @filter ||= @fields[6] end
first()
click to toggle source
Return the first (single) sample (used in one sample VCF)
# File lib/bio-vcf/vcfrecord.rb, line 178 def first @first ||= VcfGenotypeField.new(@fields[9],format,@header,ref,alt) end
format()
click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 173 def format @format ||= VcfRecordParser.get_format(@fields[8]) end
gfilter(expr, ignore_missing_data: true, quiet: false)
click to toggle source
# 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()
click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 149 def id ids[0] end
ids()
click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 145 def ids @ids ||= @fields[2].split(';') end
info()
click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 169 def info @info ||= VcfRecordParser.get_info(@fields[7]) end
method_missing(m, *args, &block)
click to toggle source
Return the sample
# File lib/bio-vcf/vcfrecord.rb, line 314 def method_missing(m, *args, &block) name = m.to_s if name =~ /\?$/ # Query for empty sample name @sample_index ||= @header.sample_index return !VcfSample::empty?(@fields[@sample_index[name.chop]]) else sample[name] end end
missing_samples?()
click to toggle source
# 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()
click to toggle source
Return the normal sample (used in two sample VCF)
# File lib/bio-vcf/vcfrecord.rb, line 183 def normal first end
pos()
click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 141 def pos @pos ||= @fields[1].to_i end
qual()
click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 161 def qual @qual ||= @fields[5].to_f end
ref()
click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 153 def ref @refs ||= @fields[3] end
sample()
click to toggle source
Return the sample as a named hash
# File lib/bio-vcf/vcfrecord.rb, line 193 def sample @sample ||= VcfGenotypeFields.new(@fields,format,@header,ref,alt) end
sample_by_index(i)
click to toggle source
# 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)
click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 197 def sample_by_name name sample[name] end
samples()
click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 213 def samples list = [] each_sample { |s| list << s } list end
tumor()
click to toggle source
Return the tumor sample (used in two sample VCF)
# File lib/bio-vcf/vcfrecord.rb, line 188 def tumor @tumor ||= VcfGenotypeField.new(@fields[10],format,@header,ref,alt) end
valid?()
click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 226 def valid? @fields.size == @header.column_names.size end