class BioVcf::VCFfile
This class abstracts a VCF file that can be iterated. The VCF can be plain text or compressed with gzip Note that files compressed with bgzip will not work, as thie ruby implementation of Zlib don't allow concatenated files
Public Class Methods
new(file: "", is_gz: true)
click to toggle source
# File lib/bio-vcf/vcffile.rb, line 7 def initialize(file: "", is_gz: true) @file = file @is_gz = is_gz end
Public Instance Methods
each() { |rec| ... }
click to toggle source
Returns an enum that can be used as an iterator.
# File lib/bio-vcf/vcffile.rb, line 19 def each return enum_for(:each) unless block_given? io = nil if @is_gz infile = open(@file) io = Zlib::GzipReader.new(infile) else io = File.open(@file) end header = BioVcf::VcfHeader.new io.each_line do |line| line.chomp! if line =~ /^##fileformat=/ header.add(line) next end if line =~ /^#/ header.add(line) next end fields = BioVcf::VcfLine.parse(line) rec = BioVcf::VcfRecord.new(fields,header) yield rec end end
parseVCFheader(head_line="")
click to toggle source
# File lib/bio-vcf/vcffile.rb, line 12 def parseVCFheader(head_line="") m=/##INFO=<ID=(.+),Number=(.+),Type=(.+),Description="(.+)">/.match(head_line) {:id=>m[1],:number=>m[2],:type=>m[3],:desc=>m[4]} end