class RDF::VCF::Reader
VCF
file reader.
This is a user-friendly wrapper for the HTSJDK implementation.
@see github.com/samtools/htsjdk @see samtools.github.io/htsjdk/javadoc/htsjdk/htsjdk/variant/vcf/VCFFileReader.html
Constants
- REF_BASE_URI
Public Class Methods
new(pathname)
click to toggle source
@param [#to_s] pathname
# File lib/rdf/vcf/reader.rb, line 37 def initialize(pathname) pathname = pathname.to_s @vcf_file = java.io.File.new(pathname) @tbi_file = java.io.File.new("#{pathname}.tbi") rescue nil @reader = VCFFileReader.new(@vcf_file, @tbi_file, false) end
open(pathname, &block)
click to toggle source
@param [#to_s] pathname
# File lib/rdf/vcf/reader.rb, line 28 def self.open(pathname, &block) reader = self.new(pathname) block.call(reader) ensure #reader.close end
Public Instance Methods
close()
click to toggle source
@return [void]
# File lib/rdf/vcf/reader.rb, line 52 def close @reader.close if @reader ensure @reader, @vcf_file, @tbi_file = nil, nil, nil end
closed?()
click to toggle source
@return [Boolean]
# File lib/rdf/vcf/reader.rb, line 46 def closed? @reader.nil? end
each_record(&block)
click to toggle source
@yield [record] @yieldparam [Record] record @yieldreturn [void] @return [void]
# File lib/rdf/vcf/reader.rb, line 74 def each_record(&block) return unless @reader @reader.iterator.each do |variant_context| # VariantContext record = Record.new(variant_context, self) block.call(record) end end
each_statement(&block)
click to toggle source
@yield [statement] @yieldparam [RDF::Statement] statement @yieldreturn [void] @return [void]
# File lib/rdf/vcf/reader.rb, line 63 def each_statement(&block) self.each_record do |record| record.to_rdf.each(&block) end end
file_date()
click to toggle source
@return [String]
# File lib/rdf/vcf/reader.rb, line 120 def file_date @file_date ||= @reader.getFileHeader().getMetaDataLine("fileDate").getKey rescue nil end
find_records(chromosome: nil, start_pos: nil, end_pos: nil, &block)
click to toggle source
@param [String] chromosome @param [Integer] start_pos @param [Integer] end_pos @yield [record] @yieldparam [Record] record @yieldreturn [void] @return [void]
# File lib/rdf/vcf/reader.rb, line 90 def find_records(chromosome: nil, start_pos: nil, end_pos: nil, &block) return unless @reader start_pos ||= 0 end_pos ||= java.lang.Integer::MAX_VALUE @reader.query(chromosome, start_pos, end_pos).each do |variant_context| # VariantContext record = Record.new(variant_context, self) block.call(record) end end
has_position?(pos)
click to toggle source
@param [Integer] pos @return [Boolean]
# File lib/rdf/vcf/reader.rb, line 103 def has_position?(pos) true # TODO end
ref_base_uri()
click to toggle source
# File lib/rdf/vcf/reader.rb, line 21 def ref_base_uri # @file_iri ||= RDF::URI(REF_BASE_URI % [reference_md5, file_date || "" , source || ""]) end
reference()
click to toggle source
@return [String]
# File lib/rdf/vcf/reader.rb, line 109 def reference() @reference ||= @reader.getFileHeader().getMetaDataLine("reference").getKey rescue nil end
reference_md5()
click to toggle source
# File lib/rdf/vcf/reader.rb, line 113 def reference_md5 ::Digest::MD5.hexdigest(reference|| "") end
source()
click to toggle source
@return [String]
# File lib/rdf/vcf/reader.rb, line 126 def source @source ||= @reader.getFileHeader().getMetaDataLine("source").getKey rescue nil end