8
Copyright or © or Copr. CNRS, (November 17, 2004)
10
This software is a computer program whose purpose is to provide classes
11
for sequences analysis.
13
This software is governed by the CeCILL license under French law and
14
abiding by the rules of distribution of free software. You can use,
15
modify and/ or redistribute the software under the terms of the CeCILL
16
license as circulated by CEA, CNRS and INRIA at the following URL
17
"http://www.cecill.info".
19
As a counterpart to the access to the source code and rights to copy,
20
modify and redistribute granted by the license, users are provided only
21
with a limited warranty and the software's author, the holder of the
22
economic rights, and the successive licensors have only limited
25
In this respect, the user's attention is drawn to the risks associated
26
with loading, using, modifying and/or developing or reproducing the
27
software by the user in light of its specific status of free software,
28
that may mean that it is complicated to manipulate, and that also
29
therefore means that it is reserved for developers and experienced
30
professionals having in-depth computer knowledge. Users are therefore
31
encouraged to load and test the software's suitability as regards their
32
requirements in conditions enabling the security of their systems and/or
33
data to be ensured and, more generally, to use and operate it in the
34
same conditions as regards security.
36
The fact that you are presently reading this means that you have had
37
knowledge of the CeCILL license and that you accept its terms.
8
Copyright or © or Copr. CNRS, (November 17, 2004)
10
This software is a computer program whose purpose is to provide classes
11
for sequences analysis.
13
This software is governed by the CeCILL license under French law and
14
abiding by the rules of distribution of free software. You can use,
15
modify and/ or redistribute the software under the terms of the CeCILL
16
license as circulated by CEA, CNRS and INRIA at the following URL
17
"http://www.cecill.info".
19
As a counterpart to the access to the source code and rights to copy,
20
modify and redistribute granted by the license, users are provided only
21
with a limited warranty and the software's author, the holder of the
22
economic rights, and the successive licensors have only limited
25
In this respect, the user's attention is drawn to the risks associated
26
with loading, using, modifying and/or developing or reproducing the
27
software by the user in light of its specific status of free software,
28
that may mean that it is complicated to manipulate, and that also
29
therefore means that it is reserved for developers and experienced
30
professionals having in-depth computer knowledge. Users are therefore
31
encouraged to load and test the software's suitability as regards their
32
requirements in conditions enabling the security of their systems and/or
33
data to be ensured and, more generally, to use and operate it in the
34
same conditions as regards security.
36
The fact that you are presently reading this means that you have had
37
knowledge of the CeCILL license and that you accept its terms.
40
40
#include "VectorSiteContainer.h"
53
53
const std::vector<const Site*>& vs,
54
54
const Alphabet* alpha,
55
55
bool checkPositions)
57
57
AbstractSequenceContainer(alpha),
63
if (vs.size() == 0) throw Exception("VectorSiteContainer::VectorSiteContainer. Empty site set.");
64
//Seq names and comments:
65
unsigned int nbSeq = vs[0]->size();
64
throw Exception("VectorSiteContainer::VectorSiteContainer. Empty site set.");
65
// Seq names and comments:
66
size_t nbSeq = vs[0]->size();
66
67
names_.resize(nbSeq);
67
68
comments_.resize(nbSeq);
68
for (unsigned int i = 0; i < nbSeq; i++)
69
for (size_t i = 0; i < nbSeq; i++)
70
71
names_[i] = "Seq_" + TextTools::toString(i);
71
comments_[i] = new Comments();
72
comments_[i] = new Comments();
73
//Now try to add each site:
74
for (unsigned int i = 0; i < vs.size(); i++)
74
// Now try to add each site:
75
for (size_t i = 0; i < vs.size(); i++)
76
addSite(*vs[i], checkPositions); //This may throw an exception if position argument already exists or is size is not valid.
77
addSite(*vs[i], checkPositions); // This may throw an exception if position argument already exists or is size is not valid.
79
80
sequences_.resize(nbSeq);
82
83
/******************************************************************************/
84
VectorSiteContainer::VectorSiteContainer(unsigned int size, const Alphabet* alpha):
85
VectorSiteContainer::VectorSiteContainer(size_t size, const Alphabet* alpha) :
85
86
AbstractSequenceContainer(alpha),
91
//Seq names and comments:
92
for (unsigned int i = 0; i < size; i++)
92
// Seq names and comments:
93
for (size_t i = 0; i < size; i++)
94
95
names_[i] = string("Seq_") + TextTools::toString(i);
95
96
comments_[i] = new Comments();
126
127
/******************************************************************************/
128
VectorSiteContainer::VectorSiteContainer(const VectorSiteContainer& vsc):
129
VectorSiteContainer::VectorSiteContainer(const VectorSiteContainer& vsc) :
129
130
AbstractSequenceContainer(vsc),
131
132
names_(vsc.names_),
132
133
comments_(vsc.getNumberOfSequences()),
133
134
sequences_(vsc.getNumberOfSequences())
135
//Now try to add each site:
136
for (unsigned int i = 0; i < vsc.getNumberOfSites(); i++)
137
addSite(vsc.getSite(i), false); //We assume that positions are correct.
136
// Now try to add each site:
137
for (size_t i = 0; i < vsc.getNumberOfSites(); i++)
139
addSite(vsc.getSite(i), false); // We assume that positions are correct.
139
for (unsigned int i = 0; i < vsc.getNumberOfSequences(); i++)
142
for (size_t i = 0; i < vsc.getNumberOfSequences(); i++)
140
144
comments_[i] = new Comments(vsc.getComments(i));
143
148
/******************************************************************************/
145
VectorSiteContainer::VectorSiteContainer(const SiteContainer& sc):
150
VectorSiteContainer::VectorSiteContainer(const SiteContainer& sc) :
146
151
AbstractSequenceContainer(sc),
148
153
names_(sc.getSequencesNames()),
149
154
comments_(sc.getNumberOfSequences()),
150
155
sequences_(sc.getNumberOfSequences())
152
//Now try to add each site:
153
for (unsigned int i = 0; i < sc.getNumberOfSites(); i++)
154
addSite(sc.getSite(i), false); //We assume that positions are correct.
157
// Now try to add each site:
158
for (size_t i = 0; i < sc.getNumberOfSites(); i++)
160
addSite(sc.getSite(i), false); // We assume that positions are correct.
156
for (unsigned int i = 0; i < sc.getNumberOfSequences(); i++)
163
for (size_t i = 0; i < sc.getNumberOfSequences(); i++)
157
165
comments_[i] = new Comments(sc.getComments(i));
160
169
/******************************************************************************/
162
VectorSiteContainer::VectorSiteContainer(const OrderedSequenceContainer& osc):
171
VectorSiteContainer::VectorSiteContainer(const OrderedSequenceContainer& osc) :
163
172
AbstractSequenceContainer(osc),
169
for (unsigned int i = 0; i < osc.getNumberOfSequences(); i++)
178
for (size_t i = 0; i < osc.getNumberOfSequences(); i++)
170
180
addSequence(osc.getSequence(i), false);
174
185
/******************************************************************************/
176
VectorSiteContainer::VectorSiteContainer(const SequenceContainer& sc):
187
VectorSiteContainer::VectorSiteContainer(const SequenceContainer& sc) :
177
188
AbstractSequenceContainer(sc),
194
207
AbstractSequenceContainer::operator=(vsc);
196
209
names_.resize(vsc.getNumberOfSequences());
197
210
setSequencesNames(vsc.getSequencesNames(), true);
198
//Now try to add each site:
199
for (unsigned int i = 0; i < vsc.getNumberOfSites(); i++)
200
addSite(vsc.getSite(i), false); //We assume that positions are correct.
202
unsigned int nbSeq = vsc.getNumberOfSequences();
211
// Now try to add each site:
212
for (size_t i = 0; i < vsc.getNumberOfSites(); i++)
214
addSite(vsc.getSite(i), false); // We assume that positions are correct.
217
size_t nbSeq = vsc.getNumberOfSequences();
203
218
comments_.resize(nbSeq);
204
for (unsigned int i = 0; i < nbSeq; i++)
219
for (size_t i = 0; i < nbSeq; i++)
205
221
comments_[i] = new Comments(vsc.getComments(i));
206
223
sequences_.resize(nbSeq);
216
233
AbstractSequenceContainer::operator=(sc);
218
235
names_.resize(sc.getNumberOfSequences());
219
236
setSequencesNames(sc.getSequencesNames(), true);
220
//Now try to add each site:
221
for (unsigned int i = 0; i < sc.getNumberOfSites(); i++)
222
addSite(sc.getSite(i), false); //We assume that positions are correct.
224
unsigned int nbSeq = sc.getNumberOfSequences();
237
// Now try to add each site:
238
for (size_t i = 0; i < sc.getNumberOfSites(); i++)
240
addSite(sc.getSite(i), false); // We assume that positions are correct.
243
size_t nbSeq = sc.getNumberOfSequences();
225
244
comments_.resize(nbSeq);
226
for (unsigned int i = 0; i < nbSeq; i++)
245
for (size_t i = 0; i < nbSeq; i++)
227
247
comments_[i] = new Comments(sc.getComments(i));
228
249
sequences_.resize(nbSeq);
272
297
/******************************************************************************/
274
void VectorSiteContainer::setSite(unsigned int pos, const Site& site, bool checkPositions) throw (Exception)
299
void VectorSiteContainer::setSite(size_t pos, const Site& site, bool checkPositions) throw (Exception)
276
if (pos >= getNumberOfSites()) throw IndexOutOfBoundsException("VectorSiteContainer::setSite.", pos, 0, getNumberOfSites() - 1);
301
if (pos >= getNumberOfSites())
302
throw IndexOutOfBoundsException("VectorSiteContainer::setSite.", pos, 0, getNumberOfSites() - 1);
279
if (site.size() != getNumberOfSequences()) throw SiteException("AlignedSequenceContainer::addSite. Site does not have the appropriate length", &site);
305
if (site.size() != getNumberOfSequences())
306
throw SiteException("AlignedSequenceContainer::addSite. Site does not have the appropriate length", &site);
281
308
// New site's alphabet and site container's alphabet matching verification
282
309
if (site.getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType())
288
315
int position = site.getPosition();
289
316
// For all positions in vector : throw exception if position already exists
290
for (unsigned int i = 0; i < sites_.size(); i++)
317
for (size_t i = 0; i < sites_.size(); i++)
292
if (sites_[i]->getPosition() == position) throw SiteException("VectorSiteContainer::setSite: Site position already exists in container", &site);
319
if (sites_[i]->getPosition() == position)
320
throw SiteException("VectorSiteContainer::setSite: Site position already exists in container", &site);
296
sites_[pos] = dynamic_cast<Site *>(site.clone());
324
sites_[pos] = dynamic_cast<Site*>(site.clone());
299
327
/******************************************************************************/
301
Site* VectorSiteContainer::removeSite(unsigned int i) throw (IndexOutOfBoundsException)
329
Site* VectorSiteContainer::removeSite(size_t i) throw (IndexOutOfBoundsException)
303
if (i >= getNumberOfSites()) throw IndexOutOfBoundsException("VectorSiteContainer::removeSite.", i, 0, getNumberOfSites() - 1);
331
if (i >= getNumberOfSites())
332
throw IndexOutOfBoundsException("VectorSiteContainer::removeSite.", i, 0, getNumberOfSites() - 1);
304
333
Site* site = sites_[i];
305
334
sites_.erase(sites_.begin() + i);
309
338
/******************************************************************************/
311
void VectorSiteContainer::deleteSite(unsigned int i) throw (IndexOutOfBoundsException)
340
void VectorSiteContainer::deleteSite(size_t i) throw (IndexOutOfBoundsException)
313
342
if (i >= getNumberOfSites())
314
343
throw IndexOutOfBoundsException("VectorSiteContainer::deleteSite.", i, 0, getNumberOfSites() - 1);
315
344
delete sites_[i];
316
sites_.erase(sites_.begin() + i);
345
sites_.erase(sites_.begin() + i);
319
348
/******************************************************************************/
321
void VectorSiteContainer::deleteSites(unsigned int siteIndex, unsigned int length) throw (IndexOutOfBoundsException)
350
void VectorSiteContainer::deleteSites(size_t siteIndex, size_t length) throw (IndexOutOfBoundsException)
323
352
if (siteIndex + length > getNumberOfSites())
324
353
throw IndexOutOfBoundsException("VectorSiteContainer::deleteSites.", siteIndex + length, 0, getNumberOfSites() - 1);
325
for (unsigned int i = siteIndex; i < siteIndex + length; ++i)
354
for (size_t i = siteIndex; i < siteIndex + length; ++i)
326
356
delete sites_[i];
327
sites_.erase(sites_.begin() + siteIndex, sites_.begin() + siteIndex + length);
358
sites_.erase(sites_.begin() + siteIndex, sites_.begin() + siteIndex + length);
330
361
/******************************************************************************/
371
405
if (checkPositions)
373
407
// For all positions in vector : throw exception if position already exists
374
for (unsigned int i = 0; i < sites_.size(); i++)
408
for (size_t i = 0; i < sites_.size(); i++)
376
if (sites_[i]->getPosition() == position) throw SiteException("VectorSiteContainer::addSite. Site position already exists in container", &site);
410
if (sites_[i]->getPosition() == position)
411
throw SiteException("VectorSiteContainer::addSite. Site position already exists in container", &site);
379
414
Site* copy = dynamic_cast<Site*>(site.clone());
380
415
copy->setPosition(position);
381
sites_.push_back(copy);
416
sites_.push_back(copy);
384
419
/******************************************************************************/
386
void VectorSiteContainer::addSite(const Site& site, unsigned int siteIndex, bool checkPositions) throw (Exception)
421
void VectorSiteContainer::addSite(const Site& site, size_t siteIndex, bool checkPositions) throw (Exception)
388
if (siteIndex >= getNumberOfSites()) throw IndexOutOfBoundsException("VectorSiteContainer::addSite", siteIndex, 0, getNumberOfSites() - 1);
423
if (siteIndex >= getNumberOfSites())
424
throw IndexOutOfBoundsException("VectorSiteContainer::addSite", siteIndex, 0, getNumberOfSites() - 1);
391
if (site.size() != getNumberOfSequences()) throw SiteException("VectorSiteContainer::addSite. Site does not have the appropriate length", &site);
427
if (site.size() != getNumberOfSequences())
428
throw SiteException("VectorSiteContainer::addSite. Site does not have the appropriate length", &site);
393
430
// New site's alphabet and site container's alphabet matching verification
394
431
if (site.getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType())
402
439
int position = site.getPosition();
403
440
// For all positions in vector : throw exception if position already exists
404
for (unsigned int i = 0; i < sites_.size(); i++)
441
for (size_t i = 0; i < sites_.size(); i++)
406
if (sites_[i]->getPosition() == position) throw SiteException("VectorSiteContainer::addSite. Site position already exists in container", &site);
443
if (sites_[i]->getPosition() == position)
444
throw SiteException("VectorSiteContainer::addSite. Site position already exists in container", &site);
410
//insert(begin() + pos, new Site(site));
448
// insert(begin() + pos, new Site(site));
411
449
sites_.insert(sites_.begin() + siteIndex, dynamic_cast<Site*>(site.clone()));
414
452
/******************************************************************************/
416
void VectorSiteContainer::addSite(const Site& site, unsigned int siteIndex, int position, bool checkPositions) throw (Exception)
454
void VectorSiteContainer::addSite(const Site& site, size_t siteIndex, int position, bool checkPositions) throw (Exception)
418
if (siteIndex >= getNumberOfSites()) throw IndexOutOfBoundsException("VectorSiteContainer::addSite", siteIndex, 0, getNumberOfSites() - 1);
456
if (siteIndex >= getNumberOfSites())
457
throw IndexOutOfBoundsException("VectorSiteContainer::addSite", siteIndex, 0, getNumberOfSites() - 1);
421
if (site.size() != getNumberOfSequences()) throw SiteException("VectorSiteContainer::addSite. Site does not have the appropriate length", &site);
460
if (site.size() != getNumberOfSequences())
461
throw SiteException("VectorSiteContainer::addSite. Site does not have the appropriate length", &site);
423
463
// New site's alphabet and site container's alphabet matching verification
424
464
if (site.getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType())
430
470
if (checkPositions)
432
472
// For all positions in vector : throw exception if position already exists
433
for (unsigned int i = 0; i < sites_.size(); i++)
473
for (size_t i = 0; i < sites_.size(); i++)
435
if (sites_[i]->getPosition() == position) throw SiteException("VectorSiteContainer::addSite. Site position already exists in container", &site);
475
if (sites_[i]->getPosition() == position)
476
throw SiteException("VectorSiteContainer::addSite. Site position already exists in container", &site);
439
Site* copy = dynamic_cast<Site *>(site.clone());
480
Site* copy = dynamic_cast<Site*>(site.clone());
440
481
copy->setPosition(position);
441
482
sites_.insert(sites_.begin() + siteIndex, copy);
444
485
/******************************************************************************/
446
unsigned int VectorSiteContainer::getNumberOfSites() const
487
size_t VectorSiteContainer::getNumberOfSites() const
448
489
return sites_.size();
464
505
Vint VectorSiteContainer::getSitePositions() const
466
507
Vint positions(sites_.size());
467
for (unsigned int i = 0; i < sites_.size(); i++)
508
for (size_t i = 0; i < sites_.size(); i++)
468
510
positions[i] = sites_[i]->getPosition();
469
512
return positions;
472
515
/******************************************************************************/
474
const Sequence& VectorSiteContainer::getSequence(unsigned int i) const throw (IndexOutOfBoundsException)
517
const Sequence& VectorSiteContainer::getSequence(size_t i) const throw (IndexOutOfBoundsException)
476
if (i >= getNumberOfSequences()) throw IndexOutOfBoundsException("VectorSiteContainer::getSequence.", i, 0, getNumberOfSequences() - 1);
519
if (i >= getNumberOfSequences())
520
throw IndexOutOfBoundsException("VectorSiteContainer::getSequence.", i, 0, getNumberOfSequences() - 1);
478
// Main loop : for all sites
479
unsigned int n = getNumberOfSites();
480
vector<int> sequence(n);
481
for (unsigned int j = 0; j < n; j++)
522
// Main loop : for all sites
523
size_t n = getNumberOfSites();
524
vector<int> sequence(n);
525
for (size_t j = 0; j < n; j++)
483
527
sequence[j] = sites_[j]->getContent()[i];
485
if (sequences_[i]) delete sequences_[i];
530
delete sequences_[i];
486
531
sequences_[i] = new BasicSequence(names_[i], sequence, *comments_[i], getAlphabet());
487
532
return *sequences_[i];
501
546
bool VectorSiteContainer::hasSequence(const string& name) const
503
//Look for sequence name:
504
for (unsigned int pos = 0; pos < names_.size(); pos++) {
505
if (names_[pos] == name) return true;
548
// Look for sequence name:
549
for (size_t pos = 0; pos < names_.size(); pos++)
551
if (names_[pos] == name)
510
557
/******************************************************************************/
512
unsigned int VectorSiteContainer::getSequencePosition(const string& name) const throw (SequenceNotFoundException)
559
size_t VectorSiteContainer::getSequencePosition(const string& name) const throw (SequenceNotFoundException)
514
//Look for sequence name:
515
for (unsigned int pos = 0; pos < names_.size(); pos++) {
516
if (names_[pos] == name) return pos;
561
// Look for sequence name:
562
for (size_t pos = 0; pos < names_.size(); pos++)
564
if (names_[pos] == name)
518
567
throw SequenceNotFoundException("VectorSiteContainer::getSequencePosition().", name);
523
572
void VectorSiteContainer::setSequence(const string& name, const Sequence& sequence, bool checkNames) throw (Exception)
525
//Look for sequence name:
526
unsigned int pos = getSequencePosition(name);
574
// Look for sequence name:
575
size_t pos = getSequencePosition(name);
527
576
setSequence(pos, sequence, checkNames);
530
579
/******************************************************************************/
532
void VectorSiteContainer::setSequence(unsigned int pos, const Sequence& sequence, bool checkNames)
581
void VectorSiteContainer::setSequence(size_t pos, const Sequence& sequence, bool checkNames)
535
584
if (pos >= getNumberOfSequences())
536
throw BadIntegerException("VectorSiteContainer::setSequence", pos);
585
throw IndexOutOfBoundsException("VectorSiteContainer::setSequence", pos, 0, getNumberOfSequences() - 1);
538
587
// New sequence's alphabet and site container's alphabet matching verification
539
588
if (sequence.getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType())
540
589
throw AlphabetMismatchException("VectorSiteContainer::addSite", getAlphabet(), sequence.getAlphabet());
542
//If the container has only one sequence, we set the size to the size of this sequence:
543
if (getNumberOfSequences() == 1) realloc(sequence.size());
591
// If the container has only one sequence, we set the size to the size of this sequence:
592
if (getNumberOfSequences() == 1)
593
realloc(sequence.size());
545
595
if (sequence.size() != sites_.size())
546
596
throw SequenceException("VectorSiteContainer::setSequence. Sequence has not the appropriate length.", &sequence);
550
for (unsigned int i = 0; i < names_.size(); i++)
600
for (size_t i = 0; i < names_.size(); i++)
551
602
if (i != pos && sequence.getName() == names_[i])
552
603
throw SequenceException("VectorSiteContainer::settSequence. Name already exists in container.", &sequence);
555
607
names_[pos] = sequence.getName();
556
//Update elements at each site:
557
for (unsigned int i = 0; i < sites_.size(); i++)
608
// Update elements at each site:
609
for (size_t i = 0; i < sites_.size(); i++)
558
611
sites_[i]->setElement(pos, sequence.getValue(i));
560
if (comments_[pos]) delete comments_[pos];
615
delete comments_[pos];
561
616
comments_[pos] = new Comments(sequence.getComments());
563
if (sequences_[pos]) delete sequences_[pos];
619
delete sequences_[pos];
564
620
sequences_[pos] = 0;
567
623
/******************************************************************************/
569
Sequence * VectorSiteContainer::removeSequence(unsigned int i) throw (IndexOutOfBoundsException)
625
Sequence* VectorSiteContainer::removeSequence(size_t i) throw (IndexOutOfBoundsException)
571
627
if (i >= getNumberOfSequences())
572
628
throw IndexOutOfBoundsException("VectorSiteContainer::removeSequence.", i, 0, getNumberOfSequences() - 1);
574
getSequence(i); //Actuallizes pointer.
630
getSequence(i); // Actuallizes pointer.
575
631
Sequence* sequence = sequences_[i];
576
for (unsigned int j = 0; j < sites_.size(); j++)
632
for (size_t j = 0; j < sites_.size(); j++)
579
635
sites_[j]->deleteElement(i);
582
//Now actualize names and comments:
638
// Now actualize names and comments:
583
639
names_.erase(names_.begin() + i);
584
if (comments_[i]) delete comments_[i];
585
642
comments_.erase(comments_.begin() + i);
586
643
// We remove the sequence, so the destruction of the sequence is up to the user:
587
//if (sequences_[i] != 0) delete sequences_[i];
644
// if (sequences_[i] != 0) delete sequences_[i];
588
645
sequences_.erase(sequences_.begin() + i);
592
649
/******************************************************************************/
594
Sequence * VectorSiteContainer::removeSequence(const string& name) throw (SequenceNotFoundException)
651
Sequence* VectorSiteContainer::removeSequence(const string& name) throw (SequenceNotFoundException)
596
//Look for sequence name:
597
unsigned int pos = getSequencePosition(name);
653
// Look for sequence name:
654
size_t pos = getSequencePosition(name);
598
655
return removeSequence(pos);
601
658
/******************************************************************************/
603
void VectorSiteContainer::deleteSequence(unsigned int i) throw (IndexOutOfBoundsException)
660
void VectorSiteContainer::deleteSequence(size_t i) throw (IndexOutOfBoundsException)
605
662
if (i >= getNumberOfSequences())
606
663
throw IndexOutOfBoundsException("VectorSiteContainer::demeteSequence.", i, 0, getNumberOfSequences() - 1);
607
for (unsigned int j = 0; j < sites_.size(); j++)
664
for (size_t j = 0; j < sites_.size(); j++)
608
666
sites_[j]->deleteElement(i);
610
//Now actualize names and comments:
669
// Now actualize names and comments:
611
670
names_.erase(names_.begin() + i);
612
if (comments_[i]) delete comments_[i];
613
673
comments_.erase(comments_.begin() + i);
614
if (sequences_[i]) delete sequences_[i];
675
delete sequences_[i];
615
676
sequences_.erase(sequences_.begin() + i);
620
681
void VectorSiteContainer::deleteSequence(const string& name) throw (SequenceNotFoundException)
622
//Look for sequence name:
623
unsigned int pos = getSequencePosition(name);
683
// Look for sequence name:
684
size_t pos = getSequencePosition(name);
627
688
/******************************************************************************/
629
690
void VectorSiteContainer::addSequence(const Sequence& sequence, bool checkNames) throw (Exception)
631
//If the container has no sequence, we set the size to the size of this sequence:
632
if (getNumberOfSequences() == 0) realloc(sequence.size());
692
// If the container has no sequence, we set the size to the size of this sequence:
693
if (getNumberOfSequences() == 0)
694
realloc(sequence.size());
634
696
// New sequence's alphabet and site container's alphabet matching verification
635
697
if (sequence.getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType())
636
698
throw AlphabetMismatchException("VectorSiteContainer::addSequence", getAlphabet(), sequence.getAlphabet());
638
700
if (sequence.size() != sites_.size())
639
701
throw SequenceException("VectorSiteContainer::addSequence. Sequence has not the appropriate length: " + TextTools::toString(sequence.size()) + ", should be " + TextTools::toString(sites_.size()) + ".", &sequence);
642
for (unsigned int i = 0; i < names_.size(); i++) {
643
if (sequence.getName() == names_[i]) throw SequenceException("VectorSiteContainer::addSequence. Name already exists in container.", &sequence);
705
for (size_t i = 0; i < names_.size(); i++)
707
if (sequence.getName() == names_[i])
708
throw SequenceException("VectorSiteContainer::addSequence. Name already exists in container.", &sequence);
648
713
names_.push_back(sequence.getName());
650
//Append elements at each site:
651
for (unsigned int i = 0; i < sites_.size(); i++) {
715
// Append elements at each site:
716
for (size_t i = 0; i < sites_.size(); i++)
652
718
sites_[i]->addElement(sequence.getValue(i));
656
722
comments_.push_back(new Comments(sequence.getComments()));
658
//Sequences pointers:
724
// Sequences pointers:
659
725
sequences_.push_back(0);
662
728
/******************************************************************************/
664
730
void VectorSiteContainer::addSequence(
665
const Sequence & sequence,
731
const Sequence& sequence,
670
if (pos >= getNumberOfSequences()) throw IndexOutOfBoundsException("VectorSiteContainer::addSequence.", pos, 0, getNumberOfSequences() - 1);
671
if (sequence.size() != sites_.size()) throw SequenceNotAlignedException("VectorSiteContainer::setSequence", &sequence);
736
if (pos >= getNumberOfSequences())
737
throw IndexOutOfBoundsException("VectorSiteContainer::addSequence.", pos, 0, getNumberOfSequences() - 1);
738
if (sequence.size() != sites_.size())
739
throw SequenceNotAlignedException("VectorSiteContainer::setSequence", &sequence);
673
741
// New sequence's alphabet and site container's alphabet matching verification
674
742
if (sequence.getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType())
681
for (unsigned int i = 0; i < names_.size(); i++)
749
for (size_t i = 0; i < names_.size(); i++)
683
if (sequence.getName() == names_[i]) throw SequenceException("VectorSiteContainer::addSequence. Name already exists in container.", &sequence);
751
if (sequence.getName() == names_[i])
752
throw SequenceException("VectorSiteContainer::addSequence. Name already exists in container.", &sequence);
687
for (unsigned int i = 0; i < sites_.size(); i++)
756
for (size_t i = 0; i < sites_.size(); i++)
690
759
sites_[i]->addElement(pos, sequence.getValue(i));
692
//Actualize names and comments:
693
names_.insert(names_.begin() + pos, sequence.getName());
761
// Actualize names and comments:
762
names_.insert(names_.begin() + pos, sequence.getName());
694
763
comments_.insert(comments_.begin() + pos, new Comments(sequence.getComments()));
695
764
sequences_.insert(sequences_.begin() + pos, 0);
738
820
void VectorSiteContainer::setSequencesNames(
739
821
const vector<string>& names,
743
825
if (names.size() != getNumberOfSequences())
744
throw BadIntegerException("VectorSiteContainer::setSequenceNames: bad number of names.", names.size());
826
throw IndexOutOfBoundsException("VectorSiteContainer::setSequenceNames: bad number of names.", names.size(), getNumberOfSequences(), getNumberOfSequences());
747
for (unsigned int i = 0; i < names.size(); i++)
829
for (size_t i = 0; i < names.size(); i++)
749
831
// For all names in vector : throw exception if name already exists
750
for (unsigned int j = 0; j < i; j++)
832
for (size_t j = 0; j < i; j++)
752
834
if (names[j] == names[i])
753
835
throw Exception("VectorSiteContainer::setSequencesNames : Sequence's name already exists in container");
757
for (unsigned int i = 0; i < names.size(); i++)
839
for (size_t i = 0; i < names.size(); i++)
759
841
names_[i] = names[i];