Class BlastLikeToXMLConverter


  • public class BlastLikeToXMLConverter
    extends Object

    A class that converts the raw output from a variety of bioinformatics software and converts it to XML that will validate against the biojava:BlastLikeDataSetCollection DTD.

    For applications supported, please the documentation for the BlastLikeSAXParser.

    Examination of the source code of this application also serves as demonstration of the simplicity of using the biojava blast-like SAX2 parsing framework. The main functionality of the application is simply built from the following code, viz.:

    
          !**
           * The following code creates a parser for native output
           * from BlastLike programs. That is,
           * Create a SAX2 Parser that takes the native output
           * from blast-like bioinformatics software.
           *!
           
            XMLReader oParser =
           (XMLReader) new BlastLikeSAXParser();
           
         !**
           * Namespace support controls the way in which
           * XML elements are reported. In XML, when an element
           * looks something like  then,
           * the part before the colon, i.e. biojava is the namespace,
           * and the part after the colon i.e. Hit is the Local name.
           * The full "biojava:Hit" name is termed the Qualified Name (QNames).
           * By default SAX2 parsers report Local Names, in this
           * example, we decided we wanted to make the parser report QNames.
           *
           * If you don't want to change default namespace support, you
           * can ignore the next piece of code.
           *
           * Dynamically change configuration of the parser
           * in regard of Namespace support. Here,
           * the xml.org/features/namespaces feature is simply "reset"
           * to its default value for SAX2.
           * The xml.org/features/namespaces-prefixes feature is
           * also set to true.  This is to ensure that xmlns attributes
           * are reported by the parser. These are required because we want
           * to configure the XMLEmitter to output qualified names (see below).
           *!
          
          try {
          oParser.setFeature("http://xml.org/sax/features/namespaces",true);
          oParser.setFeature(
                  "http://xml.org/sax/features/namespace-prefixes",true);
    
          } catch (Exception e) {
          }
          
    
          !**
           * Having selected the parser, we now want to
           * choose an object to deal with the SAX2 events
           * that the parser produces. This is the class
           * that you would normally write yourself to deal
           * with particular events you are interested in.
           * This class implements the ContentHandler - usually,
           * you would inherit from a SAX2 helper class that
           * implements this interface for you.
           *
           * Create an XML ContentHandler. This
           * implementation of the DocumentHandler
           * interface simply outputs nicely formatted
           * XML. Passing a true value to the SimpleXMLEmitter
           * constructor instructs the ContentHandler
           * to take QNames from the SAXParser, rather
           * than LocalNames.
           *
          
          ContentHandler oHandler  = 
          (ContentHandler) new SimpleXMLEmitter(true);
          
    
          !**
           * Now, link the Parser and the ContentHandler.
           *
           * Give the parser a reference to the ContentHandler
           * so that it can send SAX2 mesagges.
           *!
          
          oParser.setContentHandler(oHandler);
          
          !**
           * Finally, parse your Blast-like output.
           *
           * Now make the Parser parse the output from the
           * blast-like software and emit XML as specificed
           * by the ContentHandler.
           *!
          
          oParser.parse(oInput);  
          
     

    Copyright © 2000 Cambridge Antibody Technology.

    Primary author -

    • Simon Brocklehurst (CAT)
    Other authors -
    • Tim Dilks (CAT)
    • Colin Hardman (CAT)
    • Stuart Johnston (CAT)
    • Mathieu Wiepert (Mayo Foundation)
    Version:
    1.0
    Author:
    Cambridge Antibody Technology (CAT)
    See Also:
    BlastLikeSAXParser, SimpleXMLEmitter