5 #ifndef BPP_SEQ_CONTAINER_VECTORSITECONTAINER_H
6 #define BPP_SEQ_CONTAINER_VECTORSITECONTAINER_H
40 template<
class SiteType,
class SequenceType>
61 std::vector<std::unique_ptr<SiteType>>& vs,
62 std::shared_ptr<const Alphabet>
alphabet,
63 bool checkPositions =
true) :
71 throw Exception(
"VectorSiteContainer::VectorSiteContainer. Empty site set.");
73 size_t nbSeq = vs[0]->size();
75 for (
size_t i = 0; i < nbSeq; ++i)
96 std::shared_ptr<const Alphabet>
alphabet) :
103 for (
size_t i = 0; i < size; ++i)
119 const std::vector<std::string>& sequenceKeys,
120 std::shared_ptr<const Alphabet>
alphabet,
121 bool useKeysAsNames =
true) :
131 for (
auto key : sequenceKeys)
140 for (
auto key : sequenceKeys)
178 auto sitePtr = std::unique_ptr<SiteType>(vsc.
site(i).clone());
198 std::unique_ptr<SiteType> sitePtr(sc.
site(i).clone());
228 auto sitePtr = std::make_unique<SiteType>(vsc.
site(i));
250 auto sitePtr = std::make_unique<SiteType>(sc.
site(i));
296 const SiteType&
site(
size_t sitePosition)
const override
301 void setSite(
size_t sitePosition, std::unique_ptr<SiteType>&
site,
bool checkCoordinate =
true)
override
309 throw SiteException(
"TemplateVectorSiteContainer::setSite. Site does not have the appropriate length",
site.get());
313 if (
site->getAlphabet()->getAlphabetType() !=
getAlphabet()->getAlphabetType())
319 int coordinate =
site->getCoordinate();
323 if (i != sitePosition && this->
site(i).getCoordinate() == coordinate)
325 throw SiteException(
"TemplateVectorSiteContainer::setSite: Site position already exists in container",
site.get());
337 std::unique_ptr<SiteType>
removeSite(
size_t sitePosition)
override
343 std::get_deleter< SwitchDeleter<SiteType>>(sitePtr)->off();
344 return std::unique_ptr<SiteType>(sitePtr.get());
355 void addSite(std::unique_ptr<SiteType>&
site,
bool checkCoordinate =
true)
override
359 throw SiteException(
"TemplateVectorSiteContainer::addSite. Site does not have the appropriate length",
site.get());
362 if (
site->getAlphabet()->getAlphabetType() !=
getAlphabet()->getAlphabetType())
368 int coordinate =
site->getCoordinate();
372 if (this->
site(i).getCoordinate() == coordinate)
373 throw SiteException(
"TemplateVectorSiteContainer::addSite(site, bool): Site position already exists in container",
site.get());
385 for (
size_t i = 0; i < sitePtr->size(); ++i)
398 void addSite(std::unique_ptr<SiteType>&
site,
size_t sitePosition,
bool checkCoordinate =
true)
override
405 throw SiteException(
"TemplateVectorSiteContainer::addSite. Site does not have the appropriate length",
site.get());
408 if (
site->getAlphabet()->getAlphabetType() !=
getAlphabet()->getAlphabetType())
414 int coordinate =
site->getCoordinate();
418 if (i != sitePosition && this->
site(i).getCoordinate() == coordinate)
419 throw SiteException(
"TemplateVectorSiteContainer::addSite. Site coordinate already exists in container",
site.get());
431 for (
size_t i = 0; i < sitePtr->size(); ++i)
458 site_(i).setCoordinate(
static_cast<int>(i) + 1);
467 coordinates[i] =
site(i).getCoordinate();
479 site_(i).setCoordinate(vCoordinates[i]);
509 const SequenceType&
sequence(
size_t sequencePosition)
const override
523 std::vector<typename SequenceType::SymbolType>
sequence(n);
524 for (
size_t j = 0; j < n; ++j)
530 auto ns = std::shared_ptr<SequenceType>(
550 site_(i).deleteElement(sequencePosition);
553 auto d =
static_cast<std::vector<std::string>::difference_type
>(sequencePosition);
558 std::get_deleter<SwitchDeleter<SequenceType>>(seq)->off();
559 std::unique_ptr<SequenceType> seq2(seq.get());
574 site_(i).deleteElement(sequencePosition);
577 auto posN =
static_cast<std::vector<std::string>::difference_type
>(sequencePosition);
579 auto posC =
static_cast<std::vector<Comments>::difference_type
>(sequencePosition);
607 const std::string&
sequenceKey(
size_t sequencePosition)
const override
650 const typename SequenceType::ElementType&
valueAt(
const std::string&
sequenceKey,
size_t sitePosition)
const override
655 typename SequenceType::ElementType&
valueAt(
const std::string&
sequenceKey,
size_t sitePosition)
override
660 return this->
site_(sitePosition)[sequencePosition];
663 const typename SequenceType::ElementType&
valueAt(
size_t sequencePosition,
size_t sitePosition)
const override
665 return site(sitePosition)[sequencePosition];
668 typename SequenceType::ElementType&
valueAt(
size_t sequencePosition,
size_t sitePosition)
override
672 return site_(sitePosition)[sequencePosition];
685 double getStateValueAt(
size_t sitePosition,
size_t sequencePosition,
int state)
const override
687 return site(sitePosition).getStateValueAt(sequencePosition, state);
690 double operator()(
size_t sitePosition,
size_t sequencePosition,
int state)
const override
692 return site(sitePosition).getStateValueAt(sequencePosition, state);
724 site_(i).addElement(sequencePosition,
sequence->getValue(i));
777 site_(i).addElement(sequencePosition,
sequence->getValue(i));
801 SiteType&
site_(
size_t sitePosition)
810 std::shared_ptr<const Alphabet> alphaPtr =
getAlphabet();
811 SiteType s(alphaPtr);
813 for (
size_t i = 0; i < n; ++i)
815 std::unique_ptr<SiteType> sitePtr(s.clone());
Partial implementation of the SequenceContainer interface.
AbstractTemplateSequenceContainer & operator=(const AbstractTemplateSequenceContainer< SequenceType, HashType > &sc)
const Alphabet & alphabet() const override
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.
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.
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.
virtual ~TemplateVectorSiteContainer()
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)
size_t getNumberOfObjects() const
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.