42 #include <Bpp/Io/FileTools.h> 43 #include <Bpp/Text/TextTools.h> 44 #include <Bpp/Text/StringTokenizer.h> 47 #include <Bpp/Seq/DistanceMatrix.h> 58 string s = FileTools::getNextLine(in);
60 unsigned int n = TextTools::fromString<unsigned int>(s);
61 DistanceMatrix * dist =
new DistanceMatrix(n);
62 unsigned int rowNumber = 0;
63 unsigned int colNumber = 0;
64 s = FileTools::getNextLine(in);
70 size_t pos = s.find(
" ");
71 if (pos == string::npos)
72 throw Exception(
"PhylipDistanceMatrixFormat::read. Bad format, probably not 'extended' Phylip.");
73 dist->setName(rowNumber, s.substr(0, pos));
74 s = s.substr(pos + 2);
76 dist->setName(rowNumber, s.substr(0, 10));
80 StringTokenizer st(s,
"\t ");
81 for (; colNumber < n && st.hasMoreToken(); colNumber++)
83 double d = TextTools::fromString<double>(st.nextToken());
84 (* dist)(rowNumber, colNumber) = d;
91 s = FileTools::getNextLine(in);
98 size_t n = dist.size();
99 out <<
" " << n << endl;
103 for (
size_t i = 0; i < n; ++i) {
104 size_t s = dist.getName(i).size();
105 if (s > offset) offset = s;
108 for (
unsigned int i = 0; i < n; i++)
110 out << TextTools::resizeRight(dist.getName(i), offset,
' ');
116 for (
unsigned int j = 0; j < n; j++) {
117 if (j > 0) out <<
" ";
118 out << setprecision(8) << dist(i, j);