00001 ///////////////////////////////////////////////////////////////////////////// 00002 // File: gnFragmentSpec.h 00003 // Purpose: abstract Spec class 00004 // Description: Genome level spec class 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 _gnFragmentSpec_h_ 00013 #define _gnFragmentSpec_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/gnContigSpec.h" 00024 #include "gn/gnMultiSpec.h" 00025 #include "gn/gnException.h" 00026 00027 /** 00028 * gnFragmentSpec contains a list of specs which make up a sequence 00029 * fragment. It also contains a list of features which relate to 00030 * the sequence fragment. Finally it contains a list of sequence 00031 * related header data. This class is usually created and filled by 00032 * a file reader class like gnGBKSource. 00033 */ 00034 class GNDLLEXPORT gnFragmentSpec : public gnMultiSpec 00035 { 00036 public: 00037 gnFragmentSpec(); 00038 /** 00039 * Destructor, frees memory. 00040 */ 00041 virtual ~gnFragmentSpec(); 00042 /** 00043 * Copy constructor. 00044 * @param s the gnGenomeSpec to copy. 00045 */ 00046 gnFragmentSpec( const gnFragmentSpec& s); 00047 virtual gnFragmentSpec* Clone() const; 00048 virtual void Clear(); 00049 // Base Spec stuff 00050 virtual void SetReverseComplement( const boolean value ); 00051 00052 //Multispec stuff 00053 virtual uint32 GetSpecListLength() const; 00054 virtual gnContigSpec* GetSpec( const uint32 i ) const; 00055 virtual gnContigSpec* GetSpecByBase( const gnSeqI baseI ) const; 00056 virtual void AddSpec( gnBaseSpec* spec, const uint32 i = UINT32_MAX ); 00057 virtual void RemoveSpec( uint32 i ); 00058 00059 virtual void CropStart( gnSeqI cropLen ); 00060 virtual void CropEnd( gnSeqI cropLen ); 00061 virtual uint32 AddFeature( gnBaseFeature* feat ); 00062 virtual uint32 GetFeatureListLength() const; 00063 virtual gnBaseFeature* GetFeature( const uint32 i ) const; 00064 virtual void GetContainedFeatures(const gnLocation& lt, vector<gnBaseFeature*>& feature_vector, vector<uint32>& index_vector) const; 00065 virtual void GetIntersectingFeatures(const gnLocation& lt, vector<gnBaseFeature*>& feature_vector, vector<uint32>& index_vector) const; 00066 virtual void GetBrokenFeatures(const gnLocation& lt, vector<gnBaseFeature*>& feature_vector) const; 00067 virtual void RemoveFeature( const uint32 i ); 00068 00069 /** 00070 * Copies a specified range of bases and returns a pointer to 00071 * the resulting gnFragmentSpec. You must delete the copy when you 00072 * are finished with it. 00073 * @param startI The first base pair to copy 00074 * @param len The length of the piece to copy 00075 * @return A copy of the gnFragmentSpec containing only the specified bases 00076 */ 00077 virtual gnFragmentSpec* CloneRange( const gnSeqI startI, const gnSeqI len ) const; 00078 00079 protected: 00080 vector <gnContigSpec*> m_SpecList; 00081 //Feature stuff... 00082 vector <gnBaseFeature*> m_featureList; 00083 00084 }; // class gnFragmentSpec 00085 00086 inline 00087 gnFragmentSpec* gnFragmentSpec::Clone() const{ 00088 return new gnFragmentSpec(*this); 00089 } 00090 00091 inline 00092 uint32 gnFragmentSpec::GetSpecListLength() const{ 00093 return m_SpecList.size(); 00094 } 00095 00096 inline 00097 gnContigSpec *gnFragmentSpec::GetSpec( const uint32 i ) const{ 00098 if(i < m_SpecList.size()) 00099 return m_SpecList[i]; 00100 Throw_gnEx(ContigIndexOutOfBounds()); 00101 } 00102 00103 inline 00104 gnContigSpec* gnFragmentSpec::GetSpecByBase( const gnSeqI baseI ) const{ 00105 return m_SpecList[GetSpecIndexByBase(baseI)]; 00106 } 00107 00108 inline 00109 void gnFragmentSpec::AddSpec( gnBaseSpec* spec, const uint32 i ){ 00110 uint32 index = i == UINT32_MAX ? m_SpecList.size() : i; 00111 if(index <= m_SpecList.size()){ 00112 m_SpecList.insert(m_SpecList.begin() + index, (gnContigSpec*)spec); 00113 } 00114 } 00115 00116 inline 00117 void gnFragmentSpec::RemoveSpec( uint32 i ){ 00118 if(i < GetSpecListLength()){ 00119 m_SpecList.erase(m_SpecList.begin() + i); 00120 }else 00121 Throw_gnEx(ContigIndexOutOfBounds()); 00122 } 00123 00124 inline 00125 uint32 gnFragmentSpec::AddFeature( gnBaseFeature* feat ) 00126 { 00127 m_featureList.push_back(feat); 00128 feat->SetSpec(this); 00129 return m_featureList.size()-1; 00130 } 00131 inline 00132 uint32 gnFragmentSpec::GetFeatureListLength() const 00133 { 00134 return m_featureList.size(); 00135 } 00136 inline 00137 gnBaseFeature* gnFragmentSpec::GetFeature(const uint32 i) const 00138 { 00139 return m_featureList[i]->Clone(); 00140 } 00141 inline 00142 void gnFragmentSpec::RemoveFeature( const uint32 i) 00143 { 00144 if(i >= m_featureList.size()) 00145 Throw_gnEx(FeatureIndexOutOfBounds()); 00146 delete m_featureList[i]; 00147 m_featureList.erase(m_featureList.begin() + i); 00148 } 00149 00150 #endif 00151 // _gnFragmentSpec_h_