Class: Bio::FlatFileIndex::Indexer::Parser::TemplateParser
- Defined in:
- lib/bio/io/flatfile/indexer.rb
Direct Known Subclasses
BlastDefaultParser, EMBLParser, FastaFormatParser, GenBankParser, MaXMLClusterParser, MaXMLSequenceParser, PDBChemicalComponentParser
Constant Summary collapse
- NAMESTYLE =
NameSpaces.new
Instance Attribute Summary collapse
-
#dbclass ⇒ Object
readonly
Returns the value of attribute dbclass.
-
#errorlog ⇒ Object
readonly
Returns the value of attribute errorlog.
-
#fileid ⇒ Object
readonly
Returns the value of attribute fileid.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#primary ⇒ Object
readonly
Returns the value of attribute primary.
-
#secondary ⇒ Object
readonly
Returns the value of attribute secondary.
Instance Method Summary collapse
- #add_secondary_namespaces(*names) ⇒ Object
- #close_flatfile ⇒ Object
- #each ⇒ Object
-
#initialize ⇒ TemplateParser
constructor
A new instance of TemplateParser.
-
#open_flatfile(fileid, file) ⇒ Object
administration of a single flatfile.
- #parse_primary ⇒ Object
- #parse_secondary ⇒ Object
- #set_primary_namespace(name) ⇒ Object
Constructor Details
#initialize ⇒ TemplateParser
Returns a new instance of TemplateParser.
79 80 81 82 83 |
# File 'lib/bio/io/flatfile/indexer.rb', line 79 def initialize @namestyle = self.class::NAMESTYLE @secondary = NameSpaces.new @errorlog = [] end |
Instance Attribute Details
#dbclass ⇒ Object
Returns the value of attribute dbclass.
84 85 86 |
# File 'lib/bio/io/flatfile/indexer.rb', line 84 def dbclass @dbclass end |
#errorlog ⇒ Object (readonly)
Returns the value of attribute errorlog.
85 86 87 |
# File 'lib/bio/io/flatfile/indexer.rb', line 85 def errorlog @errorlog end |
#fileid ⇒ Object (readonly)
Returns the value of attribute fileid.
120 121 122 |
# File 'lib/bio/io/flatfile/indexer.rb', line 120 def fileid @fileid end |
#format ⇒ Object
Returns the value of attribute format.
84 85 86 |
# File 'lib/bio/io/flatfile/indexer.rb', line 84 def format @format end |
#primary ⇒ Object (readonly)
Returns the value of attribute primary.
84 85 86 |
# File 'lib/bio/io/flatfile/indexer.rb', line 84 def primary @primary end |
#secondary ⇒ Object (readonly)
Returns the value of attribute secondary.
84 85 86 |
# File 'lib/bio/io/flatfile/indexer.rb', line 84 def secondary @secondary end |
Instance Method Details
#add_secondary_namespaces(*names) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 |
# 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 ⇒ Object
164 165 166 167 |
# File 'lib/bio/io/flatfile/indexer.rb', line 164 def close_flatfile DEBUG.print "close flatfile #{@flatfilename.inspect}\n" @flatfile.close end |
#each ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# 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) ⇒ Object
administration of a single flatfile
111 112 113 114 115 116 117 118 119 |
# 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 ⇒ Object
146 147 148 149 150 151 152 153 |
# 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 ⇒ Object
155 156 157 158 159 160 161 162 |
# 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) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# 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 |