bpp-seq3  3.0.0
VectorProbabilisticSequenceContainer.cpp
Go to the documentation of this file.
1 //
2 // File: VectorProbabilisticSequenceContainer.cpp
3 // Authors:
4 // Guillaume Deuchst
5 // Julien Dutheil
6 // Last modified: 2003-07-30 00:00:00
7 //
8 
9 /*
10  Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
11 
12  This software is a computer program whose purpose is to provide classes
13  for sequences analysis.
14 
15  This software is governed by the CeCILL license under French law and
16  abiding by the rules of distribution of free software. You can use,
17  modify and/ or redistribute the software under the terms of the CeCILL
18  license as circulated by CEA, CNRS and INRIA at the following URL
19  "http://www.cecill.info".
20 
21  As a counterpart to the access to the source code and rights to copy,
22  modify and redistribute granted by the license, users are provided only
23  with a limited warranty and the software's author, the holder of the
24  economic rights, and the successive licensors have only limited
25  liability.
26 
27  In this respect, the user's attention is drawn to the risks associated
28  with loading, using, modifying and/or developing or reproducing the
29  software by the user in light of its specific status of free software,
30  that may mean that it is complicated to manipulate, and that also
31  therefore means that it is reserved for developers and experienced
32  professionals having in-depth computer knowledge. Users are therefore
33  encouraged to load and test the software's suitability as regards their
34  requirements in conditions enabling the security of their systems and/or
35  data to be ensured and, more generally, to use and operate it in the
36  same conditions as regards security.
37 
38  The fact that you are presently reading this means that you have had
39  knowledge of the CeCILL license and that you accept its terms.
40 */
41 
42 #include <Bpp/Text/TextTools.h>
43 
45 
46 using namespace bpp;
47 using namespace std;
48 
52  const std::vector<std::shared_ptr<ProbabilisticSequence>>& vs,
53  const Alphabet* alpha) :
56 {
57  for (auto i = vs.begin(); i < vs.end(); i++)
58  addSequence(*i);
59 }
60 
67 {
68  size_t max = vsc.getNumberOfSequences();
69  for (size_t i = 0; i < max; i++)
70  addSequence(vsc.getSequence(i), false);
71 
72 }
73 
78 {
79  clear();
82 
83  return *this;
84 }
85 
86 /******************************************************************************/
87 
89  const std::vector<std::string>& names,
90  bool checkNames)
91 {
92  if (names.size() != getNumberOfSequences())
93  throw IndexOutOfBoundsException("VectorProbabilisticSequenceContainer::setSequenceNames : bad number of names", names.size(), getNumberOfSequences(), getNumberOfSequences());
94  if (checkNames)
95  {
96  for (size_t i = 0; i < names.size(); i++)
97  {
98  // For all names in vector : throw exception if name already exists
99  for (size_t j = 0; j < i; j++)
100  {
101  if (names[j] == names[i])
102  throw Exception("VectorSiteContainer::setSequenceNames : Sequence's name already exists in container");
103  }
104  }
105  }
106  for (size_t i = 0; i < names.size(); i++)
107  {
108  getSequence_(i).setName(names[i]);
109  }
110 
111  setObjectNames(names);
112 }
113 
114 /******************************************************************************/
115 
117 {
120  return vsc;
121 }
122 
123 /******************************************************************************/
Partial implementation of the OrderedSequenceContainer interface.
void setGeneralComments(const Comments &comments)
Set the comments of this container.
const Alphabet * getAlphabet() const
Get container's alphabet.
AbstractValuesContainer & operator=(const AbstractValuesContainer &sc)
const Comments & getGeneralComments() const
Get the comments of this container.
The Alphabet interface.
Definition: Alphabet.h:133
virtual void setName(const std::string &name)=0
Set the name of this sequence.
The probabilistic sequence interface.
The template VectorMappedContainer class.
VectorMappedContainer< T > & operator=(const VectorMappedContainer &vsc)
void setObjectNames(const std::vector< std::string > &names)
The VectorProbabilisticSequenceContainer class.
VectorProbabilisticSequenceContainer * createEmptyContainer() const
Return a copy of this container, but with no data inside.
void clear()
Delete all objects in the container.
size_t getNumberOfSequences() const
Get the number of sequences in the container.
VectorProbabilisticSequenceContainer(const std::vector< std::shared_ptr< ProbabilisticSequence >> &vs, const Alphabet *alpha)
Build a container with shared Sequences.
virtual void addSequence(const ProbabilisticSequence &sequence, bool checkName=true)
Add a sequence at the end of the container.
const ProbabilisticSequence & getSequence(const std::string &name) const
void setSequenceNames(const std::vector< std::string > &names, bool checkNames=true)
Set all sequence names.
VectorProbabilisticSequenceContainer & operator=(const VectorProbabilisticSequenceContainer &vsc)
Assign from a VectorProbabilisticSequenceContainer.
This alphabet is used to deal NumericAlphabet.