Package org.biojava.bio.program.sax
Class FastaSearchSAXParser
- java.lang.Object
-
- org.biojava.bio.program.sax.FastaSearchSAXParser
-
- All Implemented Interfaces:
SearchContentHandler,XMLReader
public class FastaSearchSAXParser extends Object implements SearchContentHandler
FastaSearchSAXParseris a SAX2 compliant parser for '-m 10' format output from the the Fasta search program (see the Fasta documentation for details of this format).Versions of Fasta supported are as follows. Note that the compile time option -DM10_CONS should be used to allow correct reporting of the number of matches in HSPSummary elements
- 33t07
- 33t08 (current tests are against output from this version)
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.
- Since:
- 1.2
- Author:
- Keith James
-
-
Field Summary
Fields Modifier and Type Field Description protected intiStateprotected StringoFullNamespacePrefixprotected ContentHandleroHandlerprotected StringoNamespacePrefixprotected booleantNamespacePrefixesprotected booleantNamespaces
-
Constructor Summary
Constructors Constructor Description FastaSearchSAXParser()Creates a newFastaSearchSAXParserinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddHitProperty(Object key, Object value)TheaddHitPropertymethod adds a key/value pair containing some property of a particular hit.voidaddPrefixMapping(String poPrefix, String poURI)Adds a namespace prefix to URI mapping as (key,value) pairs.voidaddSearchProperty(Object key, Object value)TheaddSearchPropertymethod adds a key/value pair containing some property of the overall search result.voidaddSubHitProperty(Object key, Object value)TheaddSubHitPropertymethod adds a key/value pair containing some property of a particular subhit.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.voidendHeader()TheendHeadermethod indicates the end of a formatted header.voidendHit()TheendHitmethod indicates the end of a formatted hit.voidendSearch()TheendSearchmethod indicates the end of useful search information.voidendSubHit()TheendSubHitmethod indicates the end of a formatted subhit.ContentHandlergetContentHandler()Return the content handler.protected BufferedReadergetContentStream(InputSource poSource)Create a stream from an an InputSource, picking the correct stream according to order of precedance.DTDHandlergetDTDHandler()Do-nothing implementation of interface methodEntityResolvergetEntityResolver()Do-nothing implementation of interface methodErrorHandlergetErrorHandler()Do-nothing implementation of interface methodbooleangetFeature(String poName)Do-nothing implementation of interface methodbooleangetMoreSearches()getMoreSearchesreturns the state of theSearchContentHandlerwith respect to further searches from its data source.StringgetNamespacePrefix()DescribegetNamespacePrefixmethod here.booleangetNamespacePrefixes()Support SAX2 configuration of namespace support of parser.booleangetNamespaces()Support SAX2 configuration of namespace support of parser.ObjectgetProperty(String name)Do-nothing implementation of interface methodStringgetURIFromPrefix(String poPrefix)Gets the URI for a namespace prefix, given that prefix, or null if the prefix is not recognised.voidparse(String poSystemId)Full implementation of interface method.voidparse(InputSource source)Do-nothing implementation of interface methodStringprefix(String poElementName)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.voidsetDatabaseID(String databaseID)setDatabaseIDidentifies the database searched by a name, ID or URN.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-prefixesvoidsetMoreSearches(boolean value)setMoreSearchessets the state of theSearchContentHandler's expectation of receiving more results.voidsetNamespacePrefix(String poPrefix)voidsetProperty(String name, Object value)Do-nothing implementation of interface methodvoidsetQueryID(String queryID)setQueryIDidentifies the query sequence by a name, ID or URN.voidsetQuerySeq(String identifier)Deprecated.usesetQueryIDinstead.voidsetSubjectDB(String identifier)Deprecated.usesetDatabaseIDinstead.protected voidstartElement(org.biojava.bio.program.sax.QName poQName, Attributes atts)Utility method to centralize sending of a SAX startElement message to document handlervoidstartHeader()ThestartHeadermethod indicates the start of a formatted header.voidstartHit()ThestartHitmethod indicates the start of a formatted hit.voidstartSearch()ThestartSearchmethod indicates the start of useful search information.voidstartSubHit()ThestartSubHitmethod indicates the start of a formatted subhit.
-
-
-
Field Detail
-
oHandler
protected ContentHandler oHandler
-
tNamespaces
protected boolean tNamespaces
-
tNamespacePrefixes
protected boolean tNamespacePrefixes
-
oNamespacePrefix
protected String oNamespacePrefix
-
oFullNamespacePrefix
protected String oFullNamespacePrefix
-
iState
protected int iState
-
-
Constructor Detail
-
FastaSearchSAXParser
public FastaSearchSAXParser()
Creates a newFastaSearchSAXParserinstance.
-
-
Method Detail
-
parse
public void parse(InputSource source) throws IOException, SAXException
Do-nothing implementation of interface method- Specified by:
parsein interfaceXMLReader- Throws:
IOExceptionSAXException
-
getMoreSearches
public boolean getMoreSearches()
Description copied from interface:SearchContentHandlergetMoreSearchesreturns the state of theSearchContentHandlerwith respect to further searches from its data source. Used for handling streams of search results.- Specified by:
getMoreSearchesin interfaceSearchContentHandler- Returns:
- a
booleanvalue.
-
setMoreSearches
public void setMoreSearches(boolean value)
Description copied from interface:SearchContentHandlersetMoreSearchessets the state of theSearchContentHandler's expectation of receiving more results. Used for handling streams of search results.- Specified by:
setMoreSearchesin interfaceSearchContentHandler- Parameters:
value- abooleanvalue.
-
setQuerySeq
public void setQuerySeq(String identifier)
Deprecated.usesetQueryIDinstead.setQuerySeqidentifies the query sequence by a name, ID or URN.- Parameters:
identifier- aStringwhich should be an unique identifer for the sequence.
-
setQueryID
public void setQueryID(String queryID)
Description copied from interface:SearchContentHandlersetQueryIDidentifies the query sequence by a name, ID or URN.- Specified by:
setQueryIDin interfaceSearchContentHandler- Parameters:
queryID- aStringwhich should be an unique identifer for the sequence.
-
setSubjectDB
public void setSubjectDB(String identifier)
Deprecated.usesetDatabaseIDinstead.setSubjectDBidentifies the database searched by a name, ID or URN.- Parameters:
identifier- aStringwhich should be an unique identifier for the database searched.
-
setDatabaseID
public void setDatabaseID(String databaseID)
Description copied from interface:SearchContentHandlersetDatabaseIDidentifies the database searched by a name, ID or URN.- Specified by:
setDatabaseIDin interfaceSearchContentHandler- Parameters:
databaseID- aStringwhich should be an unique identifier for the database searched.
-
startSearch
public void startSearch()
Description copied from interface:SearchContentHandlerThestartSearchmethod indicates the start of useful search information.- Specified by:
startSearchin interfaceSearchContentHandler
-
addSearchProperty
public void addSearchProperty(Object key, Object value)
Description copied from interface:SearchContentHandlerTheaddSearchPropertymethod adds a key/value pair containing some property of the overall search result.- Specified by:
addSearchPropertyin interfaceSearchContentHandler- Parameters:
key- anObject.value- anObject.
-
endSearch
public void endSearch()
Description copied from interface:SearchContentHandlerTheendSearchmethod indicates the end of useful search information.- Specified by:
endSearchin interfaceSearchContentHandler
-
startHeader
public void startHeader()
Description copied from interface:SearchContentHandlerThestartHeadermethod indicates the start of a formatted header. This usually contains information relevant to the search as a whole.- Specified by:
startHeaderin interfaceSearchContentHandler
-
endHeader
public void endHeader()
Description copied from interface:SearchContentHandlerTheendHeadermethod indicates the end of a formatted header.- Specified by:
endHeaderin interfaceSearchContentHandler
-
startHit
public void startHit()
Description copied from interface:SearchContentHandlerThestartHitmethod indicates the start of a formatted hit. This could be a single line, or a block of lines.- Specified by:
startHitin interfaceSearchContentHandler
-
addHitProperty
public void addHitProperty(Object key, Object value)
Description copied from interface:SearchContentHandlerTheaddHitPropertymethod adds a key/value pair containing some property of a particular hit.- Specified by:
addHitPropertyin interfaceSearchContentHandler- Parameters:
key- anObject.value- anObject.
-
endHit
public void endHit()
Description copied from interface:SearchContentHandlerTheendHitmethod indicates the end of a formatted hit.- Specified by:
endHitin interfaceSearchContentHandler
-
startSubHit
public void startSubHit()
Description copied from interface:SearchContentHandlerThestartSubHitmethod indicates the start of a formatted subhit. There may be zero or more of these per hit.- Specified by:
startSubHitin interfaceSearchContentHandler
-
addSubHitProperty
public void addSubHitProperty(Object key, Object value)
Description copied from interface:SearchContentHandlerTheaddSubHitPropertymethod adds a key/value pair containing some property of a particular subhit.- Specified by:
addSubHitPropertyin interfaceSearchContentHandler- Parameters:
key- anObject.value- anObject.
-
endSubHit
public void endSubHit()
Description copied from interface:SearchContentHandlerTheendSubHitmethod indicates the end of a formatted subhit.- Specified by:
endSubHitin interfaceSearchContentHandler
-
setContentHandler
public void setContentHandler(ContentHandler poHandler)
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
public ContentHandler getContentHandler()
Return the content handler.- Specified by:
getContentHandlerin interfaceXMLReader- Returns:
- a
ContentHandlerThe current content handler, or null if none has been registered.
-
parse
public void parse(String poSystemId) throws IOException, SAXException
Full implementation of interface method.- Specified by:
parsein interfaceXMLReader- Throws:
IOExceptionSAXException
-
getFeature
public boolean getFeature(String poName) throws SAXNotRecognizedException, SAXNotSupportedException
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
public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException
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
public void setEntityResolver(EntityResolver resolver)
Do-nothing implementation of interface method- Specified by:
setEntityResolverin interfaceXMLReader
-
getEntityResolver
public EntityResolver getEntityResolver()
Do-nothing implementation of interface method- Specified by:
getEntityResolverin interfaceXMLReader
-
setDTDHandler
public void setDTDHandler(DTDHandler handler)
Do-nothing implementation of interface method- Specified by:
setDTDHandlerin interfaceXMLReader
-
getDTDHandler
public DTDHandler getDTDHandler()
Do-nothing implementation of interface method- Specified by:
getDTDHandlerin interfaceXMLReader
-
setErrorHandler
public void setErrorHandler(ErrorHandler handler)
Do-nothing implementation of interface method- Specified by:
setErrorHandlerin interfaceXMLReader
-
getErrorHandler
public ErrorHandler 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 SAXExceptionUtility method to centralize sending of a SAX startElement message to document handler- Parameters:
poQName- aQNamevalueatts- anAttributesvalue- Throws:
SAXException- if an error occurs
-
endElement
protected void endElement(org.biojava.bio.program.sax.QName poQName) throws SAXExceptionUtility method to centralize the sending of a SAX endElement message a document handler.- Parameters:
poQName- -- Throws:
SAXException- thrown ifthrown- if
-
characters
protected void characters(char[] ch, int start, int length) throws SAXExceptionUtility 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
public void addPrefixMapping(String poPrefix, String poURI)
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
public String getURIFromPrefix(String poPrefix)
Gets the URI for a namespace prefix, given that prefix, or null if the prefix is not recognised.- Parameters:
poPrefix- aStringThe namespace prefix.
-
setNamespacePrefix
public void setNamespacePrefix(String poPrefix)
- Parameters:
poPrefix- aStringvalue
-
getNamespacePrefix
public String getNamespacePrefix()
DescribegetNamespacePrefixmethod here.- Returns:
- a
Stringvalue
-
prefix
public String prefix(String poElementName)
Given an unprefixed element name, returns a new element name with a namespace prefix- Returns:
- a
Stringvalue
-
getContentStream
protected BufferedReader getContentStream(InputSource poSource)
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
-
-