Sleipnir
|
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 COALESCEBASEI_H 00023 #define COALESCEBASEI_H 00024 00025 #include <map> 00026 #include <string> 00027 #include <vector> 00028 00029 namespace Sleipnir { 00030 00031 class CCoalesceSequencerBase { 00032 public: 00033 enum ESubsequence { 00034 ESubsequenceBegin = 0, 00035 ESubsequenceTotal = ESubsequenceBegin, 00036 ESubsequenceIntrons = ESubsequenceTotal + 1, 00037 ESubsequenceExons = ESubsequenceIntrons + 1, 00038 ESubsequenceEnd = ESubsequenceExons + 1 00039 }; 00040 00041 static const char* c_aszSubsequences[]; 00042 00043 static const char* GetSubsequence( ESubsequence eSubsequence ) { 00044 00045 return c_aszSubsequences[ eSubsequence ]; } 00046 00047 static ESubsequence GetSubsequence( const std::string& strSubsequence ) { 00048 size_t i; 00049 00050 for( i = 0; c_aszSubsequences[ i ]; ++i ) 00051 if( strSubsequence == c_aszSubsequences[ i ] ) 00052 return (ESubsequence)i; 00053 00054 return ESubsequenceEnd; } 00055 00056 size_t GetTypes( ) const { 00057 00058 return m_vecstrTypes.size( ); } 00059 00060 const std::string& GetType( size_t iType ) const { 00061 00062 return m_vecstrTypes[ iType ]; } 00063 00064 size_t GetType( const std::string& strType ) const { 00065 TMapStrI::const_iterator iterType; 00066 00067 return ( ( ( iterType = m_mapstriTypes.find( strType ) ) == m_mapstriTypes.end( ) ) ? -1 : 00068 iterType->second ); } 00069 00070 protected: 00071 typedef std::map<std::string, size_t> TMapStrI; 00072 00073 TMapStrI m_mapstriTypes; 00074 std::vector<std::string> m_vecstrTypes; 00075 }; 00076 00077 template<class tType> 00078 class CCoalesceSequencer : public CCoalesceSequencerBase { 00079 public: 00080 tType& Get( size_t iType, ESubsequence eSubsequence ) { 00081 00082 return m_vecvecValues[ iType ][ eSubsequence ]; } 00083 00084 const tType& Get( size_t iType, ESubsequence eSubsequence ) const { 00085 00086 return m_vecvecValues[ iType ][ eSubsequence ]; } 00087 00088 const tType& Get( const std::string& strType, ESubsequence eSubsequence ) const { 00089 00090 return Get( GetType( strType ), eSubsequence ); } 00091 00092 size_t AddType( const std::string& strType ) { 00093 TMapStrI::const_iterator iterType; 00094 size_t iRet; 00095 00096 if( ( iterType = m_mapstriTypes.find( strType ) ) != m_mapstriTypes.end( ) ) 00097 return iterType->second; 00098 00099 m_mapstriTypes[ strType ] = iRet = m_vecvecValues.size( ); 00100 m_vecstrTypes.push_back( strType ); 00101 m_vecvecValues.push_back( std::vector<tType>( ) ); 00102 m_vecvecValues.back( ).resize( ESubsequenceEnd ); 00103 00104 return iRet; } 00105 00106 size_t GetSubsequences( size_t iType ) const { 00107 00108 return m_vecvecValues[ iType ].size( ); } 00109 00110 void Clear( ) { 00111 size_t i, j; 00112 00113 for( i = 0; i < m_vecvecValues.size( ); ++i ) 00114 for( j = 0; j < m_vecvecValues[ i ].size( ); ++j ) 00115 m_vecvecValues[ i ][ j ].Clear( ); } 00116 00117 protected: 00118 // Type by subsequence 00119 std::vector<std::vector<tType> > m_vecvecValues; 00120 }; 00121 00122 } 00123 00124 #endif // COALESCEBASEI_H