~ubuntu-branches/ubuntu/saucy/libbpp-seq/saucy-proposed

« back to all changes in this revision

Viewing changes to src/Bpp/Seq/Container/VectorSequenceContainer.cpp

  • Committer: Package Import Robot
  • Author(s): Julien Dutheil
  • Date: 2013-03-05 14:31:00 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130305143100-2jox395vr1ghao46
Tags: 2.1.0-1
* 'omics' tools now in bpp-seq-omics
* Extended BppO support
* StateProperties renamed to AlphabetIndex

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
//
7
7
 
8
8
/*
9
 
Copyright or © or Copr. CNRS, (November 17, 2004)
10
 
 
11
 
This software is a computer program whose purpose is to provide classes
12
 
for sequences 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
 
*/
 
9
   Copyright or © or Copr. CNRS, (November 17, 2004)
 
10
 
 
11
   This software is a computer program whose purpose is to provide classes
 
12
   for sequences 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
40
 
41
41
#include "VectorSequenceContainer.h"
42
42
#include <Bpp/Text/TextTools.h>
47
47
/** Class constructors: *******************************************************/
48
48
 
49
49
VectorSequenceContainer::VectorSequenceContainer(
50
 
        const std::vector<const Sequence*>& vs,
51
 
        const Alphabet* alpha)
52
 
        throw (AlphabetMismatchException):
53
 
        AbstractSequenceContainer(alpha),
 
50
  const std::vector<const Sequence*>& vs,
 
51
  const Alphabet* alpha)
 
52
throw (AlphabetMismatchException) :
 
53
  AbstractSequenceContainer(alpha),
54
54
  sequences_()
55
55
{
56
 
        for (std::vector<const Sequence *>::const_iterator i = vs.begin() ; i < vs.end() ; i++)
 
56
  for (std::vector<const Sequence*>::const_iterator i = vs.begin(); i < vs.end(); i++)
57
57
  {
58
 
                addSequence(**i);
59
 
        }
 
58
    addSequence(**i);
 
59
  }
60
60
}
61
61
 
62
62
/** Copy constructors: ********************************************************/
63
 
        
 
63
 
64
64
VectorSequenceContainer::VectorSequenceContainer(
65
 
        const VectorSequenceContainer& vsc):
66
 
        AbstractSequenceContainer(vsc),
 
65
  const VectorSequenceContainer& vsc) :
 
66
  AbstractSequenceContainer(vsc),
67
67
  sequences_()
68
68
{
69
 
        unsigned int max = vsc.getNumberOfSequences();
70
 
        for (unsigned int i = 0 ; i < max ; i++)
 
69
  size_t max = vsc.getNumberOfSequences();
 
70
  for (size_t i = 0; i < max; i++)
 
71
  {
71
72
    addSequence(vsc.getSequence(i), false);
 
73
  }
72
74
}
73
75
 
74
76
VectorSequenceContainer::VectorSequenceContainer(
75
 
        const OrderedSequenceContainer& osc):
76
 
        AbstractSequenceContainer(osc.getAlphabet()),
 
77
  const OrderedSequenceContainer& osc) :
 
78
  AbstractSequenceContainer(osc.getAlphabet()),
77
79
  sequences_()
78
80
{
79
 
        // Sequences insertion
80
 
        for (unsigned int i = 0; i < osc.getNumberOfSequences(); i++)
 
81
  // Sequences insertion
 
82
  for (unsigned int i = 0; i < osc.getNumberOfSequences(); i++)
 
83
  {
81
84
    addSequence(osc.getSequence(i), false);
 
85
  }
82
86
}
83
87
 
84
88
VectorSequenceContainer::VectorSequenceContainer(
85
 
        const SequenceContainer& sc):
86
 
        AbstractSequenceContainer(sc.getAlphabet()),
 
89
  const SequenceContainer& sc) :
 
90
  AbstractSequenceContainer(sc.getAlphabet()),
87
91
  sequences_()
88
92
{
89
 
        // Sequences insertion
90
 
  std::vector<std::string> names = sc.getSequencesNames();  
 
93
  // Sequences insertion
 
94
  std::vector<std::string> names = sc.getSequencesNames();
91
95
  for (unsigned int i = 0; i < names.size(); i++)
92
96
  {
93
97
    addSequence(sc.getSequence(names[i]), false);
94
98
  }
95
99
 
96
 
        setGeneralComments(sc.getGeneralComments());
 
100
  setGeneralComments(sc.getGeneralComments());
97
101
}
98
102
 
99
103
/** Assignation operator: *****************************************************/
100
104
 
101
105
VectorSequenceContainer& VectorSequenceContainer::operator=(
102
 
        const VectorSequenceContainer& vsc)
 
106
  const VectorSequenceContainer& vsc)
103
107
{
104
108
  clear();
105
109
  AbstractSequenceContainer::operator=(vsc);
106
110
 
107
 
        // Sequences insertion
108
 
        unsigned int max = vsc.getNumberOfSequences();
109
 
        for (unsigned int i = 0 ; i < max ; i++)
 
111
  // Sequences insertion
 
112
  size_t max = vsc.getNumberOfSequences();
 
113
  for (size_t i = 0; i < max; i++)
 
114
  {
110
115
    addSequence(vsc.getSequence(i), false);
 
116
  }
111
117
 
112
 
        return *this;
 
118
  return *this;
113
119
}
114
120
 
115
121
VectorSequenceContainer& VectorSequenceContainer::operator=(
116
 
        const OrderedSequenceContainer& osc)
 
122
  const OrderedSequenceContainer& osc)
117
123
{
118
124
  clear();
119
125
  AbstractSequenceContainer::operator=(osc);
120
126
 
121
 
        // Sequences insertion
122
 
        unsigned int max = osc.getNumberOfSequences();
123
 
        for (unsigned int i = 0 ; i < max ; i++)
 
127
  // Sequences insertion
 
128
  size_t max = osc.getNumberOfSequences();
 
129
  for (unsigned int i = 0; i < max; i++)
 
130
  {
124
131
    addSequence(osc.getSequence(i), false);
125
 
    
126
 
        return *this;
 
132
  }
 
133
 
 
134
  return *this;
127
135
}
128
136
 
129
137
/******************************************************************************/
133
141
{
134
142
  clear();
135
143
  AbstractSequenceContainer::operator=(sc);
136
 
  
137
 
  //Seq names:
 
144
 
 
145
  // Seq names:
138
146
  std::vector<std::string> names = sc.getSequencesNames();
139
 
  
 
147
 
140
148
  for (unsigned int i = 0; i < names.size(); i++)
141
149
  {
142
150
    addSequence(sc.getSequence(names[i]), false);
147
155
 
148
156
/******************************************************************************/
149
157
 
150
 
const Sequence& VectorSequenceContainer::getSequence(unsigned int sequenceIndex) const throw (IndexOutOfBoundsException)
 
158
const Sequence& VectorSequenceContainer::getSequence(size_t sequenceIndex) const throw (IndexOutOfBoundsException)
151
159
{
152
 
        // Specified sequence existence verification
153
 
        if (sequenceIndex < sequences_.size()) return *sequences_[sequenceIndex];
154
 
        throw IndexOutOfBoundsException("VectorSequenceContainer::getSequence.", sequenceIndex, 0, sequences_.size() - 1);
 
160
  // Specified sequence existence verification
 
161
  if (sequenceIndex < sequences_.size())
 
162
    return *sequences_[sequenceIndex];
 
163
  throw IndexOutOfBoundsException("VectorSequenceContainer::getSequence.", sequenceIndex, 0, sequences_.size() - 1);
155
164
}
156
165
 
157
166
/******************************************************************************/
158
167
 
159
168
bool VectorSequenceContainer::hasSequence(const string& name) const
160
169
{
161
 
        // Specified sequence name research into all sequences
162
 
        for (unsigned int i = 0; i < sequences_.size(); i++)
163
 
                if (sequences_[i]->getName() == name)
 
170
  // Specified sequence name research into all sequences
 
171
  for (size_t i = 0; i < sequences_.size(); i++)
 
172
  {
 
173
    if (sequences_[i]->getName() == name)
164
174
      return true;
 
175
  }
165
176
  return false;
166
 
 
177
}
167
178
 
168
179
/******************************************************************************/
169
180
 
170
181
const Sequence& VectorSequenceContainer::getSequence(const string& name) const throw (SequenceNotFoundException)
171
182
{
172
 
        // Specified sequence name research into all sequences
173
 
        for (unsigned int i = 0; i < sequences_.size(); i++)
174
 
                if (sequences_[i]->getName() == name)
 
183
  // Specified sequence name research into all sequences
 
184
  for (size_t i = 0; i < sequences_.size(); i++)
 
185
  {
 
186
    if (sequences_[i]->getName() == name)
175
187
      return *sequences_[i];
176
 
        throw SequenceNotFoundException("VectorSequenceContainer::getSequence : Specified sequence doesn't exist", name);
 
188
  }
 
189
  throw SequenceNotFoundException("VectorSequenceContainer::getSequence : Specified sequence doesn't exist", name);
177
190
}
178
191
 
179
192
/******************************************************************************/
180
193
 
181
 
Sequence& VectorSequenceContainer::getSequence_(unsigned int sequenceIndex) throw (IndexOutOfBoundsException)
 
194
Sequence& VectorSequenceContainer::getSequence_(size_t sequenceIndex) throw (IndexOutOfBoundsException)
182
195
{
183
 
        // Specified sequence existence verification
184
 
        if (sequenceIndex < sequences_.size()) return *sequences_[sequenceIndex];
185
 
        throw IndexOutOfBoundsException("VectorSequenceContainer::getSequence.", sequenceIndex, 0, sequences_.size() - 1);
 
196
  // Specified sequence existence verification
 
197
  if (sequenceIndex < sequences_.size())
 
198
    return *sequences_[sequenceIndex];
 
199
  throw IndexOutOfBoundsException("VectorSequenceContainer::getSequence.", sequenceIndex, 0, sequences_.size() - 1);
186
200
}
187
201
 
188
202
/******************************************************************************/
189
203
 
190
204
Sequence& VectorSequenceContainer::getSequence_(const string& name) throw (SequenceNotFoundException)
191
205
{
192
 
        // Specified sequence name research into all sequences
193
 
        for (unsigned int i = 0; i < sequences_.size(); i++) {
194
 
                if (sequences_[i]->getName() == name) return *sequences_[i];
195
 
        }
196
 
        throw SequenceNotFoundException("VectorSequenceContainer::getSequence : Specified sequence doesn't exist", name);
197
 
}
198
 
 
199
 
/******************************************************************************/
200
 
 
201
 
unsigned int VectorSequenceContainer::getSequencePosition(const string& name) const throw (SequenceNotFoundException)
202
 
{
203
 
        // Specified sequence name research into all sequences
204
 
        for (unsigned int i = 0; i < sequences_.size(); i++) {
205
 
                if (sequences_[i] -> getName() == name) return i;
206
 
        }
207
 
        throw SequenceNotFoundException("VectorSequenceContainer::getSequencePosition : Specified sequence doesn't exist", name);
208
 
}
209
 
 
210
 
/******************************************************************************/
211
 
 
212
 
void VectorSequenceContainer::setSequence(unsigned int sequenceIndex, const Sequence& sequence, bool checkName) throw (Exception)
213
 
{
214
 
        // Sequence's name existence checking
215
 
        if (checkName) {
216
 
                // For all names in vector : throw exception if name already exists
217
 
                for (unsigned int j = 0; j < sequences_.size(); j++) {
218
 
                        if (sequences_[j] -> getName() == sequence.getName())
219
 
                                if (j != sequenceIndex) throw Exception("VectorSequenceContainer::setSequence : Sequence's name already exists in container");
220
 
                }
221
 
        }
222
 
 
223
 
        // New sequence's alphabet and sequence container's alphabet matching verification
224
 
        if (sequence.getAlphabet()->getAlphabetType() == getAlphabet()->getAlphabetType())
225
 
  {
226
 
                // Delete old sequence
227
 
                delete sequences_[sequenceIndex];
228
 
                // New sequence insertion in sequence container
229
 
                sequences_[sequenceIndex] = dynamic_cast<Sequence *>(sequence.clone());
230
 
        }
 
206
  // Specified sequence name research into all sequences
 
207
  for (size_t i = 0; i < sequences_.size(); i++)
 
208
  {
 
209
    if (sequences_[i]->getName() == name)
 
210
      return *sequences_[i];
 
211
  }
 
212
  throw SequenceNotFoundException("VectorSequenceContainer::getSequence : Specified sequence doesn't exist", name);
 
213
}
 
214
 
 
215
/******************************************************************************/
 
216
 
 
217
size_t VectorSequenceContainer::getSequencePosition(const string& name) const throw (SequenceNotFoundException)
 
218
{
 
219
  // Specified sequence name research into all sequences
 
220
  for (size_t i = 0; i < sequences_.size(); i++)
 
221
  {
 
222
    if (sequences_[i]->getName() == name)
 
223
      return i;
 
224
  }
 
225
  throw SequenceNotFoundException("VectorSequenceContainer::getSequencePosition : Specified sequence doesn't exist", name);
 
226
}
 
227
 
 
228
/******************************************************************************/
 
229
 
 
230
void VectorSequenceContainer::setSequence(size_t sequenceIndex, const Sequence& sequence, bool checkName) throw (Exception)
 
231
{
 
232
  // Sequence's name existence checking
 
233
  if (checkName)
 
234
  {
 
235
    // For all names in vector : throw exception if name already exists
 
236
    for (size_t j = 0; j < sequences_.size(); j++)
 
237
    {
 
238
      if (sequences_[j]->getName() == sequence.getName())
 
239
        if (j != sequenceIndex)
 
240
          throw Exception("VectorSequenceContainer::setSequence : Sequence's name already exists in container");
 
241
    }
 
242
  }
 
243
 
 
244
  // New sequence's alphabet and sequence container's alphabet matching verification
 
245
  if (sequence.getAlphabet()->getAlphabetType() == getAlphabet()->getAlphabetType())
 
246
  {
 
247
    // Delete old sequence
 
248
    delete sequences_[sequenceIndex];
 
249
    // New sequence insertion in sequence container
 
250
    sequences_[sequenceIndex] = dynamic_cast<Sequence*>(sequence.clone());
 
251
  }
231
252
  else
232
253
    throw AlphabetMismatchException("VectorSequenceContainer::setSequence : Alphabets don't match", getAlphabet(), sequence.getAlphabet());
233
254
}
234
255
 
235
256
/******************************************************************************/
236
257
 
237
 
Sequence* VectorSequenceContainer::removeSequence(unsigned int sequenceIndex) throw (IndexOutOfBoundsException)
 
258
Sequence* VectorSequenceContainer::removeSequence(size_t sequenceIndex) throw (IndexOutOfBoundsException)
238
259
{
239
 
        // Copy sequence:
240
 
        if (sequenceIndex >= sequences_.size())
241
 
          throw IndexOutOfBoundsException("VectorSequenceContainer::removeSequence.", sequenceIndex, 0, sequences_.size() - 1);
 
260
  // Copy sequence:
 
261
  if (sequenceIndex >= sequences_.size())
 
262
    throw IndexOutOfBoundsException("VectorSequenceContainer::removeSequence.", sequenceIndex, 0, sequences_.size() - 1);
242
263
  Sequence* old = sequences_[sequenceIndex];
243
 
        // Remove pointer toward old sequence:
244
 
        sequences_.erase(sequences_.begin() + sequenceIndex);
245
 
        // Send copy:
246
 
        return old;
 
264
  // Remove pointer toward old sequence:
 
265
  sequences_.erase(sequences_.begin() + sequenceIndex);
 
266
  // Send copy:
 
267
  return old;
247
268
}
248
269
 
249
270
/******************************************************************************/
250
271
 
251
 
void VectorSequenceContainer::deleteSequence(unsigned int sequenceIndex) throw (IndexOutOfBoundsException)
 
272
void VectorSequenceContainer::deleteSequence(size_t sequenceIndex) throw (IndexOutOfBoundsException)
252
273
{
253
 
        // Delete sequence
254
 
        if (sequenceIndex >= sequences_.size())
255
 
          throw IndexOutOfBoundsException("VectorSequenceContainer::deleteSequence.", sequenceIndex, 0, sequences_.size() - 1);
 
274
  // Delete sequence
 
275
  if (sequenceIndex >= sequences_.size())
 
276
    throw IndexOutOfBoundsException("VectorSequenceContainer::deleteSequence.", sequenceIndex, 0, sequences_.size() - 1);
256
277
  delete sequences_[sequenceIndex];
257
 
        // Remove pointer toward old sequence:
258
 
        sequences_.erase(sequences_.begin() + sequenceIndex);
 
278
  // Remove pointer toward old sequence:
 
279
  sequences_.erase(sequences_.begin() + sequenceIndex);
259
280
}
260
281
 
261
282
/******************************************************************************/
262
283
 
263
284
void VectorSequenceContainer::addSequence(const Sequence& sequence, bool checkName) throw (Exception)
264
285
{
265
 
        // Sequence's name existence checking
266
 
        if (checkName)
 
286
  // Sequence's name existence checking
 
287
  if (checkName)
267
288
  {
268
 
                // For all names in vector : throw exception if name already exists
269
 
                for (unsigned int i = 0; i < sequences_.size(); i++)
 
289
    // For all names in vector : throw exception if name already exists
 
290
    for (size_t i = 0; i < sequences_.size(); i++)
270
291
    {
271
 
                        if (sequences_[i] -> getName() == sequence.getName())
272
 
                                throw Exception("VectorSequenceContainer::addSequence : Sequence '" + sequence.getName() + "' already exists in container");
273
 
                }
274
 
        }
 
292
      if (sequences_[i]->getName() == sequence.getName())
 
293
        throw Exception("VectorSequenceContainer::addSequence : Sequence '" + sequence.getName() + "' already exists in container");
 
294
    }
 
295
  }
275
296
 
276
 
        // New sequence's alphabet and sequence container's alphabet matching verification
277
 
        if (sequence.getAlphabet()->getAlphabetType() == getAlphabet()->getAlphabetType())
 
297
  // New sequence's alphabet and sequence container's alphabet matching verification
 
298
  if (sequence.getAlphabet()->getAlphabetType() == getAlphabet()->getAlphabetType())
278
299
  {
279
 
                //push_back(new Sequence(sequence.getName(), sequence.getContent(), alphabet));
280
 
                sequences_.push_back(dynamic_cast<Sequence*>(sequence.clone()));
281
 
        }
 
300
    // push_back(new Sequence(sequence.getName(), sequence.getContent(), alphabet));
 
301
    sequences_.push_back(dynamic_cast<Sequence*>(sequence.clone()));
 
302
  }
282
303
  else
283
304
    throw AlphabetMismatchException("VectorSequenceContainer::addSequence : Alphabets don't match", getAlphabet(), sequence.getAlphabet());
284
305
}
285
306
 
286
 
void VectorSequenceContainer::addSequence(const Sequence& sequence, unsigned int sequenceIndex, bool checkName) throw (Exception)
 
307
void VectorSequenceContainer::addSequence(const Sequence& sequence, size_t sequenceIndex, bool checkName) throw (Exception)
287
308
{
288
 
        // Sequence's name existence checking
289
 
        if (checkName)
 
309
  // Sequence's name existence checking
 
310
  if (checkName)
290
311
  {
291
 
                // For all names in vector : throw exception if name already exists
292
 
                for (unsigned int i = 0; i < sequences_.size(); i++)
 
312
    // For all names in vector : throw exception if name already exists
 
313
    for (size_t i = 0; i < sequences_.size(); i++)
293
314
    {
294
 
                        if (sequences_[i] -> getName() == sequence.getName())
295
 
                                throw Exception("VectorSequenceContainer::addSequence : Sequence '" + sequence.getName() + "' already exists in container");
296
 
                }
297
 
        }
 
315
      if (sequences_[i]->getName() == sequence.getName())
 
316
        throw Exception("VectorSequenceContainer::addSequence : Sequence '" + sequence.getName() + "' already exists in container");
 
317
    }
 
318
  }
298
319
 
299
 
        // New sequence's alphabet and sequence container's alphabet matching verification
300
 
        if (sequence.getAlphabet()->getAlphabetType() == getAlphabet()->getAlphabetType())
 
320
  // New sequence's alphabet and sequence container's alphabet matching verification
 
321
  if (sequence.getAlphabet()->getAlphabetType() == getAlphabet()->getAlphabetType())
301
322
  {
302
 
                //insert(begin() + pos, new Sequence(sequence.getName(), sequence.getContent(), alphabet));
303
 
                sequences_.insert(sequences_.begin() + sequenceIndex, dynamic_cast<Sequence*>(sequence.clone()));
304
 
        }
 
323
    // insert(begin() + pos, new Sequence(sequence.getName(), sequence.getContent(), alphabet));
 
324
    sequences_.insert(sequences_.begin() + sequenceIndex, dynamic_cast<Sequence*>(sequence.clone()));
 
325
  }
305
326
  else
306
327
    throw AlphabetMismatchException("VectorSequenceContainer::addSequence : Alphabets don't match", getAlphabet(), sequence.getAlphabet());
307
328
}
311
332
std::vector<std::string> VectorSequenceContainer::getSequencesNames() const
312
333
{
313
334
  std::vector<std::string> names;
314
 
        for (unsigned int i = 0; i < sequences_.size(); i++)
 
335
  for (size_t i = 0; i < sequences_.size(); i++)
 
336
  {
315
337
    names.push_back(sequences_[i]->getName());
316
 
        return names;
 
338
  }
 
339
  return names;
317
340
}
318
341
 
319
342
/******************************************************************************/
320
343
 
321
344
void VectorSequenceContainer::setSequencesNames(
322
 
        const std::vector<std::string> & names,
323
 
        bool checkNames)
324
 
        throw(Exception)
 
345
  const std::vector<std::string>& names,
 
346
  bool checkNames)
 
347
throw (Exception)
325
348
{
326
 
        if (names.size() != getNumberOfSequences())
327
 
                throw BadIntegerException("VectorSequenceContainer::setSequenceNames : bad number of names", names.size());
328
 
        if (checkNames)
329
 
  {
330
 
                for (unsigned int i = 0; i < names.size(); i++) {
331
 
                        // For all names in vector : throw exception if name already exists
332
 
                        for (unsigned int j = 0; j < i; j++) {
333
 
                                if (names[j] == names[i])
334
 
                                        throw Exception("VectorSiteContainer::setSequencesNames : Sequence's name already exists in container");
335
 
                        }
336
 
                }
337
 
        }
338
 
        for (unsigned int i = 0; i < names.size(); i++)
339
 
  {
340
 
                sequences_[i]->setName(names[i]);
341
 
        }
 
349
  if (names.size() != getNumberOfSequences())
 
350
    throw IndexOutOfBoundsException("VectorSequenceContainer::setSequenceNames : bad number of names", names.size(), getNumberOfSequences(), getNumberOfSequences());
 
351
  if (checkNames)
 
352
  {
 
353
    for (size_t i = 0; i < names.size(); i++)
 
354
    {
 
355
      // For all names in vector : throw exception if name already exists
 
356
      for (size_t j = 0; j < i; j++)
 
357
      {
 
358
        if (names[j] == names[i])
 
359
          throw Exception("VectorSiteContainer::setSequencesNames : Sequence's name already exists in container");
 
360
      }
 
361
    }
 
362
  }
 
363
  for (size_t i = 0; i < names.size(); i++)
 
364
  {
 
365
    sequences_[i]->setName(names[i]);
 
366
  }
342
367
}
343
368
 
344
369
/******************************************************************************/
345
370
 
346
371
void VectorSequenceContainer::clear()
347
372
{
348
 
        // Delete sequences
349
 
        for (unsigned int i = 0; i < sequences_.size(); i++)
 
373
  // Delete sequences
 
374
  for (size_t i = 0; i < sequences_.size(); i++)
 
375
  {
350
376
    delete sequences_[i];
351
 
        // Delete all sequence pointers
352
 
        sequences_.clear();
 
377
  }
 
378
  // Delete all sequence pointers
 
379
  sequences_.clear();
353
380
}
354
381
 
355
382
/******************************************************************************/
356
383
 
357
 
void VectorSequenceContainer::setComments(unsigned int sequenceIndex, const Comments & comments) throw (IndexOutOfBoundsException)
 
384
void VectorSequenceContainer::setComments(size_t sequenceIndex, const Comments& comments) throw (IndexOutOfBoundsException)
358
385
{
359
 
        sequences_[sequenceIndex]->setComments(comments);
 
386
  sequences_[sequenceIndex]->setComments(comments);
360
387
}
361
388
 
362
389
/******************************************************************************/
363
390
 
364
391
VectorSequenceContainer* VectorSequenceContainer::createEmptyContainer() const
365
 
366
 
        VectorSequenceContainer* vsc = new VectorSequenceContainer(getAlphabet());
367
 
        vsc->setGeneralComments(getGeneralComments());
368
 
        return(vsc);
 
392
{
 
393
  VectorSequenceContainer* vsc = new VectorSequenceContainer(getAlphabet());
 
394
  vsc->setGeneralComments(getGeneralComments());
 
395
  return vsc;
369
396
}
370
397
 
371
398
/******************************************************************************/