40
40
#include < fstream> // for std::ofstream
41
41
#endif
42
42
43
- FlatMatrix::FlatMatrix (): rowCount(0 ), distanceMatrix(nullptr ), borrowed(false ) {
43
+ FlatMatrix::FlatMatrix (): rowCount(0 ), distanceMatrix(nullptr ),
44
+ borrowed(false ) {
44
45
}
45
46
46
47
FlatMatrix::FlatMatrix (const StrVector& sequence_names,
@@ -77,6 +78,10 @@ void FlatMatrix::setSequenceName(intptr_t i,
77
78
sequenceNames[i] = new_name;
78
79
}
79
80
81
+ /* *
82
+ * @brief set the rank of the matrix and make it square
83
+ * @param rows
84
+ */
80
85
void FlatMatrix::setSize (intptr_t rows) {
81
86
if (!borrowed) {
82
87
delete [] distanceMatrix;
@@ -107,6 +112,21 @@ void FlatMatrix::addCluster(const std::string& clusterName) {
107
112
sequenceNames.emplace_back (clusterName);
108
113
}
109
114
115
+ /* *
116
+ * @brief Write a distance matrix, to the specified file, with the
117
+ * specified format, using the specified precision for representing
118
+ * distances, the specified (gzip/zlib) compression. Possibly
119
+ * reporting progress as the file is written.
120
+ * @param format - "upper", "lower", or "square"
121
+ * OR "upper.gz", "lower.gz", or "square.gz",
122
+ * to ask for gzip compression.
123
+ * @param precision - the number of digits after the decimal point
124
+ * @param compression_level - the level of compression (0 through 9)
125
+ * @param report_progress - true if progress is to be reported
126
+ * @param file_name - the path of the file
127
+ * @return true - on success
128
+ * @return false - on failure (error messages will be written to std::cerr)
129
+ */
110
130
bool FlatMatrix::writeToDistanceFile (const std::string& format,
111
131
int precision,
112
132
int compression_level,
@@ -159,6 +179,25 @@ bool FlatMatrix::writeToDistanceFile(const std::string& format,
159
179
return true ;
160
180
}
161
181
182
+ /* *
183
+ * @brief write a distance matrix, in the specifed format, with the specified
184
+ * precision, to an output stream (possibly reporting progress while
185
+ * doing so)
186
+ * @tparam S - the type of the output stream
187
+ * @tparam P - the type of the progress-display instance
188
+ * that progress points to
189
+ * @param format - "upper", "lower", or "square" (no ".gz" on the end!)
190
+ * @param precision - the number of digits to use, after the decimal point
191
+ * for each distance in the distance matrix.
192
+ * if this is more than 10, it will be ignored and 10
193
+ * will be used.
194
+ * @param out - the output stream (might by an std::iostream or a
195
+ * std::stringstream)
196
+ * @param progress - true if progress is to be reported as the write proceeds
197
+ * @note Doesn't detect errors. Exceptions will be thrown.
198
+ * The caller expects any such exceptions will be caught by
199
+ * a catch ( const std::ios::failure & ) {} block.
200
+ */
162
201
template <class S , class P >
163
202
void FlatMatrix::writeDistancesToOpenFile (const std::string& format,
164
203
int precision, S &out,
@@ -191,6 +230,14 @@ void FlatMatrix::writeDistancesToOpenFile(const std::string& format,
191
230
out.flush ();
192
231
}
193
232
233
+ /* *
234
+ * @brief Write distances, in a row of a distance matrix, to a stringstream
235
+ * @param nseqs - the number of sequences (used for calculating indices)
236
+ * @param seq1 - the row number
237
+ * @param rowStart - the first column, for which to write a distance in the row
238
+ * @param rowStop - the first column, NOT to write a distance to, in the row
239
+ * @param line - the stringstream (for the line being constructed)
240
+ */
194
241
void FlatMatrix::appendRowDistancesToLine (intptr_t nseqs, intptr_t seq1,
195
242
intptr_t rowStart, intptr_t rowStop,
196
243
std::stringstream& line) const {
@@ -204,6 +251,11 @@ void FlatMatrix::appendRowDistancesToLine(intptr_t nseqs, intptr_t seq1,
204
251
}
205
252
}
206
253
254
+ /* *
255
+ * @brief Return the maximum length of a sequence name, over all of the
256
+ * sequences.
257
+ * @return size_t - the maximum length
258
+ */
207
259
size_t FlatMatrix::getMaxSeqNameLength () const {
208
260
size_t len = 0 ;
209
261
intptr_t nseqs = sequenceNames.size ();
0 commit comments