5 #ifndef BPP_SEQ_CONTAINER_VECTORSEQUENCECONTAINER_H
6 #define BPP_SEQ_CONTAINER_VECTORSEQUENCECONTAINER_H
10 #include "../Alphabet/Alphabet.h"
11 #include "../Sequence.h"
12 #include "../ProbabilisticSequence.h"
29 template<
class SequenceType>
46 std::shared_ptr<const Alphabet>
alphabet,
47 std::vector<std::unique_ptr<SequenceType>>& vs) :
51 for (
auto& seqPtr : vs)
84 for (
size_t i = 0; i < max; ++i)
86 auto seqPtr = std::unique_ptr<SequenceType>(vsc.
sequence(i).clone());
102 for (
size_t i = 0; i < max; ++i)
104 auto seqPtr = std::unique_ptr<SequenceType>(sc.
sequence(i).clone());
123 for (
size_t i = 0; i < max; ++i)
125 auto seqPtr = std::unique_ptr<SequenceType>(vsc.
sequence(i).clone());
141 for (
size_t i = 0; i < max; ++i)
143 auto seqPtr = std::unique_ptr<SequenceType>(sc.
sequence(i).clone());
194 double getStateValueAt(
size_t sitePosition,
size_t sequencePosition,
int state)
const override
196 return sequence(sequencePosition).getStateValueAt(sitePosition, state);
199 double operator()(
size_t sitePosition,
size_t sequencePosition,
int state)
const override
201 return sequence(sequencePosition)(sitePosition, state);
219 const std::string&
sequenceKey(
size_t sequencePosition)
const override
229 const typename SequenceType::ElementType&
valueAt(
const std::string&
sequenceKey,
size_t elementPosition)
const override
234 typename SequenceType::ElementType&
valueAt(
const std::string&
sequenceKey,
size_t elementPosition)
override
239 const typename SequenceType::ElementType&
valueAt(
size_t sequencePosition,
size_t elementPosition)
const override
241 return sequence(sequencePosition)[elementPosition];
244 typename SequenceType::ElementType&
valueAt(
size_t sequencePosition,
size_t elementPosition)
override
246 return sequence_(sequencePosition)[elementPosition];
266 if (sequencePtr->getAlphabet()->getAlphabetType() !=
getAlphabet()->getAlphabetType())
276 std::get_deleter<SwitchDeleter<SequenceType>, SequenceType>(ptr)->off();
277 return std::unique_ptr<SequenceType>(ptr.get());
290 const SequenceType&
sequence(
size_t sequencePosition)
const override
295 void setSequence(
size_t sequencePosition, std::unique_ptr<SequenceType>& sequencePtr)
override
297 if (sequencePtr->getAlphabet()->getAlphabetType() !=
getAlphabet()->getAlphabetType())
303 void setSequence(
size_t sequencePosition, std::unique_ptr<SequenceType>& sequencePtr,
const std::string&
sequenceKey)
override
305 if (sequencePtr->getAlphabet()->getAlphabetType() !=
getAlphabet()->getAlphabetType())
313 if (sequencePtr->getAlphabet()->getAlphabetType() !=
getAlphabet()->getAlphabetType())
322 std::get_deleter<SwitchDeleter<SequenceType>, SequenceType>(ptr)->off();
323 return std::unique_ptr<SequenceType>(ptr.get());
330 std::vector<std::string> vs(nbSeq);
331 for (
size_t i = 0; i < nbSeq; ++i)
342 for (
size_t i = 0; i < names.size(); ++i)
355 std::vector<Comments> vs(nbSeq);
356 for (
size_t i = 0; i < nbSeq; ++i)
371 virtual void addSequence(std::unique_ptr<SequenceType>& sequencePtr)
377 virtual SequenceType&
sequence_(
size_t sequencePosition)
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.
const T & object(const std::string &name) const override
bool hasObject(const std::string &name) const override
Check if a object with a given name is present in the container.
const std::shared_ptr< T > getObject(const std::string &name) const override
Retrieve an object from the container.
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.
virtual const HashType & sequenceKey(size_t sequencePosition) const =0
Get the key associated to a given sequence.
The VectorSequenceContainer class.
VectorMappedContainer< SequenceType > sequenceVectorMap_
bool hasSequence(const std::string &sequenceKey) const override
Check if a certain key is associated to a sequence in the container.
const SequenceType & sequence(size_t sequencePosition) const override
Retrieve a sequence object from the container.
void setSequenceKeys(const std::vector< std::string > &sequenceKeys) override
Reset all sequence keys.
SequenceType::ElementType & valueAt(size_t sequencePosition, size_t elementPosition) override
Get the content of the dataset at a specific position (sequence position, site position).
virtual ~TemplateVectorSequenceContainer()
void addSequence(const std::string &sequenceKey, std::unique_ptr< SequenceType > &sequencePtr) override
Add a sequence to the container.
void setSequence(size_t sequencePosition, std::unique_ptr< SequenceType > &sequencePtr) override
Replace a sequence in the container.
TemplateVectorSequenceContainer & operator=(const TemplateSequenceContainerInterface< SequenceType, std::string > &sc)
Copy from a SequenceContainer.
const SequenceType::ElementType & valueAt(size_t sequencePosition, size_t elementPosition) const 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.
double operator()(size_t sitePosition, size_t sequencePosition, int state) const override
Get the value of a state at a given position.
TemplateVectorSequenceContainer(std::shared_ptr< const Alphabet > alphabet)
Build an empty container that will contain sequences of a particular alphabet.
virtual SequenceType & sequence_(const std::string &sequenceKey)
getSequence with given key
void clear() override
Delete all data in the container.
void deleteSequence(size_t sequencePosition) override
Remove and delete a sequence from the container.
TemplateVectorSequenceContainer< SequenceType > * clone() const override
std::unique_ptr< SequenceType > removeSequence(size_t sequencePosition) override
Remove a sequence from the container.
TemplateVectorSequenceContainer & operator=(const TemplateVectorSequenceContainer &vsc)
Assign from a VectorSequenceContainer.
double operator()(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 > &sequencePtr, const std::string &sequenceKey) override
Replace a sequence in the container.
std::vector< std::string > getSequenceNames() const override
TemplateVectorSequenceContainer(const TemplateSequenceContainerInterface< SequenceType, std::string > &sc)
Copy from a SequenceContainer.
std::vector< Comments > getSequenceComments() const override
virtual void addSequence(std::unique_ptr< SequenceType > &sequencePtr)
Add a sequence to the container, using its name as a key.
const SequenceType::ElementType & valueAt(const std::string &sequenceKey, size_t elementPosition) const override
Get the content of the dataset at a specific position (sequence key, site position).
double getStateValueAt(size_t sitePosition, size_t sequencePosition, int state) const override
Get value of a state at a given position.
TemplateVectorSequenceContainer< SequenceType > * createEmptyContainer() const override
Return a copy of this container, but with no data inside.
TemplateVectorSequenceContainer(std::shared_ptr< const Alphabet > alphabet, std::vector< std::unique_ptr< SequenceType >> &vs)
Build a container with pointers to sequence objects.
TemplateVectorSequenceContainer(const TemplateVectorSequenceContainer< SequenceType > &vsc)
Copy from a VectorSequenceContainer.
size_t getSequencePosition(const std::string &sequenceKey) const override
Get the position of a sequence with a given key in the container.
size_t getNumberOfSequences() const override
Get the number of sequences in the container.
std::vector< std::string > getSequenceKeys() const override
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.
SequenceType::ElementType & valueAt(const std::string &sequenceKey, size_t elementPosition) override
Get the content of the dataset at a specific position (sequence key, site position).
void setSequenceNames(const std::vector< std::string > &names, bool updateKeys) override
Batch-set all sequence names.
const SequenceType & sequence(const std::string &sequenceKey) const override
Retrieve a sequence object from the container.
std::unique_ptr< SequenceType > removeSequence(const std::string &sequenceKey) override
Remove a sequence from the container.
void deleteSequence(const std::string &sequenceKey) override
Remove and delete a sequence from the container.
virtual SequenceType & sequence_(size_t sequencePosition)
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.
const std::string & getObjectName(size_t objectIndex) const override
std::vector< std::string > getObjectNames() const override
size_t getObjectPosition(const std::string &name) const override
Link between position & name.
void setObjectNames(const std::vector< std::string > &names)
size_t getSize() const override
Get the number of objects in the container.
std::shared_ptr< T > removeObject(size_t objectIndex) override
Extract and remove a object from the container.
This alphabet is used to deal NumericAlphabet.