bpp-seq3  3.0.0
VectorSiteContainer.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_SEQ_CONTAINER_VECTORSITECONTAINER_H
6 #define BPP_SEQ_CONTAINER_VECTORSITECONTAINER_H
7 
9 
10 #include "SequenceContainer.h"
12 #include "SiteContainer.h"
14 #include "VectorMappedContainer.h"
15 
16 // From the STL library:
17 #include <string>
18 #include <vector>
19 #include <iterator>
20 #include <iostream>
21 #include <memory>
22 
23 namespace bpp
24 {
40 template<class SiteType, class SequenceType>
42  public AbstractTemplateSequenceContainer<SequenceType, std::string>,
43  public virtual TemplateSiteContainerInterface<SiteType, SequenceType, std::string>
44 {
45 protected:
48  std::vector<std::string> sequenceNames_;
49  std::vector<Comments> sequenceComments_;
50 
51 public:
61  std::vector<std::unique_ptr<SiteType>>& vs,
62  std::shared_ptr<const Alphabet> alphabet,
63  bool checkPositions = true) :
69  {
70  if (vs.size() == 0)
71  throw Exception("VectorSiteContainer::VectorSiteContainer. Empty site set.");
72 
73  size_t nbSeq = vs[0]->size();
74  sequenceComments_.resize(nbSeq);
75  for (size_t i = 0; i < nbSeq; ++i)
76  {
77  sequenceNames_.push_back("Seq_" + TextTools::toString(i));
79  }
80 
81  for (auto& vi : vs)
82  {
83  addSite(vi, checkPositions); // This may throw an exception if position argument already exists or is size is not valid.
84  }
85  }
86 
87 
95  size_t size,
96  std::shared_ptr<const Alphabet> alphabet) :
100  sequenceNames_(),
101  sequenceComments_(size)
102  {
103  for (size_t i = 0; i < size; ++i)
104  {
105  sequenceNames_.push_back("Seq_" + TextTools::toString(i));
107  }
108  }
109 
110 
119  const std::vector<std::string>& sequenceKeys,
120  std::shared_ptr<const Alphabet> alphabet,
121  bool useKeysAsNames = true) :
123  siteContainer_(),
125  sequenceNames_(),
126  sequenceComments_(sequenceKeys.size())
127  {
128  unsigned int i = 0;
129  if (useKeysAsNames)
130  {
131  for (auto key : sequenceKeys)
132  {
133  ++i;
134  sequenceNames_.push_back(key);
135  sequenceContainer_.appendObject(nullptr, key);
136  }
137  }
138  else
139  {
140  for (auto key : sequenceKeys)
141  {
142  ++i;
143  sequenceNames_.push_back("Seq_" + TextTools::toString(i));
144  sequenceContainer_.appendObject(nullptr, key);
145  }
146  }
147  }
148 
149 
155  TemplateVectorSiteContainer(std::shared_ptr<const Alphabet> alphabet) :
157  siteContainer_(),
159  sequenceNames_(),
161  {}
162 
163 
165  AbstractTemplateSequenceContainer<SequenceType>(vsc),
166  siteContainer_(),
170  {
171  for (auto sequenceKey : vsc.getSequenceKeys())
172  {
174  }
175 
176  for (size_t i = 0; i < vsc.getNumberOfSites(); ++i)
177  {
178  auto sitePtr = std::unique_ptr<SiteType>(vsc.site(i).clone());
179  addSite(sitePtr, false); // We assume that positions are already correct.
180  }
181  }
182 
183 
185  AbstractTemplateSequenceContainer<SequenceType>(sc),
186  siteContainer_(),
190  {
191  for (auto& sequenceKey : sc.getSequenceKeys())
192  {
194  }
195 
196  for (size_t i = 0; i < sc.getNumberOfSites(); ++i)
197  {
198  std::unique_ptr<SiteType> sitePtr(sc.site(i).clone());
199  addSite(sitePtr, false); // We assume that positions are already correct.
200  }
201  }
202 
204  AbstractTemplateSequenceContainer<SequenceType>(sc),
205  siteContainer_(),
207  sequenceNames_(),
209  {
210  for (auto& sequenceKey: sc.getSequenceKeys())
211  {
212  auto seqPtr = std::make_unique<SequenceType>(sc.sequence(sequenceKey));
213  addSequence(sequenceKey, seqPtr);
214  }
215 
216  reindexSites();
217  }
218 
220  {
221  clear();
225 
226  for (size_t i = 0; i < vsc.getNumberOfSites(); ++i)
227  {
228  auto sitePtr = std::make_unique<SiteType>(vsc.site(i));
229  addSite(sitePtr, false); // We assume that positions are already correct.
230  }
231 
232  return *this;
233  }
234 
235 
237  {
238  clear();
240  sequenceNames_ = sc.sequenceNames_;
241  sequenceComments_ = sc.sequenceComments_;
242 
243  for (auto sequenceKey : sc.getSequenceKeys())
244  {
246  }
247 
248  for (size_t i = 0; i < sc.getNumberOfSites(); ++i)
249  {
250  auto sitePtr = std::make_unique<SiteType>(sc.site(i));
251  addSite(sitePtr, false); // We assume that positions are already correct.
252  }
253 
254  return *this;
255  }
256 
257 
259  {
260  clear();
262 
263  for (auto sequenceKey: sc.getSequenceKeys())
264  {
265  addSequence(sequenceKey, sc.getSequence(sequenceKey));
266  }
267 
268  reindexSites();
269 
270  return *this;
271  }
272 
273 
275  {
276  clear();
277  }
278 
279 public:
286  {
288  }
296  const SiteType& site(size_t sitePosition) const override
297  {
298  return *siteContainer_.getObject(sitePosition);
299  }
300 
301  void setSite(size_t sitePosition, std::unique_ptr<SiteType>& site, bool checkCoordinate = true) override
302  {
303  if (sitePosition >= getNumberOfSites())
304  throw IndexOutOfBoundsException("TemplateVectorSiteContainer::setSite.", sitePosition, 0, getNumberOfSites() - 1);
305 
306  // Check size:
307  if (site->size() != getNumberOfSequences())
308  {
309  throw SiteException("TemplateVectorSiteContainer::setSite. Site does not have the appropriate length", site.get());
310  }
311 
312  // New site's alphabet and site container's alphabet matching verification
313  if (site->getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType())
314  throw AlphabetMismatchException("TemplateVectorSiteContainer::setSite", getAlphabet(), site->getAlphabet());
315 
316  // Check coordinate:
317  if (checkCoordinate)
318  {
319  int coordinate = site->getCoordinate();
320  // For all coordinates in vector: throw exception if position already exists
321  for (size_t i = 0; i < getNumberOfSites(); ++i)
322  {
323  if (i != sitePosition && this->site(i).getCoordinate() == coordinate)
324  {
325  throw SiteException("TemplateVectorSiteContainer::setSite: Site position already exists in container", site.get());
326  }
327  }
328  }
329 
330  std::shared_ptr<SiteType> sitePtr(site.release(), SwitchDeleter<SiteType>());
331  siteContainer_.addObject(sitePtr, sitePosition, false);
332 
333  // Clean Sequence Container cache
335  }
336 
337  std::unique_ptr<SiteType> removeSite(size_t sitePosition) override
338  {
339  // Clean Sequence Container cache
341 
342  auto sitePtr = siteContainer_.removeObject(sitePosition);
343  std::get_deleter< SwitchDeleter<SiteType>>(sitePtr)->off();
344  return std::unique_ptr<SiteType>(sitePtr.get());
345  }
346 
347  void deleteSite(size_t sitePosition) override
348  {
349  siteContainer_.deleteObject(sitePosition);
350  // Clean Sequence Container cache
352  }
353 
354 
355  void addSite(std::unique_ptr<SiteType>& site, bool checkCoordinate = true) override
356  {
357  // Check size:
358  if (getNumberOfSequences() != 0 && (site->size() != getNumberOfSequences()))
359  throw SiteException("TemplateVectorSiteContainer::addSite. Site does not have the appropriate length", site.get());
360 
361  // New site's alphabet and site container's alphabet matching verification
362  if (site->getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType())
363  throw AlphabetMismatchException("TemplateVectorSiteContainer::addSite", getAlphabet(), site->getAlphabet());
364 
365  // Check coordinate:
366  if (checkCoordinate)
367  {
368  int coordinate = site->getCoordinate();
369  // For all positions in vector : throw exception if position already exists
370  for (size_t i = 0; i < getNumberOfSites(); ++i)
371  {
372  if (this->site(i).getCoordinate() == coordinate)
373  throw SiteException("TemplateVectorSiteContainer::addSite(site, bool): Site position already exists in container", site.get());
374  }
375  }
376 
377  std::shared_ptr<SiteType> sitePtr(site.release(), SwitchDeleter<SiteType>());
378  siteContainer_.appendObject(sitePtr);
379 
380  // Clean Sequence Container cache
381  if (getNumberOfSequences() == 0)
382  {
383  sequenceNames_.resize(sitePtr->size());
384  sequenceComments_.resize(sitePtr->size());
385  for (size_t i = 0; i < sitePtr->size(); ++i)
386  {
387  sequenceNames_[i] = "Seq_" + TextTools::toString(i);
389  }
390  }
391  else
392  {
394  }
395  }
396 
397 
398  void addSite(std::unique_ptr<SiteType>& site, size_t sitePosition, bool checkCoordinate = true) override
399  {
400  if (sitePosition >= getNumberOfSites())
401  throw IndexOutOfBoundsException("TemplateVectorSiteContainer::addSite", sitePosition, 0, getNumberOfSites() - 1);
402 
403  // Check size:
404  if (site->size() != getNumberOfSequences())
405  throw SiteException("TemplateVectorSiteContainer::addSite. Site does not have the appropriate length", site.get());
406 
407  // New site's alphabet and site container's alphabet matching verification
408  if (site->getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType())
409  throw AlphabetMismatchException("TemplateVectorSiteContainer::addSite", getAlphabet(), site->getAlphabet());
410 
411  // Check coordinate:
412  if (checkCoordinate)
413  {
414  int coordinate = site->getCoordinate();
415  // For all positions in vector : throw exception if position already exists
416  for (size_t i = 0; i < getNumberOfSites(); i++)
417  {
418  if (i != sitePosition && this->site(i).getCoordinate() == coordinate)
419  throw SiteException("TemplateVectorSiteContainer::addSite. Site coordinate already exists in container", site.get());
420  }
421  }
422 
423  std::shared_ptr<SiteType> sitePtr(site.release(), SwitchDeleter<SiteType>());
424  siteContainer_.insertObject(sitePtr, sitePosition);
425 
426  // Clean Sequence Container cache
427  if (getNumberOfSequences() == 0)
428  {
429  sequenceNames_.resize(sitePtr->size());
430  sequenceComments_.resize(sitePtr->size());
431  for (size_t i = 0; i < sitePtr->size(); ++i)
432  {
433  sequenceNames_[i] = "Seq_" + TextTools::toString(i);
435  }
436  }
437  else
438  {
440  }
441  }
442 
443 
444  void deleteSites(size_t sitePosition, size_t length) override
445  {
446  siteContainer_.deleteObjects(sitePosition, length);
447  }
448 
449  size_t getNumberOfSites() const override
450  {
451  return siteContainer_.getSize();
452  }
453 
454  void reindexSites() override
455  {
456  for (size_t i = 0; i < getNumberOfSites(); ++i)
457  {
458  site_(i).setCoordinate(static_cast<int>(i) + 1);
459  }
460  }
461 
462  Vint getSiteCoordinates() const override
463  {
464  Vint coordinates(getNumberOfSites());
465  for (size_t i = 0; i < getNumberOfSites(); ++i)
466  {
467  coordinates[i] = site(i).getCoordinate();
468  }
469  return coordinates;
470  }
471 
472  void setSiteCoordinates(const Vint& vCoordinates) override
473  {
474  if (vCoordinates.size() != getNumberOfSites())
475  throw BadSizeException("TemplateVectorSiteContainer::setSiteCoordinates bad size of coordinates vector", vCoordinates.size(), getNumberOfSites());
476 
477  for (size_t i = 0; i < getNumberOfSites(); ++i)
478  {
479  site_(i).setCoordinate(vCoordinates[i]);
480  }
481  }
482 
491  bool hasSequence(const std::string& sequenceKey) const override
492  {
493  // Look for sequence key:
495  }
496 
497  size_t getSequencePosition(const std::string& sequenceKey) const override
498  {
499  // Look for sequence key:
501  }
502 
503  const SequenceType& sequence(const std::string& sequenceKey) const override
504  {
505  size_t pos = getSequencePosition(sequenceKey);
506  return sequence(pos);
507  }
508 
509  const SequenceType& sequence(size_t sequencePosition) const override
510  {
511  if (sequencePosition >= getNumberOfSequences())
512  throw IndexOutOfBoundsException("TemplateVectorSiteContainer::getSequence.", sequencePosition, 0, getNumberOfSequences() - 1);
513 
514  // If Sequence already exists
515  auto name = sequenceContainer_.getObjectName(sequencePosition);
517  {
518  return *sequenceContainer_.getObject(sequencePosition);
519  }
520 
521  // Main loop : for all sites
522  size_t n = getNumberOfSites();
523  std::vector<typename SequenceType::SymbolType> sequence(n);
524  for (size_t j = 0; j < n; ++j)
525  {
526  sequence[j] = site(j)[sequencePosition];
527  }
528 
529  auto alphaPtr = getAlphabet();
530  auto ns = std::shared_ptr<SequenceType>(
531  new SequenceType(
532  sequenceNames_[sequencePosition],
533  sequence,
534  sequenceComments_[sequencePosition],
535  alphaPtr),
537 
538  sequenceContainer_.addObject_(ns, sequencePosition, sequenceKey(sequencePosition), false);
539 
540  return *ns;
541  }
542 
543 
544  std::unique_ptr<SequenceType> removeSequence(size_t sequencePosition) override
545  {
546  sequence(sequencePosition); // this creates the sequence if it does not exist.
547 
548  for (size_t i = 0; i < getNumberOfSites(); ++i)
549  {
550  site_(i).deleteElement(sequencePosition);
551  }
552 
553  auto d = static_cast<std::vector<std::string>::difference_type>(sequencePosition);
554  sequenceNames_.erase(std::next(sequenceNames_.begin(), d));
555  sequenceComments_.erase(std::next(sequenceComments_.begin(), d));
556 
557  auto seq = sequenceContainer_.removeObject(sequencePosition);
558  std::get_deleter<SwitchDeleter<SequenceType>>(seq)->off();
559  std::unique_ptr<SequenceType> seq2(seq.get());
560  return seq2;
561  }
562 
563  std::unique_ptr<SequenceType> removeSequence(const std::string& sequenceKey) override
564  {
565  // Look for sequence key:
566  size_t sequencePosition = getSequencePosition(sequenceKey);
567  return removeSequence(sequencePosition);
568  }
569 
570  void deleteSequence(size_t sequencePosition) override
571  {
572  for (size_t i = 0; i < getNumberOfSites(); ++i)
573  {
574  site_(i).deleteElement(sequencePosition);
575  }
576 
577  auto posN = static_cast<std::vector<std::string>::difference_type>(sequencePosition);
578  sequenceNames_.erase(sequenceNames_.begin() + posN);
579  auto posC = static_cast<std::vector<Comments>::difference_type>(sequencePosition);
580  sequenceComments_.erase(sequenceComments_.begin() + posC);
581 
582  sequenceContainer_.deleteObject(sequencePosition);
583  }
584 
585  void deleteSequence(const std::string& sequenceKey) override
586  {
587  // Look for sequence key:
588  size_t sequencePosition = getSequencePosition(sequenceKey);
589  deleteSequence(sequencePosition);
590  }
591 
592  size_t getNumberOfSequences() const override
593  {
595  }
596 
597  std::vector<std::string> getSequenceKeys() const override
598  {
600  }
601 
602  void setSequenceKeys(const std::vector<std::string>& sequenceKeys) override
603  {
604  sequenceContainer_.setObjectNames(sequenceKeys);
605  }
606 
607  const std::string& sequenceKey(size_t sequencePosition) const override
608  {
609  return sequenceContainer_.getObjectName(sequencePosition);
610  }
611 
612  std::vector<std::string> getSequenceNames() const override
613  {
614  return sequenceNames_;
615  }
616 
617  void setSequenceNames(const std::vector<std::string>& names, bool updateKeys) override
618  {
619  if (names.size() != getNumberOfSequences())
620  throw DimensionException("TemplateVectorSiteContainer::setSequenceNames : bad number of names", names.size(), getNumberOfSequences());
622  sequenceNames_ = names;
623  if (updateKeys)
624  {
625  setSequenceKeys(names);
626  }
627  }
628 
629  std::vector<Comments> getSequenceComments() const override
630  {
631  return sequenceComments_;
632  }
633 
634  void clear() override
635  {
638  sequenceNames_.clear();
639  sequenceComments_.clear();
640  }
641 
643  {
644  auto alphaP = getAlphabet();
646  vsc->setComments(getComments());
647  return vsc;
648  }
649 
650  const typename SequenceType::ElementType& valueAt(const std::string& sequenceKey, size_t sitePosition) const override
651  {
652  return site(sitePosition)[getSequencePosition(sequenceKey)];
653  }
654 
655  typename SequenceType::ElementType& valueAt(const std::string& sequenceKey, size_t sitePosition) override
656  {
657  size_t sequencePosition = getSequencePosition(sequenceKey);
658  // Reset sequence buffer for this position:
659  sequenceContainer_.addObject(nullptr, sequencePosition, sequenceContainer_.getObjectName(sequencePosition));
660  return this->site_(sitePosition)[sequencePosition];
661  }
662 
663  const typename SequenceType::ElementType& valueAt(size_t sequencePosition, size_t sitePosition) const override
664  {
665  return site(sitePosition)[sequencePosition];
666  }
667 
668  typename SequenceType::ElementType& valueAt(size_t sequencePosition, size_t sitePosition) override
669  {
670  // Reset sequence buffer for this position:
671  sequenceContainer_.addObject(nullptr, sequencePosition, sequenceContainer_.getObjectName(sequencePosition));
672  return site_(sitePosition)[sequencePosition];
673  }
674 
675  double getStateValueAt(size_t sitePosition, const std::string& sequenceKey, int state) const override
676  {
677  return site(sitePosition).getStateValueAt(getSequencePosition(sequenceKey), state);
678  }
679 
680  double operator()(size_t sitePosition, const std::string& sequenceKey, int state) const override
681  {
682  return site(sitePosition).getStateValueAt(getSequencePosition(sequenceKey), state);
683  }
684 
685  double getStateValueAt(size_t sitePosition, size_t sequencePosition, int state) const override
686  {
687  return site(sitePosition).getStateValueAt(sequencePosition, state);
688  }
689 
690  double operator()(size_t sitePosition, size_t sequencePosition, int state) const override
691  {
692  return site(sitePosition).getStateValueAt(sequencePosition, state);
693  }
694 
695 
696  void setSequence(const std::string& sequenceKey, std::unique_ptr<SequenceType>& sequence) override
697  {
698  size_t pos = getSequencePosition(sequenceKey);
699  setSequence(pos, sequence);
700  }
701 
702 
703  void setSequence(size_t sequencePosition, std::unique_ptr<SequenceType>& sequence) override
704  {
705  setSequence(sequencePosition, sequence, sequenceContainer_.getObjectName(sequencePosition));
706  }
707 
708 
709  void setSequence(size_t sequencePosition, std::unique_ptr<SequenceType>& sequence, const std::string& sequenceKey) override
710  {
711  if (sequencePosition >= getNumberOfSequences())
712  throw IndexOutOfBoundsException("VectorSiteContainer::setSequence.", sequencePosition, 0, getNumberOfSequences() - 1);
713 
714  if (sequence->size() != getNumberOfSites())
715  throw SequenceNotAlignedException("VectorSiteContainer::setSequence", sequence.get());
716 
717  // New sequence's alphabet and site container's alphabet matching verification
718  if (sequence->getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType())
719  throw AlphabetMismatchException("VectorSiteContainer::setSequence", getAlphabet(), sequence->getAlphabet());
720 
721  // Update elements at each site:
722  for (size_t i = 0; i < getNumberOfSites(); i++)
723  {
724  site_(i).addElement(sequencePosition, sequence->getValue(i));
725  }
726 
727  sequenceContainer_.addObject(std::move(sequence), sequencePosition, sequenceKey);
728  }
729 
730 
731  void addSequence(const std::string& sequenceKey, std::unique_ptr<SequenceType>& sequence) override
732  {
733  // If the container has no sequence, we set the size to the size of this sequence:
734  if (getNumberOfSequences() == 0)
735  realloc_(sequence->size());
736 
737  // New sequence's alphabet and site container's alphabet matching verification
738  if (sequence->getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType())
739  throw AlphabetMismatchException("VectorSiteContainer::addSequence", getAlphabet(), sequence->getAlphabet());
740 
741  if (sequence->size() != getNumberOfSites())
742  throw SequenceException("VectorSiteContainer::addSequence. Sequence has not the appropriate length: " + TextTools::toString(sequence->size()) + ", should be " + TextTools::toString(getNumberOfSites()) + ".", sequence.get());
743 
745  throw SequenceException("VectorSiteContainer::addSequence. Name already exists in container.", sequence.get());
746 
747  // Update elements at each site:
748  for (size_t i = 0; i < getNumberOfSites(); ++i)
749  {
750  site_(i).addElement(sequence->getValue(i));
751  }
752 
753  // Add name and comments:
754  sequenceNames_.push_back(sequence->getName());
755  sequenceComments_.push_back(sequence->getComments());
756 
757  // Since the sequence is built already, we save it in the cache:
759  }
760 
761 
762  void insertSequence(size_t sequencePosition, std::unique_ptr<SequenceType>& sequence, const std::string& sequenceKey) override
763  {
764  if (sequencePosition >= getNumberOfSequences())
765  throw IndexOutOfBoundsException("VectorSiteContainer::insertSequence.", sequencePosition, 0, getNumberOfSequences() - 1);
766 
767  if (sequence->size() != getNumberOfSites())
768  throw SequenceNotAlignedException("VectorSiteContainer::insertSequence", sequence.get());
769 
770  // New sequence's alphabet and site container's alphabet matching verification
771  if (sequence->getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType())
772  throw AlphabetMismatchException("VectorSiteContainer::insertSequence", getAlphabet(), sequence->getAlphabet());
773 
774  // Update elements at each site:
775  for (size_t i = 0; i < getNumberOfSites(); ++i)
776  {
777  site_(i).addElement(sequencePosition, sequence->getValue(i));
778  }
779 
780  // Update name and comments:
781  sequenceNames_[sequencePosition] = sequence->getName();
782  sequenceComments_[sequencePosition] = sequence->getComments();
783 
784  // Since the sequence is built already, we save it in the cache:
785  sequenceContainer_.insertObject(std::move(sequence), sequencePosition, sequenceKey);
786  }
787 
788  // Needed because of the template class
793 protected:
801  SiteType& site_(size_t sitePosition)
802  {
803  return *siteContainer_.getObject(sitePosition);
804  }
805 
806  // Create n void sites:
807  void realloc_(size_t n)
808  {
809  clear();
810  std::shared_ptr<const Alphabet> alphaPtr = getAlphabet();
811  SiteType s(alphaPtr);
812 
813  for (size_t i = 0; i < n; ++i)
814  {
815  std::unique_ptr<SiteType> sitePtr(s.clone());
816  addSite(sitePtr, false);
817  }
818 
819  reindexSites();
820  }
821 };
822 
823 // Aliases:
826 } // end of namespace bpp.
827 #endif // BPP_SEQ_CONTAINER_VECTORSITECONTAINER_H
Partial implementation of the SequenceContainer interface.
AbstractTemplateSequenceContainer & operator=(const AbstractTemplateSequenceContainer< SequenceType, HashType > &sc)
std::shared_ptr< const Alphabet > getAlphabet() const override
Exception thrown when two alphabets do not match.
bool hasObject(const std::string &name) const override
Check if a object with a given name is present in the container.
bool isAvailableName(std::string objectName) const
const std::shared_ptr< T > getObject(const std::string &name) const override
Retrieve an object from the container.
The sequence exception base class.
Exception thrown when a sequence is not align with others.
const Comments & getComments() const override
Get the comments.
Definition: Commentable.h:79
The site exception base class.
virtual const SequenceType & sequence(const HashType &sequenceKey) const override=0
Retrieve a sequence object from the container.
virtual std::vector< HashType > getSequenceKeys() const =0
The SiteContainer interface.
Definition: SiteContainer.h:29
virtual const SiteType & site(size_t sitePosition) const override=0
Get a site from the container.
virtual size_t getNumberOfSites() const override=0
Get the number of aligned positions in the container.
The VectorSiteContainer class.
void addSite(std::unique_ptr< SiteType > &site, bool checkCoordinate=true) override
Add a site in the container.
std::unique_ptr< SequenceType > removeSequence(size_t sequencePosition) override
Remove a sequence from the container.
VectorPositionedContainer< SiteType > siteContainer_
double operator()(size_t sitePosition, size_t sequencePosition, int state) const override
Get the value of a state at a given position.
std::vector< std::string > sequenceNames_
TemplateVectorSiteContainer(std::shared_ptr< const Alphabet > alphabet)
Build a new empty container.
Vint getSiteCoordinates() const override
Get all coordinates of sites.
double getStateValueAt(size_t sitePosition, size_t sequencePosition, int state) const override
Get value of a state at a given position.
TemplateVectorSiteContainer(const TemplateSiteContainerInterface< SiteType, SequenceType, std::string > &sc)
std::vector< Comments > getSequenceComments() const override
const SequenceType::ElementType & valueAt(const std::string &sequenceKey, size_t sitePosition) const override
Get the content of the dataset at a specific position (sequence key, site position).
TemplateVectorSiteContainer(std::vector< std::unique_ptr< SiteType >> &vs, std::shared_ptr< const Alphabet > alphabet, bool checkPositions=true)
Build a new container from a set of sites.
VectorMappedContainer< SequenceType > sequenceContainer_
void addSequence(const std::string &sequenceKey, std::unique_ptr< SequenceType > &sequence) override
Add a sequence to the container.
const SequenceType & sequence(const std::string &sequenceKey) const override
Retrieve a sequence object from the container.
SequenceType::ElementType & valueAt(size_t sequencePosition, size_t sitePosition) override
Get the content of the dataset at a specific position (sequence position, site position).
double getStateValueAt(size_t sitePosition, const std::string &sequenceKey, int state) const override
Get the value of a state at a given position.
void setSequence(size_t sequencePosition, std::unique_ptr< SequenceType > &sequence) override
Replace a sequence in the container.
TemplateVectorSiteContainer(const TemplateSequenceContainerInterface< SequenceType, std::string > &sc)
void deleteSequence(size_t sequencePosition) override
Remove and delete a sequence from the container.
SequenceType::ElementType & valueAt(const std::string &sequenceKey, size_t sitePosition) override
Get the content of the dataset at a specific position (sequence key, site position).
void setSequenceKeys(const std::vector< std::string > &sequenceKeys) override
Reset all sequence keys.
void reindexSites() override
Set all coordinate attributes.
TemplateVectorSiteContainer< SiteType, SequenceType > & operator=(const TemplateSiteContainerInterface< SiteType, SequenceType, std::string > &sc)
TemplateVectorSiteContainer< SiteType, SequenceType > * createEmptyContainer() const override
Return a copy of this container, but with no data inside.
void setSite(size_t sitePosition, std::unique_ptr< SiteType > &site, bool checkCoordinate=true) override
Set a site in the container.
void addSite(std::unique_ptr< SiteType > &site, size_t sitePosition, bool checkCoordinate=true) override
Add a site in the container.
const SiteType & site(size_t sitePosition) const override
Get a site from the container.
std::vector< std::string > getSequenceKeys() const override
TemplateVectorSiteContainer< SiteType, SequenceType > * clone() const override
void insertSequence(size_t sequencePosition, std::unique_ptr< SequenceType > &sequence, const std::string &sequenceKey) override
Insert a sequence in the container.
TemplateVectorSiteContainer(const TemplateVectorSiteContainer< SiteType, SequenceType > &vsc)
TemplateVectorSiteContainer< SiteType, SequenceType > & operator=(const TemplateSequenceContainerInterface< SequenceType, std::string > &sc)
void setSequence(size_t sequencePosition, std::unique_ptr< SequenceType > &sequence, const std::string &sequenceKey) override
Replace a sequence in the container.
const SequenceType & sequence(size_t sequencePosition) const override
Retrieve a sequence object from the container.
void deleteSites(size_t sitePosition, size_t length) override
Remove a continuous range of sites in the container.
void setSequence(const std::string &sequenceKey, std::unique_ptr< SequenceType > &sequence) override
Replace a sequence in the container.
TemplateVectorSiteContainer(const std::vector< std::string > &sequenceKeys, std::shared_ptr< const Alphabet > alphabet, bool useKeysAsNames=true)
Build a new empty container with specified sequence keys.
TemplateVectorSiteContainer(size_t size, std::shared_ptr< const Alphabet > alphabet)
Build a new empty container with specified size.
void clear() override
Delete all data in the container.
void setSiteCoordinates(const Vint &vCoordinates) override
Set all coordinates of sites.
void deleteSite(size_t sitePosition) override
Delete a site from the container.
size_t getSequencePosition(const std::string &sequenceKey) const override
Get the position of a sequence with a given key in the container.
void deleteSequence(const std::string &sequenceKey) override
Remove and delete a sequence from the container.
size_t getNumberOfSequences() const override
Get the number of sequences in the container.
TemplateVectorSiteContainer< SiteType, SequenceType > & operator=(const TemplateVectorSiteContainer< SiteType, SequenceType > &vsc)
bool hasSequence(const std::string &sequenceKey) const override
Check if a certain key is associated to a sequence in the container.
size_t getNumberOfSites() const override
Get the number of aligned positions in the container.
std::unique_ptr< SiteType > removeSite(size_t sitePosition) override
Remove a site from the container.
double operator()(size_t sitePosition, const std::string &sequenceKey, int state) const override
Get the value of a state at a given position.
SiteType & site_(size_t sitePosition)
std::vector< std::string > getSequenceNames() const override
std::unique_ptr< SequenceType > removeSequence(const std::string &sequenceKey) override
Remove a sequence from the container.
const std::string & sequenceKey(size_t sequencePosition) const override
Get the key associated to a given sequence.
void setSequenceNames(const std::vector< std::string > &names, bool updateKeys) override
Batch-set all sequence names.
std::vector< Comments > sequenceComments_
const SequenceType::ElementType & valueAt(size_t sequencePosition, size_t sitePosition) const override
Get the content of the dataset at a specific position (sequence position, site position).
void addObject(std::shared_ptr< T > newObject, size_t objectIndex, const std::string &name, bool check=false) override
void insertObject(std::shared_ptr< T > newObject, size_t objectIndex, const std::string &name) override
void deleteObject(size_t objectIndex) override
Delete an object from the container.
virtual void appendObject(std::shared_ptr< T > newObject, const std::string &name, bool checkNames=true)
void clear() override
Delete all objects in the container.
void addObject_(std::shared_ptr< T > newObject, size_t objectIndex, const std::string &name, bool check=false) const
const std::string & getObjectName(size_t objectIndex) const override
std::vector< std::string > getObjectNames() const override
void nullify() override
Nullify all elements.
size_t getObjectPosition(const std::string &name) const override
Link between position & name.
void setObjectNames(const std::vector< std::string > &names)
std::shared_ptr< T > removeObject(size_t objectIndex) override
Extract and remove a object from the container.
std::shared_ptr< T > removeObject(size_t objectIndex) override
Extract and remove a object from the container.
size_t getSize() const override
the size
const std::shared_ptr< T > getObject(size_t objectIndex) const override
Retrieve an object from the container.
void deleteObject(size_t objectIndex) override
Delete an object from the container.
void appendObject(std::shared_ptr< T > object)
void addObject(std::shared_ptr< T > object, size_t objectIndex, bool checkPosition=false)
Add an object.
void insertObject(std::shared_ptr< T > object, size_t objectIndex)
Insert an object.
void deleteObjects(size_t objectIndex, size_t length)
void clear() override
Destroys the vector.
std::string toString(T t)
This alphabet is used to deal NumericAlphabet.
std::vector< int > Vint