Sleipnir
tools/OntoShell/parser.h
00001 /*****************************************************************************
00002 * This file is provided under the Creative Commons Attribution 3.0 license.
00003 *
00004 * You are free to share, copy, distribute, transmit, or adapt this work
00005 * PROVIDED THAT you attribute the work to the authors listed below.
00006 * For more information, please see the following web page:
00007 * http://creativecommons.org/licenses/by/3.0/
00008 *
00009 * This file is a component of the Sleipnir library for functional genomics,
00010 * authored by:
00011 * Curtis Huttenhower (chuttenh@princeton.edu)
00012 * Mark Schroeder
00013 * Maria D. Chikina
00014 * Olga G. Troyanskaya (ogt@princeton.edu, primary contact)
00015 *
00016 * If you use this library, the included executable tools, or any related
00017 * code in your work, please cite the following publication:
00018 * Curtis Huttenhower, Mark Schroeder, Maria D. Chikina, and
00019 * Olga G. Troyanskaya.
00020 * "The Sleipnir library for computational functional genomics"
00021 *****************************************************************************/
00022 #ifndef PARSER_H
00023 #define PARSER_H
00024 
00025 class CParser {
00026 public:
00027     static const char   c_cSep  = '/';
00028     static const char   c_szDot[];
00029     static const char   c_szDotDot[];
00030     static const char*  c_aszParsers[];
00031 
00032     struct SLocation {
00033         static const char   c_szRoot[];
00034 
00035         const IOntology*    m_pOnto;
00036         size_t              m_iNode;
00037 
00038         SLocation( );
00039 
00040         bool operator==( const SLocation& ) const;
00041 
00042         string ToString( bool ) const;
00043         bool IsValid( ) const;
00044         void Invalidate( );
00045     };
00046 
00047     static const char* GetCommand( size_t );
00048 
00049     CParser( const Sleipnir::IOntology**, const Sleipnir::CGenome& );
00050 
00051     size_t GetOntologies( ) const;
00052     const IOntology* GetOntology( size_t ) const;
00053     const CGenome& GetGenome( ) const;
00054 
00055 protected:
00056     typedef set<const CGene*>   TSetPGenes;
00057 
00058     static bool SplitLocation( const string&, std::vector<string>& );
00059     static bool IsRooted( const string& );
00060     static SLocation GetLocation( const std::vector<const Sleipnir::IOntology*>&, const string& = c_szDot,
00061         bool = true, const SLocation* = NULL );
00062     static bool MoveLocation( SLocation&, const string&, const std::vector<const Sleipnir::IOntology*>& );
00063     static void CollectGenes( const std::vector<SLocation>&, TSetPGenes& );
00064 
00065     bool Recurse( SLocation, bool, bool, std::vector<SLocation>& ) const;
00066     void TermFinder( const Sleipnir::CGenes&, float, const Sleipnir::CGenes&, bool, bool, bool,
00067         std::vector<size_t>&, std::vector<Sleipnir::STermFound>& ) const;
00068 
00069     const CGenome&              m_Genome;
00070     vector<const IOntology*>    m_vecpOntologies;
00071 };
00072 
00073 #endif // PARSER_H