42 #include <Bpp/Text/TextTools.h> 50 const std::vector<const Sequence*>& vs,
56 for (std::vector<const Sequence*>::const_iterator i = vs.begin(); i < vs.end(); i++)
70 for (
size_t i = 0; i < max; i++)
95 for (
unsigned int i = 0; i < names.size(); i++)
113 for (
size_t i = 0; i < max; i++)
129 for (
unsigned int i = 0; i < max; i++)
148 for (
unsigned int i = 0; i < names.size(); i++)
161 if (sequenceIndex < sequences_.size())
162 return *sequences_[sequenceIndex];
163 throw IndexOutOfBoundsException(
"VectorSequenceContainer::getSequence.", sequenceIndex, 0, sequences_.size() - 1);
171 for (
size_t i = 0; i <
sequences_.size(); i++)
184 for (
size_t i = 0; i < sequences_.size(); i++)
186 if (sequences_[i]->getName() == name)
187 return *sequences_[i];
197 if (sequenceIndex < sequences_.size())
198 return *sequences_[sequenceIndex];
199 throw IndexOutOfBoundsException(
"VectorSequenceContainer::getSequence.", sequenceIndex, 0, sequences_.size() - 1);
207 for (
size_t i = 0; i < sequences_.size(); i++)
209 if (sequences_[i]->getName() == name)
210 return *sequences_[i];
220 for (
size_t i = 0; i < sequences_.size(); i++)
222 if (sequences_[i]->getName() == name)
225 throw SequenceNotFoundException(
"VectorSequenceContainer::getSequencePosition : Specified sequence doesn't exist", name);
236 for (
size_t j = 0; j < sequences_.size(); j++)
238 if (sequences_[j]->getName() == sequence.getName())
239 if (j != sequenceIndex)
240 throw Exception(
"VectorSequenceContainer::setSequence : Sequence's name already exists in container");
245 if (sequence.getAlphabet()->getAlphabetType() == getAlphabet()->getAlphabetType())
248 delete sequences_[sequenceIndex];
250 sequences_[sequenceIndex] =
dynamic_cast<Sequence*
>(sequence.clone());
253 throw AlphabetMismatchException(
"VectorSequenceContainer::setSequence : Alphabets don't match", getAlphabet(), sequence.getAlphabet());
261 if (sequenceIndex >= sequences_.size())
262 throw IndexOutOfBoundsException(
"VectorSequenceContainer::removeSequence.", sequenceIndex, 0, sequences_.size() - 1);
263 Sequence* old = sequences_[sequenceIndex];
265 sequences_.erase(sequences_.begin() +
static_cast<ptrdiff_t
>(sequenceIndex));
275 if (sequenceIndex >= sequences_.size())
276 throw IndexOutOfBoundsException(
"VectorSequenceContainer::deleteSequence.", sequenceIndex, 0, sequences_.size() - 1);
277 delete sequences_[sequenceIndex];
279 sequences_.erase(sequences_.begin() +
static_cast<ptrdiff_t
>(sequenceIndex));
290 for (
size_t i = 0; i < sequences_.size(); i++)
292 if (sequences_[i]->getName() == sequence.getName())
293 throw Exception(
"VectorSequenceContainer::addSequence : Sequence '" + sequence.getName() +
"' already exists in container");
298 if (sequence.getAlphabet()->getAlphabetType() == getAlphabet()->getAlphabetType())
301 sequences_.push_back(dynamic_cast<Sequence*>(sequence.clone()));
304 throw AlphabetMismatchException(
"VectorSequenceContainer::addSequence : Alphabets don't match", getAlphabet(), sequence.getAlphabet());
313 for (
size_t i = 0; i < sequences_.size(); i++)
315 if (sequences_[i]->getName() == sequence.getName())
316 throw Exception(
"VectorSequenceContainer::addSequence : Sequence '" + sequence.getName() +
"' already exists in container");
321 if (sequence.getAlphabet()->getAlphabetType() == getAlphabet()->getAlphabetType())
324 sequences_.insert(sequences_.begin() +
static_cast<ptrdiff_t
>(sequenceIndex), dynamic_cast<Sequence*>(sequence.clone()));
327 throw AlphabetMismatchException(
"VectorSequenceContainer::addSequence : Alphabets don't match", getAlphabet(), sequence.getAlphabet());
334 std::vector<std::string> names;
335 for (
size_t i = 0; i <
sequences_.size(); i++)
345 const std::vector<std::string>& names,
349 if (names.size() != getNumberOfSequences())
350 throw IndexOutOfBoundsException(
"VectorSequenceContainer::setSequenceNames : bad number of names", names.size(), getNumberOfSequences(), getNumberOfSequences());
353 for (
size_t i = 0; i < names.size(); i++)
356 for (
size_t j = 0; j < i; j++)
358 if (names[j] == names[i])
359 throw Exception(
"VectorSiteContainer::setSequencesNames : Sequence's name already exists in container");
363 for (
size_t i = 0; i < names.size(); i++)
365 sequences_[i]->setName(names[i]);
374 for (
size_t i = 0; i <
sequences_.size(); i++)
386 sequences_[sequenceIndex]->setComments(comments);
size_t getNumberOfSequences() const
Get the number of sequences in the container.
Exception thrown when a sequence is not found The sequence not found exception base class...
bool hasSequence(const std::string &name) const
Check if a sequence with a given name is present in the container.
VectorSequenceContainer & operator=(const VectorSequenceContainer &vsc)
Assign from a VectorSequenceContainer.
void setComments(const std::string &name, const Comments &comments)
Set the comments of a particular sequence.
std::vector< std::string > Comments
Declaration of Comments type.
void deleteSequence(const std::string &name)
Delete a sequence of the container.
The OrderedSequenceContainer interface.
This alphabet is used to deal NumericAlphabet.
const Alphabet * getAlphabet() const
Get sequence container's alphabet.
std::vector< Sequence * > sequences_
A std::vector of pointers toward the sequences stored in the container.
The VectorSequenceContainer class.
AbstractSequenceContainer & operator=(const AbstractSequenceContainer &sc)
Partial implementation of the OrderedSequenceContainer interface.
const Comments & getGeneralComments() const
Get the comments of this container.
virtual void addSequence(const Sequence &sequence, bool checkName=true)
Add a sequence at the end of the container.
virtual const Sequence & getSequence(size_t sequenceIndex) const =0
Retrieve a sequence object from the container.
void setSequence(const std::string &name, const Sequence &sequence, bool checkName=true)
Replace a sequence in the container.
virtual const Comments & getGeneralComments() const =0
Get the comments of this container.
void setSequencesNames(const std::vector< std::string > &names, bool checkNames=true)
Set all sequence names.
const Sequence & getSequence(const std::string &name) const
Retrieve a sequence object from the container.
Sequence * removeSequence(const std::string &name)
Extract (and remove) a sequence from the container.
virtual const Sequence & getSequence(const std::string &name) const =0
Retrieve a sequence object from the container.
virtual const std::string & getName(size_t sequenceIndex) const
Get the name of a particular sequence.
size_t getSequencePosition(const std::string &name) const
Get the position of a sequence in sequence container from its name.
virtual std::vector< std::string > getSequencesNames() const =0
Get all the names of the sequences in the container.
void clear()
Delete all sequences in the container.
std::vector< std::string > getSequencesNames() const
Get all the names of the sequences in the container.
Exception thrown when two alphabets do not match.
Sequence & getSequence_(size_t i)
VectorSequenceContainer(const std::vector< const Sequence *> &vs, const Alphabet *alpha)
Build a new container from a std::vector of pointers toward sequence objects.
VectorSequenceContainer * createEmptyContainer() const
Return a copy of this container, but with no sequence inside.
The SequenceContainer interface.
void setGeneralComments(const Comments &comments)
Set the comments of this container.
virtual size_t getNumberOfSequences() const =0
Get the number of sequences in the container.