Skip to content

Commit e0b2c51

Browse files
committed
Added tabular reporting option.
1 parent aac20bf commit e0b2c51

5 files changed

Lines changed: 37 additions & 16 deletions

File tree

src/common.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#include <immintrin.h>
4646
#endif
4747

48-
#define STRSTREAM_PRECISION 6
48+
#define STRSTREAM_PRECISION 4
4949

5050
#define VERSION "v0.6.0"
5151
#define PRINT_VERSION std::cerr << "krepp version: " << VERSION << std::endl;

src/krepp.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ void QueryIndex::header_preport(strstream& dreport_stream)
403403
qtree->stream_nwk_jplace(dreport_stream, qtree->get_root());
404404
if (summarize) {
405405
dreport_stream << "\nDISTAL_NODE\tEDGE_NUM\tWEIGHTED_COUNT\tSEQUENCE_ABUNDANCE\n";
406+
} else if (tabular) {
407+
dreport_stream << "\nSEQ_ID\tDISTAL_NODE\tEDGE_NUM\tLWR\tDIST\n";
406408
} else {
407409
(void)0; // TODO: Perhaps introduce an alternative placement report format.
408410
}
@@ -439,7 +441,7 @@ void QueryIndex::place_sequences()
439441
strstream preport_stream;
440442
preport_stream.precision(STRSTREAM_PRECISION);
441443
preport_stream << std::fixed;
442-
if (summarize) {
444+
if (summarize || tabular) {
443445
header_preport(preport_stream);
444446
(*output_stream) << preport_stream.rdbuf();
445447
} else {
@@ -461,7 +463,7 @@ void QueryIndex::place_sequences()
461463
#pragma omp task untied
462464
{
463465
strstream batch_stream;
464-
ib.place_sequences(batch_stream);
466+
ib.place_sequences(batch_stream, tabular);
465467
if (!summarize && !cont_reading) {
466468
#pragma omp task
467469
{
@@ -498,6 +500,8 @@ void QueryIndex::place_sequences()
498500
preport_stream << nd->get_name(true) << "\t" << nd->get_en() << "\t" << wcount << "\t" << wcount / twcount << "\n";
499501
}
500502
(*output_stream) << preport_stream.rdbuf();
503+
} else if (tabular) {
504+
(void)0;
501505
} else {
502506
preport_stream.str("");
503507
end_jplace(preport_stream);
@@ -615,6 +619,9 @@ void QueryIndex::init_sc_place(CLI::App& sc)
615619
sc.add_flag("--filter,!--no-filter",
616620
filter,
617621
"Filter a placement when there is not enough k-mer matches below threshold tau. [true]");
622+
sc.add_flag("--tabular,!--no-tabular",
623+
tabular,
624+
"Output the per query sequence placements (taxonomic/phylogenetic) in a tab-separated format. [false]");
618625
sc.callback([&]() {
619626
no_filter = !filter;
620627
if (!output_path.empty()) {
@@ -747,12 +754,11 @@ int main(int argc, char** argv)
747754
if (sc_place.count("--lineage-file") + sc_place.count("-l")) {
748755
krepp_place.read_lineages();
749756
std::cerr << "Placing given sequences on the taxonomic lineage..." << std::endl;
750-
krepp_place.place_sequences();
751757
} else {
752758
krepp_place.ensure_backbone();
753759
std::cerr << "Placing given sequences on the backbone tree..." << std::endl;
754-
krepp_place.place_sequences();
755760
}
761+
krepp_place.place_sequences();
756762
std::chrono::duration<float> es_s = std::chrono::system_clock::now() - tstart - es_b;
757763
std::cerr << "Done placing queries, elapsed: " << es_s.count() << " sec" << std::endl;
758764
std::cerr << "Total number of sequences queried: " << krepp_place.get_total_qseq() << std::endl;

src/krepp.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ class QueryIndex : public TargetIndex
212212
double dist_max = 0.25;
213213
bool no_filter = true;
214214
bool filter = false;
215+
bool tabular = false;
215216
bool multi = true;
216217
bool summarize = false;
217218
uint64_t total_qseq = 0;

src/query.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void IBatch::report_distances(strstream& batch_stream)
192192
}
193193
}
194194

195-
void IBatch::place_sequences(strstream& batch_stream)
195+
void IBatch::place_sequences(strstream& batch_stream, bool tabular)
196196
{
197197
for (bix = 0; bix < batch_size; ++bix) {
198198
const char* seq = seq_batch[bix].data();
@@ -205,11 +205,11 @@ void IBatch::place_sequences(strstream& batch_stream)
205205
summarize_matches(imers_or, imers_rc);
206206
batch_stream.precision(STRSTREAM_PRECISION);
207207
batch_stream << std::fixed;
208-
report_placement(batch_stream);
208+
report_placement(batch_stream, tabular);
209209
}
210210
}
211211

212-
void IBatch::report_placement(strstream& batch_stream)
212+
void IBatch::report_placement(strstream& batch_stream, bool tabular)
213213
{
214214
if (node_to_minfo.size() == 0 || !(no_filter || (mi_closest->get_leq_tau(tau) > 1.0))) {
215215
return;
@@ -218,12 +218,16 @@ void IBatch::report_placement(strstream& batch_stream)
218218
minfo_sptr_t mi_pp = mi_closest;
219219
mi_pp->chisq = 0;
220220

221-
batch_stream << "\t\t\t{\"n\" : [\"" << identifer_batch[bix] << "\"], \"p\" : [";
221+
if (!tabular) batch_stream << "\t\t\t{\"n\" : [\"" << identifer_batch[bix] << "\"], \"p\" : [";
222222
if (node_to_minfo.size() == 1) {
223223
if (summarize) {
224224
node_to_wcount[nd_pp] += 1.0;
225225
} else {
226-
batch_stream << PLACEMENT_FIELD(nd_pp, mi_pp) << "]},\n";
226+
if (tabular) {
227+
batch_stream << identifer_batch[bix] << "\t" << TABULAR_FIELD(nd_pp, mi_pp) << "\n";
228+
} else {
229+
batch_stream << PLACEMENT_FIELD(nd_pp, mi_pp) << "]},\n";
230+
}
227231
}
228232
return;
229233
}
@@ -281,11 +285,15 @@ void IBatch::report_placement(strstream& batch_stream)
281285
if (summarize) {
282286
node_to_wcount[nd_pp] += 1.0 / nd_v.size();
283287
} else {
284-
if (i > 0) batch_stream << ",";
285-
batch_stream << "\n\t\t\t\t" << PLACEMENT_FIELD(nd_pp, mi_pp);
288+
if (i > 0 && !tabular) batch_stream << ",";
289+
if (tabular) {
290+
batch_stream << identifer_batch[bix] << "\t" << TABULAR_FIELD(nd_pp, mi_pp) << "\n";
291+
} else {
292+
batch_stream << "\n\t\t\t\t" << PLACEMENT_FIELD(nd_pp, mi_pp);
293+
}
286294
}
287295
}
288-
if (!summarize) {
296+
if (!summarize && !tabular) {
289297
batch_stream << "]\n\t\t\t},\n";
290298
}
291299
} else {
@@ -302,7 +310,11 @@ void IBatch::report_placement(strstream& batch_stream)
302310
if (summarize) {
303311
node_to_wcount[nd_pp] += 1.0;
304312
} else {
305-
batch_stream << PLACEMENT_FIELD(nd_pp, mi_pp) << "]},\n";
313+
if (tabular) {
314+
batch_stream << identifer_batch[bix] << "\t" << TABULAR_FIELD(nd_pp, mi_pp) << "\n";
315+
} else {
316+
batch_stream << PLACEMENT_FIELD(nd_pp, mi_pp) << "]},\n";
317+
}
306318
}
307319
}
308320
}

src/query.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ class IBatch
5858
void search_mers(const char* seq, uint64_t len, imers_sptr_t imers_or, imers_sptr_t imers_rc);
5959
void summarize_matches(imers_sptr_t imers_or, imers_sptr_t imers_rc);
6060
void estimate_distances(strstream& batch_stream);
61-
void place_sequences(strstream& batch_stream);
6261
void report_distances(strstream& batch_stream);
63-
void report_placement(strstream& batch_stream);
62+
void place_sequences(strstream& batch_stream, bool tabular);
63+
void report_placement(strstream& batch_stream, bool tabular);
6464
const parallel_flat_phmap<node_sptr_t, double>& get_summary() { return node_to_wcount; }
6565

6666
private:
@@ -191,6 +191,8 @@ class Minfo
191191
"[" << nd->get_en() << ", " << mi->jukes_cantor_dist() - nd->get_midpoint_pendant() << ", " << nd->get_midpoint_pendant() \
192192
<< ", " << -mi->v_llh << ", " << mi->lwr << ", " << mi->d_llh << "]"
193193

194+
#define TABULAR_FIELD(nd, mi) nd->get_name(true) << "\t" << nd->get_en() << "\t" << mi->lwr << "\t" << mi->d_llh
195+
194196
#define DISTANCE_FIELD(nd, mi) nd->get_name() << "\t" << mi->d_llh << "\n"
195197

196198
private:

0 commit comments

Comments
 (0)