41 #include <Bpp/Text/TextTools.h> 42 #include <Bpp/Text/StringTokenizer.h> 43 #include <Bpp/Io/FileTools.h> 55 if (!input) {
throw IOException (
"Clustal::read : fail to open file"); }
57 const Alphabet * alpha = sc.getAlphabet();
58 vector<BasicSequence> sequences;
63 comments[0] = FileTools::getNextLine(input);
65 lineRead = FileTools::getNextLine(input);
67 string::size_type beginSeq = 0;
68 unsigned int count = 0;
69 for (
size_t i = lineRead.size(); i > 0; i--) {
70 char c = lineRead[i-1];
73 if (count == nbSpacesBeforeSeq_) {
74 beginSeq = i - 1 + nbSpacesBeforeSeq_;
80 if (beginSeq == 0)
throw IOException(
"Clustal::read. Bad intput file.");
82 unsigned int countSequences = 0;
87 sequences.push_back(
BasicSequence(TextTools::removeSurroundingWhiteSpaces(lineRead.substr(0, beginSeq - nbSpacesBeforeSeq_)), lineRead.substr(beginSeq), alpha));
88 getline(input, lineRead,
'\n');
90 test = !TextTools::isEmpty(lineRead) && !TextTools::isEmpty(lineRead.substr(0, beginSeq - nbSpacesBeforeSeq_));
92 while (input && test);
95 lineRead = FileTools::getNextLine(input);
96 while (!TextTools::isEmpty(lineRead)) {
98 for (
unsigned int i = 0; i < countSequences; ++i) {
100 if (TextTools::isEmpty(lineRead))
101 throw IOException(
"Clustal::read. Bad intput file.");
102 sequences[i].append(lineRead.substr(beginSeq));
103 getline(input, lineRead,
'\n');
106 lineRead = FileTools::getNextLine(input);
109 for (
unsigned int i = 0; i < countSequences; ++i)
110 sc.addSequence(sequences[i], checkNames_);
111 sc.setGeneralComments(comments);
116 output <<
"CLUSTAL W (1.81) multiple sequence alignment" << endl;
118 if (sc.getNumberOfSequences() == 0)
123 for (
size_t i = 0; i < sc.getNumberOfSequences(); ++i ) {
124 const Sequence& seq = sc.getSequence(i);
125 if (seq.
getName().size() > length)
127 text.push_back(sc.getSequence(i).toString());
129 length += nbSpacesBeforeSeq_;
130 for (
unsigned int j = 0; j < text[0].size(); j += charsByLine_) {
131 for (
unsigned int i = 0; i < sc.getNumberOfSequences(); ++i ) {
132 output << TextTools::resizeRight(sc.getSequence(i).getName(), length);
133 output << text[i].substr(j, charsByLine_) << endl;
std::vector< std::string > Comments
Declaration of Comments type.
The SiteContainer interface.
This alphabet is used to deal NumericAlphabet.
virtual const std::string & getName() const =0
Get the name of this sequence.
void appendAlignmentFromStream(std::istream &input, SiteContainer &sc) const
Append sequences to a container from a stream.
A basic implementation of the Sequence interface.
void writeAlignment(std::ostream &output, const SiteContainer &sc) const
Write a container to a stream.