class VCF::Variant
Constants
- CASTING
Attributes
alt[R]
chrom[R]
filter[R]
id[R]
info[R]
pos[R]
qual[R]
ref[R]
sample_data[R]
str[R]
Public Class Methods
new(str)
click to toggle source
# File lib/exodb/vcf.rb, line 80 def initialize(str) @str = str end
Public Instance Methods
parse!(info_attr, format_attr)
click to toggle source
# File lib/exodb/vcf.rb, line 84 def parse!(info_attr, format_attr) if @str splited = str.split(/\s+/) @chrom = splited[0] @pos = splited[1].to_i @id = splited[2] @ref = splited[3] @alt = splited[4] @qual = splited[5] @filter = splited[6] @info = {} parse_info(splited[7], info_attr) @formats = splited[8].split(/:/) @sample_data = [] splited[9..-1].each {|data| @sample_data.push(parse_format(data, @formats, format_attr))} @str = nil end end
Private Instance Methods
parse_format(str, formats, format_attr)
click to toggle source
# File lib/exodb/vcf.rb, line 123 def parse_format(str, formats, format_attr) result = {} splited = str.split(/:/) formats.each_index do |ind| case format_attr[formats[ind]][:Number] when '1' result[formats[ind]] = CASTING.call(splited[ind], format_attr[formats[0]][:Type]) when '0' result[formats[ind]] = true else result[formats[ind]] = [] formats[ind].split(/,/).each {|e| result[formats[ind]].push(CASTING.call(e, format_attr[formats[ind]][:Type]))} end end return result end
parse_info(str, info_attr)
click to toggle source
# File lib/exodb/vcf.rb, line 108 def parse_info(str, info_attr) str.split(/;/).each do |entry| splited = entry.split(/=/) case info_attr[splited[0]][:Number] when '1' @info[splited[0]] = CASTING.call(splited[1], info_attr[splited[0]][:Type]) when '0' @info[splited[0]] = true else @info[splited[0]] = [] splited[1].split(/,/).each {|e| @info[splited[0]].push(CASTING.call(e, info_attr[splited[0]][:Type]))} end end end