void VectorSiteContainer::setSequence(size_t pos, const Sequence& sequence, bool checkNames) throw (Exception) { if (pos >= getNumberOfSequences()) throw IndexOutOfBoundsException("VectorSiteContainer::setSequence", pos, 0, getNumberOfSequences() - 1); // New sequence's alphabet and site container's alphabet matching verification if (sequence.getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType()) throw AlphabetMismatchException("VectorSiteContainer::addSite", getAlphabet(), sequence.getAlphabet()); // If the container has only one sequence, we set the size to the size of this sequence: if (getNumberOfSequences() == 1) realloc(sequence.size()); if (sequence.size() != sites_.size()) throw SequenceException("VectorSiteContainer::setSequence. Sequence has not the appropriate length.", &sequence); if (checkNames) { for (size_t i = 0; i < names_.size(); i++) { if (i != pos && sequence.getName() == names_[i]) throw SequenceException("VectorSiteContainer::settSequence. Name already exists in container.", &sequence); } } // Update name: names_[pos] = sequence.getName(); // Update elements at each site: for (size_t i = 0; i < sites_.size(); i++) { sites_[i]->setElement(pos, sequence.getValue(i)); } // Update comments: if (comments_[pos]) delete comments_[pos]; comments_[pos] = new Comments(sequence.getComments()); // Update sequences: if (sequences_[pos]) delete sequences_[pos]; sequences_[pos] = 0; }
void VectorSiteContainer::addSequence(const Sequence& sequence, bool checkNames) throw (Exception) { // If the container has no sequence, we set the size to the size of this sequence: if (getNumberOfSequences() == 0) realloc(sequence.size()); // New sequence's alphabet and site container's alphabet matching verification if (sequence.getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType()) throw AlphabetMismatchException("VectorSiteContainer::addSequence", getAlphabet(), sequence.getAlphabet()); if (sequence.size() != sites_.size()) throw SequenceException("VectorSiteContainer::addSequence. Sequence has not the appropriate length: " + TextTools::toString(sequence.size()) + ", should be " + TextTools::toString(sites_.size()) + ".", &sequence); if (checkNames) { for (size_t i = 0; i < names_.size(); i++) { if (sequence.getName() == names_[i]) throw SequenceException("VectorSiteContainer::addSequence. Name already exists in container.", &sequence); } } // Append name: names_.push_back(sequence.getName()); // Append elements at each site: for (size_t i = 0; i < sites_.size(); i++) { sites_[i]->addElement(sequence.getValue(i)); } // Append comments: comments_.push_back(new Comments(sequence.getComments())); // Sequences pointers: sequences_.push_back(0); }
void VectorSiteContainer::addSequence( const Sequence& sequence, size_t pos, bool checkNames) throw (Exception) { if (pos >= getNumberOfSequences()) throw IndexOutOfBoundsException("VectorSiteContainer::addSequence.", pos, 0, getNumberOfSequences() - 1); if (sequence.size() != sites_.size()) throw SequenceNotAlignedException("VectorSiteContainer::setSequence", &sequence); // New sequence's alphabet and site container's alphabet matching verification if (sequence.getAlphabet()->getAlphabetType() != getAlphabet()->getAlphabetType()) { throw AlphabetMismatchException("VectorSiteContainer::addSite", getAlphabet(), sequence.getAlphabet()); } if (checkNames) { for (size_t i = 0; i < names_.size(); i++) { if (sequence.getName() == names_[i]) throw SequenceException("VectorSiteContainer::addSequence. Name already exists in container.", &sequence); } } for (size_t i = 0; i < sites_.size(); i++) { // For each site: sites_[i]->addElement(pos, sequence.getValue(i)); } // Actualize names and comments: names_.insert(names_.begin() + pos, sequence.getName()); comments_.insert(comments_.begin() + pos, new Comments(sequence.getComments())); sequences_.insert(sequences_.begin() + pos, 0); }
BasicSequence::BasicSequence(const Sequence& s) : BasicSymbolList(s), name_(s.getName()), comments_(s.getComments()) {}