class Bio::FlatFileIndex::Indexer::Parser::TemplateParser

Constants

NAMESTYLE

Attributes

dbclass[RW]
errorlog[R]
fileid[R]
format[RW]
primary[R]
secondary[R]

Public Class Methods

new() click to toggle source
# File lib/bio/io/flatfile/indexer.rb, line 79
def initialize
  @namestyle = self.class::NAMESTYLE
  @secondary = NameSpaces.new
  @errorlog = []
end

Public Instance Methods

add_secondary_namespaces(*names) click to toggle source
# File lib/bio/io/flatfile/indexer.rb, line 98
def add_secondary_namespaces(*names)
  DEBUG.print "add_secondary_namespaces: #{names.inspect}\n"
  names.each do |x|
    unless x.is_a?(NameSpace) then
      y = @namestyle[x]
      raise 'unknown secondary namespace' unless y
      @secondary << y
    end
  end
  true
end
close_flatfile() click to toggle source
# File lib/bio/io/flatfile/indexer.rb, line 164
def close_flatfile
  DEBUG.print "close flatfile #{@flatfilename.inspect}\n"
  @flatfile.close
end
each() { |pos, len| ... } click to toggle source
# File lib/bio/io/flatfile/indexer.rb, line 122
def each
  @flatfile.each do |x|
    @entry = x
    pos = @flatfile.entry_start_pos
    len = @flatfile.entry_ended_pos - @flatfile.entry_start_pos
    begin
      yield pos, len
    rescue RuntimeError, NameError => evar
      DEBUG.print "Caught error: #{evar.inspect}\n"
      DEBUG.print "in #{@flatfilename.inspect} position #{pos}\n"
      DEBUG.print "===begin===\n"
      DEBUG.print @flatfile.entry_raw.to_s.chomp
      DEBUG.print "\n===end===\n"
      @errorlog << [ evar, @flatfilename, pos ]
      if @fatal then
        DEBUG.print "Fatal error occurred, stop creating index...\n"
        raise evar
      else
        DEBUG.print "This entry shall be incorrectly indexed.\n"
      end
    end #rescue
  end
end
open_flatfile(fileid, file) click to toggle source

administration of a single flatfile

# File lib/bio/io/flatfile/indexer.rb, line 111
def open_flatfile(fileid, file)
  @fileid = fileid
  @flatfilename = file
  DEBUG.print "fileid=#{fileid} file=#{@flatfilename.inspect}\n"
  @flatfile = Bio::FlatFile.open(@dbclass, file, 'rb')
  @flatfile.raw = nil
  @flatfile.entry_pos_flag = true
  @entry = nil
end
parse_primary() click to toggle source
# File lib/bio/io/flatfile/indexer.rb, line 146
def parse_primary
  r = self.primary.proc.call(@entry)
  unless r.is_a?(String) and r.length > 0
    #@fatal = true
    raise 'primary id must be a non-void string (skipped this entry)'
  end
  r
end
parse_secondary() { |name, y| ... } click to toggle source
# File lib/bio/io/flatfile/indexer.rb, line 155
def parse_secondary
  self.secondary.each do |x|
    p = x.proc.call(@entry)
    p.each do |y|
      yield x.name, y if y.length > 0
    end
  end
end
set_primary_namespace(name) click to toggle source
# File lib/bio/io/flatfile/indexer.rb, line 87
def set_primary_namespace(name)
  DEBUG.print "set_primary_namespace: #{name.inspect}\n"
  if name.is_a?(NameSpace) then
    @primary = name
  else
    @primary = @namestyle[name] 
  end
  raise 'unknown primary namespace' unless @primary
  @primary
end