Class: Bio::FlatFileIndex::Indexer::Parser::FastaFormatParser

Inherits:
TemplateParser show all
Defined in:
lib/bio/io/flatfile/indexer.rb

Overview

class SPTRParser

Constant Summary

NAMESTYLE =
NameSpaces.new(
             NameSpace.new( 'UNIQUE', nil ),
             NameSpace.new( 'entry_id', Proc.new { |x| x.entry_id } ),
             NameSpace.new( 'accession', Proc.new { |x| x.accessions } ),
             NameSpace.new( 'id_string', Proc.new { |x| 
                             x.identifiers.id_strings
                           }),
             NameSpace.new( 'word', Proc.new { |x|
                             x.identifiers.words
                           })
)
PRIMARY =
'UNIQUE'
SECONDARY =
[ 'entry_id', 'accession', 'id_string', 'word' ]

Instance Attribute Summary

Attributes inherited from TemplateParser

#dbclass, #errorlog, #fileid, #format, #primary, #secondary

Instance Method Summary (collapse)

Methods inherited from TemplateParser

#add_secondary_namespaces, #close_flatfile, #each, #parse_secondary, #set_primary_namespace

Constructor Details

- (FastaFormatParser) initialize(pri_name = nil, sec_names = nil)

Returns a new instance of FastaFormatParser



275
276
277
278
279
280
281
282
283
284
# File 'lib/bio/io/flatfile/indexer.rb', line 275

def initialize(pri_name = nil, sec_names = nil)
  super()
  self.format = 'fasta'
  self.dbclass = Bio::FastaFormat
  self.set_primary_namespace((pri_name or PRIMARY))
  unless sec_names then
    sec_names = self.class::SECONDARY
  end
  self.add_secondary_namespaces(*sec_names)
end

Instance Method Details

- (Object) open_flatfile(fileid, file)



285
286
287
288
289
290
291
292
293
294
295
# File 'lib/bio/io/flatfile/indexer.rb', line 285

def open_flatfile(fileid, file)
  super
  @count = 1
  @flatfilename_base = File.basename(@flatfilename)
  @flatfile.pos = 0
  begin
    pos = @flatfile.pos
    line = @flatfile.gets
  end until (!line or line =~ /^\>/)
  @flatfile.pos = pos
end

- (Object) parse_primary



262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/bio/io/flatfile/indexer.rb', line 262

def parse_primary
  if p = self.primary.proc then
    r = p.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
  else
    unique_primary_key
  end
end