Bio::PullParserI

Bio::PullParserI is a base module for fast 'pull' parsing.
Download

Bio::PullParserI Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Sendu Bala
  • Publisher web site:
  • http://search.cpan.org/~sendu/

Bio::PullParserI Tags


Bio::PullParserI Description

Bio::PullParserI is a base module for fast 'pull' parsing. Bio::PullParserI is a base module for fast 'pull' parsing.SYNOPSIS # do not use this class, it is intended for parser module # writers onlyIf you are writing a module to parse some new format, you may wish to use a 'pull' approach whereby you only do work (reading file data, parsing it, turning the parsed data in an object) when absolutely necessary.PullParserI provides a system for doing exactly that. As a PullParser you need a chunk. A chunk is just a Bio::Root::IO that contains all the raw data you would want to parse. You can use the chunk() method to create a chunk from a filename, existing filehandle or even a string. If you make a chunk from a large file, but actually only want your chunk to be some portion of the whole file, supply start and end amounts in bytes to chunk() at the same time. The methods _chunk_seek() and _chunk_tell() provide seeks and tells that are relative to the start and end of your chunk, not the whole file.The other thing you will need to decide when making a chunk is how to handle piped input. A PullParser typically needs seekable data to parse, so if your data is piped in and unseekable, you must decide between creating a temp file or reading the input into memory, which will be done before the chunk becomes usable and you can begin any parsing. Alternatively you can choose to force a sequential read, in which case you can make use of _dependencies() to define the linear order of methods that would result in the file being read sequentially. The return value of _sequential() is also useful here, if you would need to cache some data or otherwise behave differently during a sequential read.The main method in the system is get_field(). This method relies on the existance of a private hash reference accessible to it with the method _fields(). That hash ref should have as keys all the sorts of data you will want to parse (eg. 'score'), and prior to parsing the values would be undefined. A user of your module can then call either $module->get_field('score') or $module->score and get_field will either return the answer from $self->_fields->{score} if it is defined, or call a method _discover_score() first if not. So for the system to work you need to define a _discover_*() method for every field in the fields hash, and ensure that the method stores an answer in the fields hash.How you implement your _discover_* methods is up to you, though you should never call a _discover_* method directly yourself; always use get_field(), since get_field() will deal with calling dependant methods for you if a forced sequenctial read is in progress due to piped input. You will almost certainly want to make use of the various chunk-related methods of this class (that are denoted private by the leading '_'; this means you can use them as the author of a parser class, but users of your parser should not).Primary amongst them is _*_chunk_by_end() to which you provide text that represents the end of your desired chunk and it does a readline with your argument as $/. The chunk knows about its line-endings, so if you want your end definition to include a new line, just always use "n" and PullParserI will do any necessary conversion for you.If your input data is hierarchical (eg. report->many results->many hits->many hsps), and you want an object at the leaf of the hierarchy to have access to information that is shared amongst all of them (is parsed in the root), you don't have to copy the data to each leaf object; simply by defining parent(), when you call get_field() and the requested field isn't in your leaf's fields hash, the leaf's parent will be asked for the field instead, and so on till root.See Bio::SearchIO::hmmer_pull for an example of implementing a parser using PullParserI. Requirements: · Perl


Bio::PullParserI Related Software