Skip to content

Commit

Permalink
fixed abundance table formatting & output
Browse files Browse the repository at this point in the history
 - added missing taxon column for unclassified reads in abundance tables
 - prevent that read numbers are shown in scientific notation
  • Loading branch information
muellan committed Mar 11, 2024
1 parent 54790ef commit d35f957
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/classification.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ struct rank_higher {
}
};

using taxon_count_map = std::map<const taxon*, float, rank_higher>;
// using taxon_count_map = std::unordered_map<const taxon*, query_id>;
using taxon_count_map = std::map<const taxon*, double, rank_higher>;


/*************************************************************************//**
Expand Down
18 changes: 17 additions & 1 deletion src/printing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#include <ostream>
#include <utility>
#include <iomanip>
#include <cmath>


namespace mc {
Expand Down Expand Up @@ -425,6 +427,8 @@ void show_abundance_table (std::ostream& os,
<< "number of reads" << opt.tokens.column
<< "abundance\n";

double ipart = 0.0;

for (const auto& tc : allTaxCounts) {
if (tc.first) {
os << tc.first->rank_name() << opt.tokens.rankSuffix
Expand All @@ -436,10 +440,22 @@ void show_abundance_table (std::ostream& os,
} else {
os << "none";
}
os << opt.tokens.column << tc.second << opt.tokens.column

os << opt.tokens.column;
// ensure that integer values are printed as such
// and not in scientific notation
if (std::modf(tc.second, &ipart) == 0.0) {
os << ipart;
} else {
// set higher precision to prevent scientific notation
// and set back to default (6) after that
os << std::setprecision(15) << tc.second << std::setprecision(6);
}
os << opt.tokens.column
<< (tc.second / double(statistics.total()) * 100) << "%\n";
}
os << "unclassified" << opt.tokens.column
<< "--" << opt.tokens.column
<< '0' << opt.tokens.column
<< statistics.unassigned() << opt.tokens.column
<< statistics.unclassified_rate() * 100 << "%\n";
Expand Down

0 comments on commit d35f957

Please sign in to comment.