Class BlastLikeSAXParser
- All Implemented Interfaces:
XMLReader
The SAX2 events produced are as if the input to the parser was an XML file validating against the biojava BlastLikeDataSetCollection DTD. There is no requirement for an intermediate conversion of native output to XML format. An application of the parsing framework, however, is to create XML format files from native output files.
The biojava Blast-like parsing framework is designed to uses minimal memory,so that in principle, extremely large native outputs can be parsed and XML ContentHandlers can listen only for small amounts of information.
The framework currently supports parsing of native output from the following bioinformatics programs. Please note that if you are using different versions of NCBI or WU Blast to those listed below, it is worth considering trying setting the parsing mode to Lazy, which means parsing will be attempted if the program is recognised, regardless of version.
- NCBI Blast version 2.0.11
- NCBI Blast version 2.2.2
- NCBI Blast version 2.2.3
- WU-Blast version 2.0a19mp-washu
- HMMER 2.1.1 hmmsearch
- Support for HMMER hmmpfam almost there but not fully tested
Notes to SAX driver writers
The framework that this parser is built on is designed to be extensible with support for both different pieces of software (i.e. not just software that produces Blast-like output), and multiple versions of programs.
This class inherits from the org.biojava.bio.program.sax.AbstractNativeAppSAXParser abstract base class. The abstract base class is a good place to start looking if you want to write new native application SAX2 parsers. This and releated classes have only package-level visibility. Typically, application writers are expected to provide a facade class in this package (similar to the current class) to allow users access to functionality.
NB Support for InputSource is not complete due to the fact that URLs are not resolved and cannot, therefore, be used as an InputSource. System pathnames, ByteStreams and CharacterStreams, however, are all supported.
Copyright © 2000 Cambridge Antibody Technology.
Primary author -
- Simon Brocklehurst (CAT)
- Tim Dilks (CAT)
- Colin Hardman (CAT)
- Stuart Johnston (CAT)
- Mathieu Wiepert (Mayo Foundation)
- Travis Banks
- Version:
- 1.0
- Author:
- Cambridge Antibody Technology (CAT), Travis Banks
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected Stringprotected ContentHandlerprotected Stringprotected booleanprotected boolean -
Constructor Summary
ConstructorsConstructorDescriptionInitialises SAXParser, and sets default namespace prefix to "biojava". -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPrefixMapping(String poPrefix, String poURI) Adds a namespace prefix to URI mapping as (key,value) pairs.protected voidchangeState(int piState) Centralise chaining of iState field to help with debugging.protected voidcharacters(char[] ch, int start, int length) Utility method to centralize the sending of a SAX characters message a document handler.protected voidendElement(org.biojava.bio.program.sax.QName poQName) Utility method to centralize the sending of a SAX endElement message a document handler.Return the content handler.protected BufferedReadergetContentStream(InputSource poSource) Create a stream from an an InputSource, picking the correct stream according to order of precedance.Do-nothing implementation of interface methodDo-nothing implementation of interface methodDo-nothing implementation of interface methodbooleangetFeature(String poName) Do-nothing implementation of interface methodDescribegetNamespacePrefixmethod here.booleanSupport SAX2 configuration of namespace support of parser.booleanSupport SAX2 configuration of namespace support of parser.getProperty(String name) Do-nothing implementation of interface methodgetURIFromPrefix(String poPrefix) Gets the URI for a namespace prefix, given that prefix, or null if the prefix is not recognised.voidFull implementation of interface method.voidparse(InputSource poSource) parseinitiates the parsing operation.Given an unprefixed element name, returns a new element name with a namespace prefixvoidsetContentHandler(ContentHandler poHandler) Allow an application to register a content event handler.voidsetDTDHandler(DTDHandler handler) Do-nothing implementation of interface methodvoidsetEntityResolver(EntityResolver resolver) Do-nothing implementation of interface methodvoidsetErrorHandler(ErrorHandler handler) Do-nothing implementation of interface methodvoidsetFeature(String poName, boolean value) Handles support for ReasoningDomain and Namespace-prefixesvoidSetting the mode to lazy means that, if the program is recognised, e.g.voidThis is the default, parsing will be attempted only if both the program e.g.voidsetNamespacePrefix(String poPrefix) voidsetProperty(String name, Object value) Do-nothing implementation of interface methodprotected voidstartElement(org.biojava.bio.program.sax.QName poQName, Attributes atts) Utility method to centralize sending of a SAX startElement message to document handler
-
Field Details
-
oHandler
-
tNamespaces
protected boolean tNamespaces -
tNamespacePrefixes
protected boolean tNamespacePrefixes -
oNamespacePrefix
-
oFullNamespacePrefix
-
iState
protected int iState
-
-
Constructor Details
-
BlastLikeSAXParser
public BlastLikeSAXParser()Initialises SAXParser, and sets default namespace prefix to "biojava".
-
-
Method Details
-
parse
parseinitiates the parsing operation.- Specified by:
parsein interfaceXMLReader- Parameters:
poSource- anInputSource.- Throws:
IOException- if an error occurs.SAXException- if an error occurs.
-
setModeStrict
This is the default, parsing will be attempted only if both the program e.g. NCBI BlastP, and a particular version are recognised as bsing supported. -
setModeLazy
Setting the mode to lazy means that, if the program is recognised, e.g. WU-TBlastX, then parsing will be attempted even if the particular version is not recognised. Using this option is more likely to result in erroneous parsing than if the strict mode is used. -
setContentHandler
Allow an application to register a content event handler. If the application does not register a content handler, all content events reported by the SAX parser will be silently ignored.Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.
- Specified by:
setContentHandlerin interfaceXMLReader- Parameters:
poHandler- aContentHandlerThe XML content handler- Throws:
NullPointerException- If the handler argument is null
-
getContentHandler
Return the content handler.- Specified by:
getContentHandlerin interfaceXMLReader- Returns:
- a
ContentHandlerThe current content handler, or null if none has been registered.
-
parse
Full implementation of interface method.- Specified by:
parsein interfaceXMLReader- Throws:
IOExceptionSAXException
-
getFeature
Do-nothing implementation of interface method- Specified by:
getFeaturein interfaceXMLReader- Throws:
SAXNotRecognizedExceptionSAXNotSupportedException
-
setFeature
public void setFeature(String poName, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException Handles support for ReasoningDomain and Namespace-prefixes- Specified by:
setFeaturein interfaceXMLReader- Throws:
SAXNotRecognizedExceptionSAXNotSupportedException
-
getProperty
Do-nothing implementation of interface method- Specified by:
getPropertyin interfaceXMLReader- Throws:
SAXNotRecognizedExceptionSAXNotSupportedException
-
setProperty
public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException Do-nothing implementation of interface method- Specified by:
setPropertyin interfaceXMLReader- Throws:
SAXNotRecognizedExceptionSAXNotSupportedException
-
setEntityResolver
Do-nothing implementation of interface method- Specified by:
setEntityResolverin interfaceXMLReader
-
getEntityResolver
Do-nothing implementation of interface method- Specified by:
getEntityResolverin interfaceXMLReader
-
setDTDHandler
Do-nothing implementation of interface method- Specified by:
setDTDHandlerin interfaceXMLReader
-
getDTDHandler
Do-nothing implementation of interface method- Specified by:
getDTDHandlerin interfaceXMLReader
-
setErrorHandler
Do-nothing implementation of interface method- Specified by:
setErrorHandlerin interfaceXMLReader
-
getErrorHandler
Do-nothing implementation of interface method- Specified by:
getErrorHandlerin interfaceXMLReader
-
startElement
protected void startElement(org.biojava.bio.program.sax.QName poQName, Attributes atts) throws SAXException Utility method to centralize sending of a SAX startElement message to document handler- Parameters:
poQName- aQNamevalueatts- anAttributesvalue- Throws:
SAXException- if an error occurs
-
endElement
Utility method to centralize the sending of a SAX endElement message a document handler.- Parameters:
poQName- -- Throws:
SAXException- thrown ifthrown- if
-
characters
Utility method to centralize the sending of a SAX characters message a document handler.- Parameters:
ch- -start- -length- -- Throws:
SAXException- thrown ifthrown- if
-
getNamespaces
public boolean getNamespaces()Support SAX2 configuration of namespace support of parser. -
getNamespacePrefixes
public boolean getNamespacePrefixes()Support SAX2 configuration of namespace support of parser. -
addPrefixMapping
Adds a namespace prefix to URI mapping as (key,value) pairs. This mapping can be looked up later to get URIs on request using the getURIFromPrefix method.- Parameters:
poPrefix- aStringrepresentation of the namespace prefixpoURI- aStringrepresentation of the URI for the namespace prefix.
-
getURIFromPrefix
Gets the URI for a namespace prefix, given that prefix, or null if the prefix is not recognised.- Parameters:
poPrefix- aStringThe namespace prefix.
-
setNamespacePrefix
- Parameters:
poPrefix- aStringvalue
-
getNamespacePrefix
DescribegetNamespacePrefixmethod here.- Returns:
- a
Stringvalue
-
prefix
Given an unprefixed element name, returns a new element name with a namespace prefix- Returns:
- a
Stringvalue
-
getContentStream
Create a stream from an an InputSource, picking the correct stream according to order of precedance.- Parameters:
poSource- anInputSourcevalue- Returns:
- a
BufferedReadervalue
-
changeState
protected void changeState(int piState) Centralise chaining of iState field to help with debugging. E.g. printing out value etc. All changes to iState should be made through this method.- Parameters:
piState- anintvalue
-