bpp-phyl  2.2.0
SitePatterns.h
Go to the documentation of this file.
1 //
2 // File: SitePatterns.h
3 // Created by: Julien Dutheil
4 // Created on: Tue Nov 29 15:37 2005
5 // from file PatternTools.h
6 //
7 
8 /*
9 Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
10 
11 This software is a computer program whose purpose is to provide classes
12 for phylogenetic data analysis.
13 
14 This software is governed by the CeCILL license under French law and
15 abiding by the rules of distribution of free software. You can use,
16 modify and/ or redistribute the software under the terms of the CeCILL
17 license as circulated by CEA, CNRS and INRIA at the following URL
18 "http://www.cecill.info".
19 
20 As a counterpart to the access to the source code and rights to copy,
21 modify and redistribute granted by the license, users are provided only
22 with a limited warranty and the software's author, the holder of the
23 economic rights, and the successive licensors have only limited
24 liability.
25 
26 In this respect, the user's attention is drawn to the risks associated
27 with loading, using, modifying and/or developing or reproducing the
28 software by the user in light of its specific status of free software,
29 that may mean that it is complicated to manipulate, and that also
30 therefore means that it is reserved for developers and experienced
31 professionals having in-depth computer knowledge. Users are therefore
32 encouraged to load and test the software's suitability as regards their
33 requirements in conditions enabling the security of their systems and/or
34 data to be ensured and, more generally, to use and operate it in the
35 same conditions as regards security.
36 
37 The fact that you are presently reading this means that you have had
38 knowledge of the CeCILL license and that you accept its terms.
39 */
40 
41 #ifndef _SITEPATTERNS_H_
42 #define _SITEPATTERNS_H_
43 
44 #include "Tree.h"
45 
46 #include <Bpp/Clonable.h>
47 #include <Bpp/Numeric/VectorTools.h>
48 
49 //From bpp-seq:
50 #include <Bpp/Seq/Site.h>
51 #include <Bpp/Seq/Container/SiteContainer.h>
52 
53 // From the STL:
54 #include <map>
55 #include <vector>
56 #include <string>
57 
58 namespace bpp
59 {
60 
69 class SitePatterns :
70  public virtual Clonable
71 {
72  private:
77  {
78  public:
79  std::string siteS;
80  const Site* siteP;
82 
83  public:
87  {
88  siteS = ss.siteS;
89  siteP = ss.siteP;
91  return *this;
92  }
93 
94  bool operator<(const SortableSite& ss) const { return siteS < ss.siteS; }
95 
96  virtual ~SortableSite() {}
97  };
98 
100  // * @brief Class used for site pattern sorting.
101  // */
102  //struct SSComparator :
103  // std::binary_function<SortableSite, SortableSite, bool>
104  //{
105  // bool operator()(const SortableSite& ss1, const SortableSite& ss2) const { return ss1.siteS < ss2.siteS; }
106  //};
107 
108  private:
109  std::vector<std::string> names_;
110  std::vector<const Site *> sites_;
111  std::vector<unsigned int> weights_;
112  std::vector<size_t> indices_;
113  const SiteContainer* sequences_;
114  const Alphabet* alpha_;
115  bool own_;
116 
117  public:
127  SitePatterns(const SiteContainer* sequences, bool own = false);
128 
129  virtual ~SitePatterns()
130  {
131  if(own_) delete sequences_;
132  }
133 
134  SitePatterns(const SitePatterns& patterns) :
135  names_(patterns.names_),
136  sites_(patterns.sites_),
137  weights_(patterns.weights_),
138  indices_(patterns.indices_),
139  sequences_(0),
140  alpha_(patterns.alpha_),
141  own_(patterns.own_)
142  {
143  if(!patterns.own_) sequences_ = patterns.sequences_;
144  else sequences_ = dynamic_cast<SiteContainer*>(patterns.sequences_->clone());
145  }
146 
148  {
149  names_ = patterns.names_;
150  sites_ = patterns.sites_;
151  weights_ = patterns.weights_;
152  indices_ = patterns.indices_;
153  if(!patterns.own_) sequences_ = patterns.sequences_;
154  else sequences_ = dynamic_cast<SiteContainer*>(patterns.sequences_->clone());
155  alpha_ = patterns.alpha_;
156  own_ = patterns.own_;
157  return *this;
158  }
159 
160 #ifdef NO_VIRTUAL_COV
161  Clonable*
162 #else
163  SitePatterns *
164 #endif
165  clone() const { return new SitePatterns(*this); }
166 
167  public:
171  const std::vector<unsigned int>& getWeights() const { return weights_; }
175  const std::vector<size_t>& getIndices() const { return indices_; }
176 
180  SiteContainer* getSites() const;
181 
182 };
183 
184 } //end of namespace bpp.
185 
186 #endif // _SITEPATTERNS_H_
187 
const std::vector< size_t > & getIndices() const
Definition: SitePatterns.h:175
SitePatterns(const SiteContainer *sequences, bool own=false)
Build a new SitePattern object.
std::vector< const Site * > sites_
Definition: SitePatterns.h:110
virtual ~SitePatterns()
Definition: SitePatterns.h:129
std::vector< size_t > indices_
Definition: SitePatterns.h:112
SitePatterns(const SitePatterns &patterns)
Definition: SitePatterns.h:134
const std::vector< unsigned int > & getWeights() const
Definition: SitePatterns.h:171
const SiteContainer * sequences_
Definition: SitePatterns.h:113
std::vector< std::string > names_
Class used for site pattern sorting.
Definition: SitePatterns.h:109
std::vector< unsigned int > weights_
Definition: SitePatterns.h:111
Class used for site pattern sorting.
Definition: SitePatterns.h:76
SortableSite(const SortableSite &ss)
Definition: SitePatterns.h:85
SitePatterns * clone() const
Definition: SitePatterns.h:165
SortableSite & operator=(const SortableSite &ss)
Definition: SitePatterns.h:86
SiteContainer * getSites() const
bool operator<(const SortableSite &ss) const
Definition: SitePatterns.h:94
Data structure for site patterns.
Definition: SitePatterns.h:69
const Alphabet * alpha_
Definition: SitePatterns.h:114
SitePatterns & operator=(const SitePatterns &patterns)
Definition: SitePatterns.h:147