Class FastaSearchSAXParser

  • All Implemented Interfaces:
    SearchContentHandler, org.xml.sax.XMLReader

    public class FastaSearchSAXParser
    extends java.lang.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
    • Constructor Summary

      Constructors 
      Constructor Description
      FastaSearchSAXParser()
      Creates a new FastaSearchSAXParser instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void addHitProperty​(java.lang.Object key, java.lang.Object value)
      The addHitProperty method adds a key/value pair containing some property of a particular hit.
      void addPrefixMapping​(java.lang.String poPrefix, java.lang.String poURI)
      Adds a namespace prefix to URI mapping as (key,value) pairs.
      void addSearchProperty​(java.lang.Object key, java.lang.Object value)
      The addSearchProperty method adds a key/value pair containing some property of the overall search result.
      void addSubHitProperty​(java.lang.Object key, java.lang.Object value)
      The addSubHitProperty method adds a key/value pair containing some property of a particular subhit.
      protected void changeState​(int piState)
      Centralise chaining of iState field to help with debugging.
      protected void characters​(char[] ch, int start, int length)
      Utility method to centralize the sending of a SAX characters message a document handler.
      protected void endElement​(org.biojava.bio.program.sax.QName poQName)
      Utility method to centralize the sending of a SAX endElement message a document handler.
      void endHeader()
      The endHeader method indicates the end of a formatted header.
      void endHit()
      The endHit method indicates the end of a formatted hit.
      void endSearch()
      The endSearch method indicates the end of useful search information.
      void endSubHit()
      The endSubHit method indicates the end of a formatted subhit.
      org.xml.sax.ContentHandler getContentHandler()
      Return the content handler.
      protected java.io.BufferedReader getContentStream​(org.xml.sax.InputSource poSource)
      Create a stream from an an InputSource, picking the correct stream according to order of precedance.
      org.xml.sax.DTDHandler getDTDHandler()
      Do-nothing implementation of interface method
      org.xml.sax.EntityResolver getEntityResolver()
      Do-nothing implementation of interface method
      org.xml.sax.ErrorHandler getErrorHandler()
      Do-nothing implementation of interface method
      boolean getFeature​(java.lang.String poName)
      Do-nothing implementation of interface method
      boolean getMoreSearches()
      getMoreSearches returns the state of the SearchContentHandler with respect to further searches from its data source.
      java.lang.String getNamespacePrefix()
      Describe getNamespacePrefix method here.
      boolean getNamespacePrefixes()
      Support SAX2 configuration of namespace support of parser.
      boolean getNamespaces()
      Support SAX2 configuration of namespace support of parser.
      java.lang.Object getProperty​(java.lang.String name)
      Do-nothing implementation of interface method
      java.lang.String getURIFromPrefix​(java.lang.String poPrefix)
      Gets the URI for a namespace prefix, given that prefix, or null if the prefix is not recognised.
      void parse​(java.lang.String poSystemId)
      Full implementation of interface method.
      void parse​(org.xml.sax.InputSource source)
      Do-nothing implementation of interface method
      java.lang.String prefix​(java.lang.String poElementName)
      Given an unprefixed element name, returns a new element name with a namespace prefix
      void setContentHandler​(org.xml.sax.ContentHandler poHandler)
      Allow an application to register a content event handler.
      void setDatabaseID​(java.lang.String databaseID)
      setDatabaseID identifies the database searched by a name, ID or URN.
      void setDTDHandler​(org.xml.sax.DTDHandler handler)
      Do-nothing implementation of interface method
      void setEntityResolver​(org.xml.sax.EntityResolver resolver)
      Do-nothing implementation of interface method
      void setErrorHandler​(org.xml.sax.ErrorHandler handler)
      Do-nothing implementation of interface method
      void setFeature​(java.lang.String poName, boolean value)
      Handles support for ReasoningDomain and Namespace-prefixes
      void setMoreSearches​(boolean value)
      setMoreSearches sets the state of the SearchContentHandler's expectation of receiving more results.
      void setNamespacePrefix​(java.lang.String poPrefix)  
      void setProperty​(java.lang.String name, java.lang.Object value)
      Do-nothing implementation of interface method
      void setQueryID​(java.lang.String queryID)
      setQueryID identifies the query sequence by a name, ID or URN.
      void setQuerySeq​(java.lang.String identifier)
      Deprecated.
      use setQueryID instead.
      void setSubjectDB​(java.lang.String identifier)
      Deprecated.
      use setDatabaseID instead.
      protected void startElement​(org.biojava.bio.program.sax.QName poQName, org.xml.sax.Attributes atts)
      Utility method to centralize sending of a SAX startElement message to document handler
      void startHeader()
      The startHeader method indicates the start of a formatted header.
      void startHit()
      The startHit method indicates the start of a formatted hit.
      void startSearch()
      The startSearch method indicates the start of useful search information.
      void startSubHit()
      The startSubHit method indicates the start of a formatted subhit.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • oHandler

        protected org.xml.sax.ContentHandler oHandler
      • tNamespaces

        protected boolean tNamespaces
      • tNamespacePrefixes

        protected boolean tNamespacePrefixes
      • oNamespacePrefix

        protected java.lang.String oNamespacePrefix
      • oFullNamespacePrefix

        protected java.lang.String oFullNamespacePrefix
      • iState

        protected int iState
    • Constructor Detail

      • FastaSearchSAXParser

        public FastaSearchSAXParser()
        Creates a new FastaSearchSAXParser instance.
    • Method Detail

      • parse

        public void parse​(org.xml.sax.InputSource source)
                   throws java.io.IOException,
                          org.xml.sax.SAXException
        Do-nothing implementation of interface method
        Specified by:
        parse in interface org.xml.sax.XMLReader
        Throws:
        java.io.IOException
        org.xml.sax.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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.
      • addSearchProperty

        public void addSearchProperty​(java.lang.Object key,
                                      java.lang.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.
      • 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
      • 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​(java.lang.Object key,
                                   java.lang.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.
      • 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​(java.lang.Object key,
                                      java.lang.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.
      • setContentHandler

        public void setContentHandler​(org.xml.sax.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 org.xml.sax.XMLReader
        Parameters:
        poHandler - a ContentHandler The XML content handler
        Throws:
        java.lang.NullPointerException - If the handler argument is null
      • getContentHandler

        public org.xml.sax.ContentHandler getContentHandler()
        Return the content handler.
        Specified by:
        getContentHandler in interface org.xml.sax.XMLReader
        Returns:
        a ContentHandler The current content handler, or null if none has been registered.
      • parse

        public void parse​(java.lang.String poSystemId)
                   throws java.io.IOException,
                          org.xml.sax.SAXException
        Full implementation of interface method.
        Specified by:
        parse in interface org.xml.sax.XMLReader
        Throws:
        java.io.IOException
        org.xml.sax.SAXException
      • getFeature

        public boolean getFeature​(java.lang.String poName)
                           throws org.xml.sax.SAXNotRecognizedException,
                                  org.xml.sax.SAXNotSupportedException
        Do-nothing implementation of interface method
        Specified by:
        getFeature in interface org.xml.sax.XMLReader
        Throws:
        org.xml.sax.SAXNotRecognizedException
        org.xml.sax.SAXNotSupportedException
      • setFeature

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

        public java.lang.Object getProperty​(java.lang.String name)
                                     throws org.xml.sax.SAXNotRecognizedException,
                                            org.xml.sax.SAXNotSupportedException
        Do-nothing implementation of interface method
        Specified by:
        getProperty in interface org.xml.sax.XMLReader
        Throws:
        org.xml.sax.SAXNotRecognizedException
        org.xml.sax.SAXNotSupportedException
      • setProperty

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

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

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

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

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

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

        public org.xml.sax.ErrorHandler getErrorHandler()
        Do-nothing implementation of interface method
        Specified by:
        getErrorHandler in interface org.xml.sax.XMLReader
      • startElement

        protected void startElement​(org.biojava.bio.program.sax.QName poQName,
                                    org.xml.sax.Attributes atts)
                             throws org.xml.sax.SAXException
        Utility method to centralize sending of a SAX startElement message to document handler
        Parameters:
        poQName - a QName value
        atts - an Attributes value
        Throws:
        org.xml.sax.SAXException - if an error occurs
      • endElement

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

        protected void characters​(char[] ch,
                                  int start,
                                  int length)
                           throws org.xml.sax.SAXException
        Utility method to centralize the sending of a SAX characters message a document handler.
        Parameters:
        ch - -
        start - -
        length - -
        Throws:
        org.xml.sax.SAXException - thrown if
        thrown - 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​(java.lang.String poPrefix,
                                     java.lang.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 java.lang.String getURIFromPrefix​(java.lang.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​(java.lang.String poPrefix)
        Parameters:
        poPrefix - a String value
      • getNamespacePrefix

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

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

        protected java.io.BufferedReader getContentStream​(org.xml.sax.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