5 #ifndef BPP_SEQ_CONTAINER_ALIGNEDSEQUENCECONTAINER_H
6 #define BPP_SEQ_CONTAINER_ALIGNEDSEQUENCECONTAINER_H
11 #include "../SiteTools.h"
12 #include "../ProbabilisticSite.h"
13 #include "../Sequence.h"
14 #include "../ProbabilisticSequence.h"
38 template<
class SequenceType,
class SiteType>
61 std::shared_ptr<const Alphabet>
alphabet,
62 std::vector< std::unique_ptr<Sequence>> vs) :
72 for (
const auto& seq: vs)
76 throw BadSizeException(
"AlignedSequenceContainer: sequences of different sizes in aligned construction",
length_, seq->size());
212 const SiteType&
site(
size_t sitePosition)
const override
225 auto site = std::shared_ptr<SiteType>(
229 for (
size_t j = 0; j < n; j++)
238 void setSite(
size_t sitePosition, std::unique_ptr<SiteType>&
site,
bool checkCoordinate =
true)
override
243 if (
site->getAlphabet()->getAlphabetType() !=
getAlphabet()->getAlphabetType())
248 throw SiteException(
"AlignedSequenceContainer::setSite, site does not have the appropriate length",
site.get());
253 int coordinate =
site->getCoordinate();
258 throw SiteException(
"AlignedSequenceContainer::setSite: Site position already exists in container",
site.get());
275 std::unique_ptr<SiteType>
removeSite(
size_t sitePosition)
override
286 sequence_(j).deleteElement(sitePosition);
295 std::get_deleter< SwitchDeleter<SiteType>>(sitePtr)->off();
296 return std::unique_ptr<SiteType>(sitePtr.get());
308 sequence_(j).deleteElement(sitePosition);
328 sequence_(j).deleteElements(sitePosition, length);
333 coordinates_.begin() +
static_cast<ptrdiff_t
>(sitePosition + length));
341 void addSite(std::unique_ptr<SiteType>&
site,
bool checkCoordinate =
true)
override
344 if (
site->getAlphabet()->getAlphabetType() !=
getAlphabet()->getAlphabetType())
349 throw SiteException(
"AlignedSequenceContainer::addSite, site does not have the appropriate length",
site.get());
352 int coordinate =
site->getCoordinate();
359 throw SiteException(
"AlignedSequenceContainer::addSite: Site coordinate already exists in container",
site.get());
376 void addSite(std::unique_ptr<SiteType>&
site,
size_t sitePosition,
bool checkCoordinate =
true)
override
382 if (
site->getAlphabet()->getAlphabetType() !=
getAlphabet()->getAlphabetType())
387 throw SiteException(
"AlignedSequenceContainer::addSite, site does not have the appropriate length",
site.get());
390 int coordinate =
site->getCoordinate();
397 throw SiteException(
"AlignedSequenceContainer::addSite: Site coordinate already exists in container",
site.get());
440 for (
size_t i = 0; i < vCoordinates.size(); ++i)
450 for (
size_t i = 0; i <
length_; ++i)
491 void setSequence(
size_t sequencePosition, std::unique_ptr<SequenceType>& sequencePtr)
override
508 void setSequence(
size_t sequencePosition, std::unique_ptr<SequenceType>& sequencePtr,
const std::string&
sequenceKey)
override
552 typename SequenceType::ElementType&
valueAt(
const std::string&
sequenceKey,
size_t sitePosition)
override
559 typename SequenceType::ElementType&
valueAt(
const size_t sequencePosition,
size_t sitePosition)
override
563 return sequence_(sequencePosition)[sitePosition];
const Alphabet & alphabet() const override
std::shared_ptr< const Alphabet > getAlphabet() const override
size_t size() const override
Get the number of elements in the list.
Exception thrown when two alphabets do not match.
Exception thrown when a sequence is not align with others.
A basic implementation of the Sequence interface.
The site exception base class.
The AlignedSequencesContainer class.
TemplateAlignedSequenceContainer(std::shared_ptr< const Alphabet > alphabet)
Build a new empty container with the specified alphabet.
void insertSequence(size_t sequencePosition, std::unique_ptr< SequenceType > &sequencePtr, const std::string &sequenceKey) override
Insert a sequence in the container.
Vint getSiteCoordinates() const override
Get all coordinates of sites.
virtual ~TemplateAlignedSequenceContainer()
void setSequence(size_t sequencePosition, std::unique_ptr< SequenceType > &sequencePtr, const std::string &sequenceKey) override
Replace a sequence in the container.
std::unique_ptr< SiteType > removeSite(size_t sitePosition) override
Remove a site from the container.
TemplateAlignedSequenceContainer & operator=(const TemplateSequenceContainerInterface< SequenceType, std::string > &sc)
TemplateAlignedSequenceContainer(const TemplateAlignedSequenceContainer< SequenceType, SiteType > &asc)
Copy constructor.
SequenceType::ElementType & valueAt(const size_t sequencePosition, size_t sitePosition) override
Get the content of the dataset at a specific position (sequence position, site position).
void clear() override
Delete all data in the container.
size_t getNumberOfSites() const override
Get the number of aligned positions in the container.
void deleteSites(size_t sitePosition, size_t length) override
Remove a continuous range of sites in the container.
void setSequence(size_t sequencePosition, std::unique_ptr< SequenceType > &sequencePtr) override
Replace a sequence in the container.
TemplateAlignedSequenceContainer< SequenceType, SiteType > & operator=(const TemplateSiteContainerInterface< SiteType, SequenceType, std::string > &sc)
VectorPositionedContainer< SiteType > siteVector_
TemplateAlignedSequenceContainer(std::shared_ptr< const Alphabet > alphabet, std::vector< std::unique_ptr< Sequence >> vs)
Build a container with pointers to sequence objects.
void deleteSite(size_t sitePosition) override
Delete a site from the container.
bool checkSize_(const Sequence &sequenceRef)
Check sequence's size before insertion in sequence container.
TemplateAlignedSequenceContainer< SequenceType, SiteType > * clone() const override
void setSite(size_t sitePosition, std::unique_ptr< SiteType > &site, bool checkCoordinate=true) override
Set a site in 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).
std::vector< int > coordinates_
TemplateAlignedSequenceContainer & operator=(const TemplateAlignedSequenceContainer< SequenceType, SiteType > &asc)
TemplateAlignedSequenceContainer(const TemplateSiteContainerInterface< SiteType, SequenceType, std::string > &sc)
Convert any SiteContainer object into a AlignedSequenceContainer object.
TemplateAlignedSequenceContainer(const TemplateSequenceContainerInterface< SequenceType, std::string > &sc)
Try to coerce a SequenceContainer object into an AlignedSequenceContainer object.
void setSiteCoordinates(const Vint &vCoordinates) override
Set all coordinates of sites.
void addSite(std::unique_ptr< SiteType > &site, bool checkCoordinate=true) override
Add 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.
void addSequence(const std::string &sequenceKey, std::unique_ptr< SequenceType > &sequencePtr) override
Add a sequence to the container.
TemplateAlignedSequenceContainer * createEmptyContainer() const override
Return a copy of this container, but with no data inside.
const SiteType & site(size_t sitePosition) const override
Get a site from the container.
void reindexSites() override
Set all coordinate attributes.
void setSequence(const std::string &sequenceKey, std::unique_ptr< SequenceType > &sequencePtr) override
Replace a sequence in the container.
virtual Vint getSiteCoordinates() const =0
Get all coordinates of sites.
virtual const SequenceType & sequence(const HashType &sequenceKey) const override=0
Retrieve a sequence object from the container.
virtual size_t getNumberOfSequences() const =0
Get the number of sequences in the container.
The SiteContainer interface.
virtual size_t getNumberOfSites() const override=0
Get the number of aligned positions in the container.
The VectorSequenceContainer class.
void addSequence(const std::string &sequenceKey, std::unique_ptr< SequenceType > &sequencePtr) override
Add a sequence to the container.
void clear() override
Delete all data in the container.
TemplateVectorSequenceContainer & operator=(const TemplateVectorSequenceContainer &vsc)
Assign from a VectorSequenceContainer.
size_t getNumberOfSequences() const override
Get the number of sequences in the container.
void setSequence(const std::string &sequenceKey, std::unique_ptr< SequenceType > &sequencePtr) override
Replace a sequence in the container.
const std::string & sequenceKey(size_t sequencePosition) const override
Get the key associated to a given sequence.
void insertSequence(size_t sequencePosition, std::unique_ptr< SequenceType > &sequencePtr, const std::string &sequenceKey) override
Insert a sequence in the container.
const SequenceType & sequence(const std::string &sequenceKey) const override
Retrieve a sequence object from the container.
virtual SequenceType & sequence_(size_t sequencePosition)
void setSize(size_t size) override
std::shared_ptr< T > removeObject(size_t objectIndex) override
Extract and remove a object from the container.
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)
bool hasObjectWithPosition(size_t objectIndex) const
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 addObject_(std::shared_ptr< T > object, size_t objectIndex, bool checkPosition=false) const
virtual void nullify()
Nullify all elements.
void deleteObjects(size_t objectIndex, size_t length)
void clear() override
Destroys the vector.
This alphabet is used to deal NumericAlphabet.