|
bpp-phyl
2.1.0
|
00001 // 00002 // File: SitePatterns.h 00003 // Created by: Julien Dutheil 00004 // Created on: Tue Nov 29 15:37 2005 00005 // from file PatternTools.h 00006 // 00007 00008 /* 00009 Copyright or © or Copr. Bio++ Development Team, (November 16, 2004) 00010 00011 This software is a computer program whose purpose is to provide classes 00012 for phylogenetic data analysis. 00013 00014 This software is governed by the CeCILL license under French law and 00015 abiding by the rules of distribution of free software. You can use, 00016 modify and/ or redistribute the software under the terms of the CeCILL 00017 license as circulated by CEA, CNRS and INRIA at the following URL 00018 "http://www.cecill.info". 00019 00020 As a counterpart to the access to the source code and rights to copy, 00021 modify and redistribute granted by the license, users are provided only 00022 with a limited warranty and the software's author, the holder of the 00023 economic rights, and the successive licensors have only limited 00024 liability. 00025 00026 In this respect, the user's attention is drawn to the risks associated 00027 with loading, using, modifying and/or developing or reproducing the 00028 software by the user in light of its specific status of free software, 00029 that may mean that it is complicated to manipulate, and that also 00030 therefore means that it is reserved for developers and experienced 00031 professionals having in-depth computer knowledge. Users are therefore 00032 encouraged to load and test the software's suitability as regards their 00033 requirements in conditions enabling the security of their systems and/or 00034 data to be ensured and, more generally, to use and operate it in the 00035 same conditions as regards security. 00036 00037 The fact that you are presently reading this means that you have had 00038 knowledge of the CeCILL license and that you accept its terms. 00039 */ 00040 00041 #ifndef _SITEPATTERNS_H_ 00042 #define _SITEPATTERNS_H_ 00043 00044 #include "Tree.h" 00045 00046 #include <Bpp/Clonable.h> 00047 #include <Bpp/Numeric/VectorTools.h> 00048 00049 //From bpp-seq: 00050 #include <Bpp/Seq/Site.h> 00051 #include <Bpp/Seq/Container/SiteContainer.h> 00052 00053 // From the STL: 00054 #include <map> 00055 #include <vector> 00056 #include <string> 00057 00058 namespace bpp 00059 { 00060 00069 class SitePatterns : 00070 public virtual Clonable 00071 { 00072 private: 00076 class SortableSite 00077 { 00078 public: 00079 std::string siteS; 00080 const Site* siteP; 00081 size_t originalPosition; 00082 00083 public: 00084 SortableSite() : siteS(), siteP(0), originalPosition(0) {} 00085 SortableSite(const SortableSite& ss) : siteS(ss.siteS), siteP(ss.siteP), originalPosition(ss.originalPosition) {} 00086 SortableSite& operator=(const SortableSite& ss) 00087 { 00088 siteS = ss.siteS; 00089 siteP = ss.siteP; 00090 originalPosition = ss.originalPosition; 00091 return *this; 00092 } 00093 00094 bool operator<(const SortableSite& ss) const { return siteS < ss.siteS; } 00095 00096 virtual ~SortableSite() {} 00097 }; 00098 00100 // * @brief Class used for site pattern sorting. 00101 // */ 00102 //struct SSComparator : 00103 // std::binary_function<SortableSite, SortableSite, bool> 00104 //{ 00105 // bool operator()(const SortableSite& ss1, const SortableSite& ss2) const { return ss1.siteS < ss2.siteS; } 00106 //}; 00107 00108 private: 00109 std::vector<std::string> names_; 00110 std::vector<const Site *> sites_; 00111 std::vector<unsigned int> weights_; 00112 std::vector<size_t> indices_; 00113 const SiteContainer* sequences_; 00114 const Alphabet* alpha_; 00115 bool own_; 00116 00117 public: 00127 SitePatterns(const SiteContainer* sequences, bool own = false); 00128 00129 virtual ~SitePatterns() 00130 { 00131 if(own_) delete sequences_; 00132 } 00133 00134 SitePatterns(const SitePatterns& patterns) : 00135 names_(patterns.names_), 00136 sites_(patterns.sites_), 00137 weights_(patterns.weights_), 00138 indices_(patterns.indices_), 00139 sequences_(0), 00140 alpha_(patterns.alpha_), 00141 own_(patterns.own_) 00142 { 00143 if(!patterns.own_) sequences_ = patterns.sequences_; 00144 else sequences_ = dynamic_cast<SiteContainer*>(patterns.sequences_->clone()); 00145 } 00146 00147 SitePatterns& operator=(const SitePatterns& patterns) 00148 { 00149 names_ = patterns.names_; 00150 sites_ = patterns.sites_; 00151 weights_ = patterns.weights_; 00152 indices_ = patterns.indices_; 00153 if(!patterns.own_) sequences_ = patterns.sequences_; 00154 else sequences_ = dynamic_cast<SiteContainer*>(patterns.sequences_->clone()); 00155 alpha_ = patterns.alpha_; 00156 own_ = patterns.own_; 00157 return *this; 00158 } 00159 00160 #ifdef NO_VIRTUAL_COV 00161 Clonable* 00162 #else 00163 SitePatterns * 00164 #endif 00165 clone() const { return new SitePatterns(*this); } 00166 00167 public: 00171 const std::vector<unsigned int>& getWeights() const { return weights_; } 00175 const std::vector<size_t>& getIndices() const { return indices_; } 00176 00180 SiteContainer* getSites() const; 00181 00182 }; 00183 00184 } //end of namespace bpp. 00185 00186 #endif // _SITEPATTERNS_H_ 00187