Class FastaSearchSAXParser

java.lang.Object
org.biojava.bio.program.sax.FastaSearchSAXParser
All Implemented Interfaces:
SearchContentHandler, XMLReader

public class FastaSearchSAXParser extends Object implements SearchContentHandler

FastaSearchSAXParser is 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 Details

    • 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 Details

  • Method Details

    • parse

      public void parse(InputSource source) throws IOException, SAXException
      Do-nothing implementation of interface method
      Specified by:
      parse in interface XMLReader
      Throws:
      IOException
      SAXException
    • getMoreSearches

      public boolean getMoreSearches()
      Description copied from interface: SearchContentHandler
      getMoreSearches returns the state of the SearchContentHandler with respect to further searches from its data source. Used for handling streams of search results.
      Specified by:
      getMoreSearches in interface SearchContentHandler
      Returns:
      a boolean value.
    • setMoreSearches

      public void setMoreSearches(boolean value)
      Description copied from interface: SearchContentHandler
      setMoreSearches sets the state of the SearchContentHandler's expectation of receiving more results. Used for handling streams of search results.
      Specified by:
      setMoreSearches in interface SearchContentHandler
      Parameters:
      value - a boolean value.
    • setQuerySeq

      public void setQuerySeq(String identifier)
      Deprecated.
      use setQueryID instead.
      setQuerySeq identifies the query sequence by a name, ID or URN.
      Parameters:
      identifier - a String which should be an unique identifer for the sequence.
    • setQueryID

      public void setQueryID(String queryID)
      Description copied from interface: SearchContentHandler
      setQueryID identifies the query sequence by a name, ID or URN.
      Specified by:
      setQueryID in interface SearchContentHandler
      Parameters:
      queryID - a String which should be an unique identifer for the sequence.
    • setSubjectDB

      public void setSubjectDB(String identifier)
      Deprecated.
      use setDatabaseID instead.
      setSubjectDB identifies the database searched by a name, ID or URN.
      Parameters:
      identifier - a String which should be an unique identifier for the database searched.
    • setDatabaseID

      public void setDatabaseID(String databaseID)
      Description copied from interface: SearchContentHandler
      setDatabaseID identifies the database searched by a name, ID or URN.
      Specified by:
      setDatabaseID in interface SearchContentHandler
      Parameters:
      databaseID - a String which should be an unique identifier for the database searched.
    • startSearch

      public void startSearch()
      Description copied from interface: SearchContentHandler
      The startSearch method indicates the start of useful search information.
      Specified by:
      startSearch in interface SearchContentHandler
    • addSearchProperty

      public void addSearchProperty(Object key, Object value)
      Description copied from interface: SearchContentHandler
      The addSearchProperty method adds a key/value pair containing some property of the overall search result.
      Specified by:
      addSearchProperty in interface SearchContentHandler
      Parameters:
      key - an Object.
      value - an Object.
    • endSearch

      public void endSearch()
      Description copied from interface: SearchContentHandler
      The endSearch method indicates the end of useful search information.
      Specified by:
      endSearch in interface SearchContentHandler
    • startHeader

      public void startHeader()
      Description copied from interface: SearchContentHandler
      The startHeader method indicates the start of a formatted header. This usually contains information relevant to the search as a whole.
      Specified by:
      startHeader in interface SearchContentHandler
    • endHeader

      public void endHeader()
      Description copied from interface: SearchContentHandler
      The endHeader method indicates the end of a formatted header.
      Specified by:
      endHeader in interface SearchContentHandler
    • startHit

      public void startHit()
      Description copied from interface: SearchContentHandler
      The startHit method indicates the start of a formatted hit. This could be a single line, or a block of lines.
      Specified by:
      startHit in interface SearchContentHandler
    • addHitProperty

      public void addHitProperty(Object key, Object value)
      Description copied from interface: SearchContentHandler
      The addHitProperty method adds a key/value pair containing some property of a particular hit.
      Specified by:
      addHitProperty in interface SearchContentHandler
      Parameters:
      key - an Object.
      value - an Object.
    • endHit

      public void endHit()
      Description copied from interface: SearchContentHandler
      The endHit method indicates the end of a formatted hit.
      Specified by:
      endHit in interface SearchContentHandler
    • startSubHit

      public void startSubHit()
      Description copied from interface: SearchContentHandler
      The startSubHit method indicates the start of a formatted subhit. There may be zero or more of these per hit.
      Specified by:
      startSubHit in interface SearchContentHandler
    • addSubHitProperty

      public void addSubHitProperty(Object key, Object value)
      Description copied from interface: SearchContentHandler
      The addSubHitProperty method adds a key/value pair containing some property of a particular subhit.
      Specified by:
      addSubHitProperty in interface SearchContentHandler
      Parameters:
      key - an Object.
      value - an Object.
    • endSubHit

      public void endSubHit()
      Description copied from interface: SearchContentHandler
      The endSubHit method indicates the end of a formatted subhit.
      Specified by:
      endSubHit in interface SearchContentHandler
    • 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:
      setContentHandler in interface XMLReader
      Parameters:
      poHandler - a ContentHandler The XML content handler
      Throws:
      NullPointerException - If the handler argument is null
    • getContentHandler

      public ContentHandler getContentHandler()
      Return the content handler.
      Specified by:
      getContentHandler in interface XMLReader
      Returns:
      a ContentHandler The 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:
      parse in interface XMLReader
      Throws:
      IOException
      SAXException
    • getFeature

      public boolean getFeature(String poName) throws SAXNotRecognizedException, SAXNotSupportedException
      Do-nothing implementation of interface method
      Specified by:
      getFeature in interface XMLReader
      Throws:
      SAXNotRecognizedException
      SAXNotSupportedException
    • setFeature

      public void setFeature(String poName, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException
      Handles support for ReasoningDomain and Namespace-prefixes
      Specified by:
      setFeature in interface XMLReader
      Throws:
      SAXNotRecognizedException
      SAXNotSupportedException
    • getProperty

      Do-nothing implementation of interface method
      Specified by:
      getProperty in interface XMLReader
      Throws:
      SAXNotRecognizedException
      SAXNotSupportedException
    • setProperty

      public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException
      Do-nothing implementation of interface method
      Specified by:
      setProperty in interface XMLReader
      Throws:
      SAXNotRecognizedException
      SAXNotSupportedException
    • setEntityResolver

      public void setEntityResolver(EntityResolver resolver)
      Do-nothing implementation of interface method
      Specified by:
      setEntityResolver in interface XMLReader
    • getEntityResolver

      public EntityResolver getEntityResolver()
      Do-nothing implementation of interface method
      Specified by:
      getEntityResolver in interface XMLReader
    • setDTDHandler

      public void setDTDHandler(DTDHandler handler)
      Do-nothing implementation of interface method
      Specified by:
      setDTDHandler in interface XMLReader
    • getDTDHandler

      public DTDHandler getDTDHandler()
      Do-nothing implementation of interface method
      Specified by:
      getDTDHandler in interface XMLReader
    • setErrorHandler

      public void setErrorHandler(ErrorHandler handler)
      Do-nothing implementation of interface method
      Specified by:
      setErrorHandler in interface XMLReader
    • getErrorHandler

      public ErrorHandler getErrorHandler()
      Do-nothing implementation of interface method
      Specified by:
      getErrorHandler in interface XMLReader
    • 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 - a QName value
      atts - an Attributes value
      Throws:
      SAXException - if an error occurs
    • endElement

      protected void endElement(org.biojava.bio.program.sax.QName poQName) throws SAXException
      Utility method to centralize the sending of a SAX endElement message a document handler.
      Parameters:
      poQName - -
    • characters

      protected void characters(char[] ch, int start, int length) throws SAXException
      Utility method to centralize the sending of a SAX characters message a document handler.
      Parameters:
      ch - -
      start - -
      length - -
    • 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 - a String representation of the namespace prefix
      poURI - a String representation 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 - a String The namespace prefix.
    • setNamespacePrefix

      public void setNamespacePrefix(String poPrefix)
      Parameters:
      poPrefix - a String value
    • getNamespacePrefix

      public String getNamespacePrefix()
      Describe getNamespacePrefix method here.
      Returns:
      a String value
    • prefix

      public String prefix(String poElementName)
      Given an unprefixed element name, returns a new element name with a namespace prefix
      Returns:
      a String value
    • getContentStream

      protected BufferedReader getContentStream(InputSource poSource)
      Create a stream from an an InputSource, picking the correct stream according to order of precedance.
      Parameters:
      poSource - an InputSource value
      Returns:
      a BufferedReader value
    • 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 - an int value