00001 ///////////////////////////////////////////////////////////////////////////// 00002 // File: gnMultiSpec.h 00003 // Purpose: abstract multiple spec class 00004 // Description: For specs which can contain multiple data sources 00005 // Changes: 00006 // Version: libGenome 0.5.1 00007 // Author: Aaron Darling 00008 // Modified by: 00009 // Copyright: (c) Aaron Darling 00010 // Licenses: See COPYING file for details 00011 ///////////////////////////////////////////////////////////////////////////// 00012 #ifndef _gnMultiSpec_h_ 00013 #define _gnMultiSpec_h_ 00014 00015 #include "gn/gnDefs.h" 00016 00017 #include <vector> 00018 #include <string> 00019 00020 #include "gn/gnClone.h" 00021 #include "gn/gnBaseFeature.h" 00022 #include "gn/gnBaseHeader.h" 00023 #include "gn/gnBaseSpec.h" 00024 00025 /** 00026 * This class defines an interface for specs which have multiple subspecs 00027 * containing sequence data. 00028 */ 00029 class GNDLLEXPORT gnMultiSpec : public gnBaseSpec 00030 { 00031 public: 00032 gnMultiSpec(){} 00033 /** 00034 * Destructor, frees memory. 00035 */ 00036 virtual ~gnMultiSpec(){} 00037 virtual gnMultiSpec* Clone() const = 0; 00038 00039 // Base Spec stuff 00040 virtual gnSeqI GetLength() const; 00041 virtual void CropStart( gnSeqI cropLen ); 00042 virtual void CropEnd( gnSeqI cropLen ); 00043 00044 virtual string GetSourceName() const; 00045 virtual void SetSourceName(const string& sourceName); 00046 virtual void Clear(); 00047 00048 virtual boolean SeqRead(const gnSeqI start, gnSeqC* buf, uint32& bufLen, const uint32 contigI ) const; 00049 00050 //Multispec stuff 00051 /** 00052 * Returns the number of subspecs this spec contains. 00053 * @return The number of subspecs this spec contains. 00054 */ 00055 virtual uint32 GetSpecListLength() const = 0; 00056 /** 00057 * Get the spec at index i in the list of subspecs. 00058 * @param i The index of the spec 00059 * @return The spec. 00060 */ 00061 virtual gnBaseSpec* GetSpec( const uint32 i ) const = 0; 00062 /** 00063 * Get the spec from the list of subspecs which contains the specified base pair. 00064 * @param baseI The base pair index. 00065 * @return The spec. 00066 */ 00067 virtual gnBaseSpec* GetSpecByBase( const gnSeqI baseI ) const = 0; 00068 /** 00069 * Get the index of the subspec which contains the specified base pair. 00070 * @param baseI The base pair index. 00071 * @return The subspec index. 00072 */ 00073 virtual uint32 GetSpecIndexByBase( const gnSeqI baseI ) const; 00074 /** 00075 * Get the index of the spec which has the given name. 00076 * @param name The name of the spec to find. 00077 * @return The spec index. 00078 */ 00079 virtual uint32 GetSpecIndexByName( const string& name ) const; 00080 /** 00081 * Get the starting base pair, in this spec's sequence, of the given subspec. 00082 * @param specI The subspec index. 00083 * @return The subspec's starting base pair. 00084 */ 00085 virtual gnSeqI GetSpecStartBase( const uint32 specI ) const; 00086 /** 00087 * Get the ending base pair, in this spec's sequence, of the given subspec. 00088 * @param specI The subspec index. 00089 * @return The subspec's ending base pair. 00090 */ 00091 virtual gnSeqI GetSpecEndBase( const uint32 specI ) const; 00092 /** 00093 * Add a subspec to this spec. 00094 * Throws an exception if the insertion index i is out of range 00095 * @param spec The subspec to add. 00096 * @param i The subspec to insert before 00097 * @return True if successful 00098 */ 00099 virtual void AddSpec( gnBaseSpec* spec, const uint32 i = UINT32_MAX ) = 0; 00100 /** 00101 * Remove a subspec from this spec. 00102 * @param i The index of the subspec to remove. 00103 */ 00104 virtual void RemoveSpec( uint32 i ) = 0; 00105 00106 /** 00107 * Returns the number of headers this spec contains. 00108 * @return The number of headers this spec contains. 00109 */ 00110 virtual uint32 GetHeaderListLength() const; 00111 /** 00112 * Add a header to this spec, adds to the end of the header list by default. 00113 * @param head The header to add. 00114 * @param i The header to insert before. If i is larger than the size of the header list 00115 * the header will be added to the end of the list. 00116 */ 00117 virtual void AddHeader( gnBaseHeader *head, const uint32 i = UINT32_MAX); 00118 /** 00119 * Get the headers at index i in the list of headers. 00120 * Throws a HeaderIndexOutOfBounds exception if a nonexistant header is referenced 00121 * @param i The index of the header 00122 * @return The header. 00123 */ 00124 virtual gnBaseHeader* GetHeader( const uint32 i ) const; 00125 /** 00126 * Find the first header with the specified name, starting at index i. 00127 * @param name The name of the header to find. 00128 * @param i The index to start looking at. 00129 * @return The header or NULL if none was found. 00130 */ 00131 virtual gnBaseHeader* GetHeader( const string& name, uint32& i) const; 00132 /** 00133 * Remove a header from this spec. 00134 * Throws a HeaderIndexOutOfBounds exception if a nonexistant header is referenced 00135 * @param i The index of the header to remove. 00136 */ 00137 virtual void RemoveHeader( uint32 i ); 00138 00139 /** 00140 * Add a feature to this spec. 00141 * @param feat The feature to add. 00142 * @return True if successful 00143 */ 00144 uint32 AddFeature( gnBaseFeature* feat ); 00145 /** 00146 * Returns the number of features this spec contains. 00147 * @return The number of features this spec contains. 00148 */ 00149 virtual uint32 GetFeatureListLength() const = 0; 00150 /** 00151 * Get the feature at index i in the list of features. 00152 * @param i The index of the feature 00153 * @return The feature. 00154 */ 00155 virtual gnBaseFeature* GetFeature( const uint32 i ) const = 0; 00156 /** 00157 * Creates a list of all features which are contained by coordinates specified. 00158 * @param lt The coordinates containing the features to return. 00159 * @param feature_vector The vector to store features in. 00160 * @param index_vector A vector of indices which correspond to the features. 00161 */ 00162 virtual void GetContainedFeatures(const gnLocation& lt, vector<gnBaseFeature*>& feature_vector, vector<uint32>& index_vector) const = 0; 00163 /** 00164 * Creates a list of all features which intersect the coordinates specified. 00165 * @param lt The coordinates intersecting the features to return. 00166 * @param feature_vector The vector to store features in. 00167 * @param index_vector A vector of indices which correspond to the features. 00168 */ 00169 virtual void GetIntersectingFeatures(const gnLocation& lt, vector<gnBaseFeature*>& feature_vector, vector<uint32>& index_vector) const = 0; 00170 /** 00171 * Creates a list of features which may have been broken by an edit. 00172 * @param lt The coordinates containing the features to return. 00173 * @param feature_vector The vector to store features in. 00174 */ 00175 virtual void GetBrokenFeatures(const gnLocation& lt, vector<gnBaseFeature*>& feature_vector) const = 0; 00176 /** 00177 * Remove a feature from this spec. 00178 * @param i The index of the feature to remove. 00179 * @return True if successful 00180 */ 00181 virtual void RemoveFeature( const uint32 i ) = 0; 00182 00183 protected: 00184 string m_sourceName; 00185 00186 vector <gnBaseHeader*> m_headerList; 00187 private: 00188 00189 }; // class gnMultiSpec 00190 00191 inline 00192 uint32 gnMultiSpec::GetHeaderListLength() const 00193 { 00194 return m_headerList.size(); 00195 } 00196 inline 00197 gnBaseHeader* gnMultiSpec::GetHeader(const uint32 i) const 00198 { 00199 if(i < m_headerList.size()){ 00200 return m_headerList[i]; 00201 } 00202 return 0; 00203 } 00204 00205 inline 00206 string gnMultiSpec::GetSourceName() const{ 00207 return m_sourceName; 00208 } 00209 00210 inline 00211 void gnMultiSpec::SetSourceName(const string& sourceName){ 00212 m_sourceName = sourceName; 00213 } 00214 00215 #endif 00216 // _gnMultiSpec_h_