VectorSiteContainer::VectorSiteContainer(const SequenceContainer& sc) :
  AbstractSequenceContainer(sc),
  sites_(0),
  names_(0),
  comments_(0),
  sequences_(0)
{
  vector<string> names = sc.getSequencesNames();
  for (size_t i = 0; i < names.size(); i++)
  {
    addSequence(sc.getSequence(names[i]), false);
  }
  reindexSites();
}
Example #2
0
void Mase::write(ostream & output, const SequenceContainer & sc) const throw (Exception)
{
	// Checking the existence of specified file, and possibility to open it in write mode
	if (!output) { throw IOException ("Mase::write : failed to open file"); }

	Comments comments = sc.getGeneralComments();

	// Writing all general commentaries in file
	for (unsigned int i = 0 ; i < comments.size() ; i++) {
		output << ";;" << comments[i] << endl;
	}

	string seq, temp = "";  // Initialization

	// Main loop : for all sequences
	vector<string> names = sc.getSequencesNames();
	for (unsigned int i = 0 ; i < names.size() ; i ++) {
		comments = sc.getComments(names[i]);

		// Writing all sequence comments in file
		// If no comments are associated with current sequence, an empy commentary line will be writed
		if (comments.size() == 0) {
			output << ";" << endl;
		} else {
			for (unsigned int j = 0 ; j < comments.size() ; j++) {
				output << ";" << comments[j] << endl;
			}
		}

		// Sequence name writing
		output << names[i] << endl;

		// Sequence cutting to specified characters number per line
		seq = sc.toString(names[i]);
		while (seq != "") {
			if (seq.size() > _charsByLine) {
				temp = seq;
				temp.erase(temp.begin() + _charsByLine , temp.end());
				output << temp  << endl;
				seq.erase(seq.begin(), seq.begin() + _charsByLine);
			}
			else {
				output << seq << endl;
				seq = "";
			}
		}
	}
}