class VCF

Attributes

alt_attr[R]
contig[R]
filter_attr[R]
format_attr[R]
info_attr[R]
meta[R]
samples[R]
variants[R]

Public Class Methods

new() click to toggle source
# File lib/exodb/vcf.rb, line 7
def initialize()
        @info_attr = {}
        @filter_attr = {}
        @format_attr = {}
        @alt_attr = {}
        @meta = {}
        @contig = {}
        @variants = []

end

Public Instance Methods

fileformat() click to toggle source
# File lib/exodb/vcf.rb, line 44
def fileformat
        return @meta[:fileformat]
end
open(filename) click to toggle source
# File lib/exodb/vcf.rb, line 18
def open(filename)
        
        File.open(filename).each do |line|
                case line
                when /^##INFO/
                        parse_info(line.chomp)
                when /^##FORMAT/
                        parse_format(line.chomp)
                when /^##FILTER/
                        parse_filter(line.chomp)
                when /^##contig/
                        parse_contig(line.chomp)
                when /^##ALT/
                        parse_alt(line.chomp)
                when /^##/
                        parse_meta(line.chomp)
                when /^#/
                        @samples = line.split(/\s+/)[9..-1]
                else
                        @variants.push(Variant.new(line.chomp))
                end
                
        end
        
end
parse(line = 4000) click to toggle source
# File lib/exodb/vcf.rb, line 48
def parse(line = 4000)
        @variants.each_index do |ind|
                break if ind > line
                Thread.new (ind) {
                        @variants[ind].parse!(@info_attr, @format_attr)
                }
        end
end
sample_num() click to toggle source
# File lib/exodb/vcf.rb, line 57
def sample_num
        return @samples.length
end
variant_num() click to toggle source
# File lib/exodb/vcf.rb, line 61
def variant_num
        return @variants.length
end

Private Instance Methods

parse_alt(str) click to toggle source
# File lib/exodb/vcf.rb, line 170
def parse_alt(str)
        data = parse_data(str[7..-1])
        @alt_attr[data[:ID]] = data
end
parse_contig(str) click to toggle source
# File lib/exodb/vcf.rb, line 151
def parse_contig(str)
        @contig = parse_data(str[10..-1])
end
parse_data(str) click to toggle source
# File lib/exodb/vcf.rb, line 175
def parse_data(str)
        result = {}
        str.scan(/(\w+=\w+|\w+=\".+\")/).each do |entry|
                splited = entry[0].split(/=/)
                result[splited[0].to_sym] = splited [1]
        end
        return result
end
parse_filter(str) click to toggle source
# File lib/exodb/vcf.rb, line 155
def parse_filter(str)
        data = parse_data(str[10..-1])
        @filter_attr[data[:ID]] = data
end
parse_format(str) click to toggle source
# File lib/exodb/vcf.rb, line 165
def parse_format(str)
        data = parse_data(str[10..-1])
        @format_attr[data[:ID]] = data
end
parse_info(str) click to toggle source
# File lib/exodb/vcf.rb, line 160
def parse_info(str)
        data = parse_data(str[8..-1])
        @info_attr[data[:ID]] = data
end
parse_meta(str) click to toggle source
# File lib/exodb/vcf.rb, line 146
def parse_meta(str)
        splited = str[2..-1].split(/=/)
        @meta[splited[0].to_sym] = splited[1]
end