43 #include <Bpp/Text/TextTools.h> 53 for (map<string, Sequence*>::const_iterator it = ms.begin(); it != ms.end(); it++)
76 vector<string> keys = msc.
getKeys();
97 if (i < sequences_.size())
99 map<string, Sequence*>::const_iterator it = sequences_.begin();
100 for (
unsigned int j = 0; j < i; j++) it++;
103 throw IndexOutOfBoundsException(
"MapSequenceContainer::getSequence", i, 0, sequences_.size() - 1);
111 for (map<string, Sequence*>::const_iterator it = sequences_.begin(); it != sequences_.end(); it++)
112 if (it->second->getName() == name)
122 for (map<string, Sequence*>::const_iterator it =
sequences_.begin(); it !=
sequences_.end(); it++)
123 if (it->second->getName() == name)
132 if (i >= sequences_.size())
133 throw IndexOutOfBoundsException(
"MapSequenceContainer::getSequence", i, 0, sequences_.size() - 1);
134 map<string, Sequence*>::iterator it = sequences_.begin();
135 for (
size_t j = 0; j < i; j++) it++;
144 for (map<string, Sequence*>::iterator it = sequences_.begin(); it != sequences_.end(); it++)
145 if (it->second->getName() == name)
155 map<string, Sequence*>::const_iterator it = sequences_.find(key);
156 if (it == sequences_.end())
168 for (map<string, Sequence*>::const_iterator it = sequences_.begin(); it != sequences_.end(); it++)
170 if (it->second->getName() == name)
return pos;
180 throw (IndexOutOfBoundsException)
187 for (map<string, Sequence*>::const_iterator it = sequences_.begin(); it != sequences_.end(); it++)
189 if (it->second->getName() == sequence.getName())
190 if (j != i)
throw Exception(
"MapSequenceContainer::setSequence : Sequence's name already exists in container");
196 if (sequence.getAlphabet()->getAlphabetType() == getAlphabet()->getAlphabetType())
199 delete sequences_[getKey(i)];
201 sequences_[getKey(i)] =
dynamic_cast<Sequence*
>(sequence.clone());
215 for (map<string, Sequence*>::const_iterator it = sequences_.begin(); it != sequences_.end(); it++)
217 if (it->second->getName() == name)
218 if (it->second->getName() != name)
219 throw Exception(
"MapSequenceContainer::setSequence : Sequence's name already exists in container");
224 if (sequence.getAlphabet()->getAlphabetType() == getAlphabet()->getAlphabetType())
227 delete sequences_[name];
229 sequences_[name] =
dynamic_cast<Sequence*
>(sequence.clone());
243 for (map<string, Sequence*>::const_iterator it = sequences_.begin(); it != sequences_.end(); it++)
245 if (it->second->getName() == sequence.getName())
246 if (it->first != key)
247 throw Exception(
"MapSequenceContainer::setSequenceByKey : Sequence's name already exists in container");
252 if (sequence.getAlphabet()->getAlphabetType() == getAlphabet()->getAlphabetType())
255 delete sequences_[key];
257 sequences_[key] =
dynamic_cast<Sequence*
>(sequence.clone());
267 if (i >= sequences_.size())
268 throw IndexOutOfBoundsException(
"MapSequenceContainer::removeSequence", i, 0, sequences_.size() - 1);
269 map<string, Sequence*>::iterator it = sequences_.begin();
270 for (
size_t j = 0; j < i; j++) it++;
272 sequences_.erase(it);
280 for (map<string, Sequence*>::iterator it = sequences_.begin(); it != sequences_.end(); it++) {
281 if (it->second->getName() == name)
284 sequences_.erase(it);
295 map<string, Sequence*>::iterator it = sequences_.find(key);
296 if (it == sequences_.end())
300 sequences_.erase(key);
308 if (i >= sequences_.size())
309 throw IndexOutOfBoundsException(
"MapSequenceContainer::deleteSequence", i, 0, sequences_.size() - 1);
310 map<string, Sequence*>::iterator it = sequences_.begin();
311 for (
size_t j = 0; j < i; j++) it++;
313 sequences_.erase(it);
320 for (map<string, Sequence*>::iterator it = sequences_.begin(); it != sequences_.end(); it++) {
321 if (it->second->getName() == name)
324 sequences_.erase(it);
335 map<string, Sequence*>::iterator it = sequences_.find(key);
336 if (it == sequences_.end())
339 sequences_.erase(key);
350 for (map<string, Sequence*>::const_iterator it = sequences_.begin(); it != sequences_.end(); it++)
352 if (it->second->getName() == sequence.getName())
353 throw Exception(
"MapSequenceContainer::addSequence: Sequence '" + sequence.getName() +
", already exists in container");
358 for (map<string, Sequence*>::const_iterator it = sequences_.begin(); it != sequences_.end(); it++)
359 if (key == it->first)
360 throw Exception(
"MapSequenceContainer::addSequence: key already in use. (" + key +
")");
363 if (sequence.getAlphabet()->getAlphabetType() == getAlphabet()->getAlphabetType())
364 sequences_.insert(make_pair(key, dynamic_cast<Sequence*>(sequence.clone())));
373 for (map<string, Sequence*>::const_iterator it =
sequences_.begin(); it !=
sequences_.end(); it++)
374 keys.push_back(it->first);
382 if (pos >= getNumberOfSequences())
383 throw IndexOutOfBoundsException(
"MapSequenceContainer::getKey", pos, 0, sequences_.size() - 1);
384 map<string, Sequence*>::const_iterator it = sequences_.begin();
385 for (
size_t i = 0; i < pos; i++) it++;
395 return getKey(getSequencePosition(name));
407 if (pos >= getNumberOfSequences())
408 throw IndexOutOfBoundsException(
"MapSequenceContainer::setComments", pos, 0, sequences_.size() - 1);
409 map<string, Sequence*>::iterator it = sequences_.begin();
410 for (
size_t i = 0 ; i < pos ; i++) it++;
411 it->second->setComments(comments);
418 vector<string> names;
419 for (map<string, Sequence*>::const_iterator it =
sequences_.begin(); it !=
sequences_.end(); it++)
420 names.push_back(it->second->getName());
428 if (names.size() != getNumberOfSequences())
429 throw IndexOutOfBoundsException(
"MapSequenceContainer::setSequenceNames : bad number of names", names.size(), getNumberOfSequences(), getNumberOfSequences());
432 for (
size_t i = 0 ; i < names.size() ; i++)
433 for (
unsigned int j = 0 ; j < i ; j++)
434 if (names[j] == names[i])
435 throw Exception(
"MapSequenceContainer::setSequencesNames: Sequence's name already exists in container");
437 map<string, Sequence*>::iterator it = sequences_.begin();
438 for (
size_t i = 0 ; i < names.size() ; i++)
440 it->second->setName(names[i]);
Exception thrown when a sequence is not found The sequence not found exception base class...
size_t getNumberOfSequences() const
Get the number of sequences in the container.
std::vector< std::string > Comments
Declaration of Comments type.
size_t getSequencePosition(const std::string &name) const
Get the position of a sequence in sequence container from its name.
Sequence & getSequence_(size_t i)
void addSequence(const std::string &key, const Sequence &sequence, bool checkNames=true)
Add a sequence and key.
void clear()
Delete all sequences in the container.
std::string getKey(size_t pos) const
This alphabet is used to deal NumericAlphabet.
const Alphabet * getAlphabet() const
Get sequence container's alphabet.
void deleteSequenceByKey(const std::string &key)
Delete a sequence.
AbstractSequenceContainer & operator=(const AbstractSequenceContainer &sc)
Partial implementation of the OrderedSequenceContainer interface.
const Comments & getGeneralComments() const
Get the comments of this container.
virtual ~MapSequenceContainer()
MapSequenceContainer class.
const Sequence & getSequenceByKey(const std::string &key) const
Get a sequence.
MapSequenceContainer(const std::map< std::string, Sequence *> &ms, const Alphabet *alpha)
const Sequence & getSequence(const std::string &name) const
Retrieve a sequence object from the container.
std::map< std::string, Sequence * > sequences_
void setComments(size_t sequenceIndex, const Comments &comments)
Set the comments of a particular sequence.
std::vector< std::string > getSequencesNames() const
Get all the names of the sequences in the container.
void setSequenceByKey(const std::string &key, const Sequence &sequence, bool checkNames=true)
Set a sequence.
Sequence * removeSequence(const std::string &name)
Extract (and remove) a sequence from the container.
MapSequenceContainer & operator=(const MapSequenceContainer &msc)
void setSequence(const std::string &name, const Sequence &sequence, bool checkName=true)
Replace a sequence in the container.
Exception thrown when two alphabets do not match.
virtual const std::string getSequenceId() const
Get the id of the sequence that was to be found.
void setSequencesNames(const std::vector< std::string > &names, bool checkNames)
Set all sequence names.
std::vector< std::string > getKeys() const
void deleteSequence(const std::string &name)
Delete a sequence of the container.
Sequence * removeSequenceByKey(const std::string &key)
Remove a sequence.
MapSequenceContainer * createEmptyContainer() const
Return a copy of this container, but with no sequence inside.
bool hasSequence(const std::string &name) const
Check if a sequence with a given name is present in the container.
void setGeneralComments(const Comments &comments)
Set the comments of this container.