Skip to content

Commit

Permalink
using pprintpp
Browse files Browse the repository at this point in the history
  • Loading branch information
voutcn committed Jun 24, 2019
1 parent c98f425 commit 2217fc6
Show file tree
Hide file tree
Showing 30 changed files with 638 additions and 147 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ find_package(ZLIB REQUIRED)
find_package(OpenMP REQUIRED)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DXXH_INLINE_ALL -D__STDC_FORMAT_MACROS")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DXXH_INLINE_ALL -D__STDC_FORMAT_MACROS -ftemplate-depth=3000")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-function")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprefetch-loop-arrays -funroll-loops")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__XROOT__='\"${CMAKE_SOURCE_DIR}/src\"'")
Expand Down
4 changes: 2 additions & 2 deletions src/assembly/contig_stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ inline ContigStat CalcAndPrintStat(UnitigGraph &graph, bool print = true, bool c
if (print) {
xinfo("");
for (auto &kv : stat) {
xinfoc("%s: %lu, ", kv.first.c_str(), kv.second);
xinfoc("{}: {}, ", kv.first.c_str(), kv.second);
}
xinfoc("\n");
xinfoc("{}", "\n");
}
return stat;
}
Expand Down
3 changes: 2 additions & 1 deletion src/assembly/contig_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
#include <cassert>
#include <cstdint>
#include <string>
#include "utils/utils.h"

class UnitigGraph;

inline void WriteContig(const std::string &ascii_contig, unsigned k_size, long long id, int flag, double multi,
FILE *file) {
fprintf(file, ">k%d_%lld flag=%d multi=%.4lf len=%lu\n%s\n", k_size, id, flag, multi, ascii_contig.length(),
pfprintf(file, ">k{}_{} flag={} multi={.4} len={}\n{}\n", k_size, id, flag, multi, ascii_contig.length(),
ascii_contig.c_str());
}

Expand Down
8 changes: 4 additions & 4 deletions src/assembly/sdbg_pruning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,20 @@ uint64_t RemoveTips(SDBG &dbg, int max_tip_len) {
}

for (int len = 2; len < max_tip_len; len *= 2) {
xinfo("Removing tips with length less than %d; ", len);
xinfo("Removing tips with length less than {}; ", len);
timer.reset();
timer.start();
number_tips += Trim(dbg, len, ignored);
timer.stop();
xinfoc("Accumulated tips removed: %lld; time elapsed: %.4f\n", (long long)number_tips, timer.elapsed());
xinfoc("Accumulated tips removed: {}; time elapsed: {.4}\n", number_tips, timer.elapsed());
}

xinfo("Removing tips with length less than %d; ", max_tip_len);
xinfo("Removing tips with length less than {}; ", max_tip_len);
timer.reset();
timer.start();
number_tips += Trim(dbg, max_tip_len, ignored);
timer.stop();
xinfoc("Accumulated tips removed: %lld; time elapsed: %.4f\n", (long long)number_tips, timer.elapsed());
xinfoc("Accumulated tips removed: {}; time elapsed: {.4}\n", number_tips, timer.elapsed());

return number_tips;
}
Expand Down
10 changes: 5 additions & 5 deletions src/assembly/unitig_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ UnitigGraph::UnitigGraph(SDBG *sdbg) : sdbg_(sdbg), adapter_impl_(this), sudo_ad
}
}
}
xinfo("Graph size without loops: %lu, palindrome: %lu\n", vertices_.size(), count_palindrome);
xinfo("Graph size without loops: {}, palindrome: {}\n", vertices_.size(), count_palindrome);

// assemble looped paths
std::mutex loop_lock;
Expand Down Expand Up @@ -114,9 +114,9 @@ UnitigGraph::UnitigGraph(SDBG *sdbg) : sdbg_(sdbg), adapter_impl_(this), sudo_ad

if (vertices_.size() >= kMaxNumVertices) {
xfatal(
"Too many vertices in the unitig graph (%llu >= %llu), "
"Too many vertices in the unitig graph ({} >= {}), "
"you may increase the kmer size to remove tons of erroneous kmers.\n",
static_cast<unsigned long long>(vertices_.size()), static_cast<unsigned long long>(kMaxNumVertices));
vertices_.size(), kMaxNumVertices);
}

sdbg_->FreeMultiplicity();
Expand Down Expand Up @@ -355,7 +355,7 @@ std::string UnitigGraph::VertexToDNAString(VertexAdapter v) {

cur_edge = sdbg_->PrevSimplePathEdge(cur_edge);
if (cur_edge == SDBG::kNullID) {
xfatal("%lld, %lld, %lld, %lld, (%lld, %lld), %d, %d\n", v.b(), v.e(), v.rb(), v.re(),
xfatal("{}, {}, {}, {}, ({}, {}), {}, {}\n", v.b(), v.e(), v.rb(), v.re(),
sdbg_->EdgeReverseComplement(v.e()), sdbg_->EdgeReverseComplement(v.b()), v.GetLength(), i);
}
}
Expand All @@ -364,7 +364,7 @@ std::string UnitigGraph::VertexToDNAString(VertexAdapter v) {
label.push_back("ACGT"[cur_char > 4 ? (cur_char - 5) : (cur_char - 1)]);

if (cur_edge != v.b()) {
xfatal("fwd: %lld, %lld, rev: %lld, %lld, (%lld, %lld) length: %d\n", v.b(), v.e(), v.rb(), v.re(),
xfatal("fwd: {}, {}, rev: {}, {}, ({}, {}) length: {}\n", v.b(), v.e(), v.rb(), v.re(),
sdbg_->EdgeReverseComplement(v.e()), sdbg_->EdgeReverseComplement(v.b()), v.GetLength());
}

Expand Down
11 changes: 5 additions & 6 deletions src/localasm/local_assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void LocalAssembler::BuildHashMapper(bool show_stat) {
}

if (show_stat) {
xinfo("Number of contigs: %lu, Mapper size: %lu\n", contigs_.SeqCount(), mapper_.size());
xinfo("Number of contigs: {}, Mapper size: {}\n", contigs_.SeqCount(), mapper_.size());
}
}

Expand Down Expand Up @@ -292,7 +292,7 @@ void LocalAssembler::EstimateInsertSize(bool show_stat) {
insert_sizes_[lib_id] = tlen_t(insert_hist.mean(), insert_hist.sd());

if (show_stat) {
xinfo("Lib %d, insert size: %.2lf sd: %.2lf\n", lib_id, insert_hist.mean(), insert_hist.sd());
xinfo("Lib {}, insert size: {.2} sd: {.2}\n", lib_id, insert_hist.mean(), insert_hist.sd());
}
}
}
Expand Down Expand Up @@ -410,7 +410,7 @@ void LocalAssembler::MapToContigs() {
}
}

xinfo("Lib %d: total %ld reads, aligned %lu, added %lu reads for local assembly\n", lib_id,
xinfo("Lib {}: total {} reads, aligned {}, added {} reads for local assembly\n", lib_id,
lib_info_[lib_id].to - lib_info_[lib_id].from + 1, num_mapped, num_added);
}
locks_.reset(0);
Expand Down Expand Up @@ -537,16 +537,15 @@ void LocalAssembler::LocalAssemble() {
for (uint64_t j = 0; j < out_contigs.size(); ++j) {
if (out_contigs[j].size() > min_contig_len_ && out_contigs[j].size() > local_kmax_) {
auto str = out_contigs[j].str();
fprintf(local_file, ">lc_%llu_strand_%d_id_%llu flag=0 multi=1\n%s\n", static_cast<unsigned long long>(cid),
strand, static_cast<unsigned long long>(j), str.c_str());
pfprintf(local_file, ">lc_{}_strand_{}_id_{} flag=0 multi=1\n{s}\n", cid, strand, j, str.c_str());
num_contigs++;
num_bases += out_contigs[j].size();
}
}
}
}

fprintf(local_info, "%lld %lld\n", num_contigs, num_bases);
pfprintf(local_info, "{} {}\n", num_contigs, num_bases);

fclose(local_file);
fclose(local_info);
Expand Down
13 changes: 7 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <cstring>

#include "definitions.h"
#include "utils/utils.h"
#include "utils/cpu_dispatch.h"

int main_assemble(int argc, char **argv);
Expand All @@ -41,8 +42,8 @@ int main_filter_by_len(int argc, char **argv);
int main_extract_pe(int argc, char **argv);

void show_help(const char *program_name) {
fprintf(stderr,
"Usage: %s <sub_program> [sub options]\n"
pfprintf(stderr,
"Usage: {s} <sub_program> [sub options]\n"
" sub-programs:\n"
" assemble assemble from SdBG\n"
" local local asssembly\n"
Expand All @@ -57,7 +58,7 @@ void show_help(const char *program_name) {
" trim trim low quality tail of fastq reads\n"
" filterbylen filter contigs by length\n"
" extractpe extract pe reads and se reads from fasta/fastq files\n"
" checkcpu check whether the run-time CPU supports POPCNT and BMI2"
" checkcpu check whether the run-time CPU supports POPCNT and BMI2\n"
" dumpversion dump version\n"
" kmax the largest k value supported\n",
program_name);
Expand Down Expand Up @@ -94,11 +95,11 @@ int main(int argc, char **argv) {
} else if (strcmp(argv[1], "extractpe") == 0) {
return main_extract_pe(argc - 1, argv + 1);
} else if (strcmp(argv[1], "checkcpu") == 0) {
printf("%d\n", HasPopcnt() && HasBmi2());
pprintf("{}\n", HasPopcnt() && HasBmi2());
} else if (strcmp(argv[1], "dumpversion") == 0) {
printf("%s\n", PACKAGE_VERSION);
pprintf("{s}\n", PACKAGE_VERSION);
} else if (strcmp(argv[1], "kmax") == 0) {
printf("%d\n", kMaxK);
pprintf("{}\n", kMaxK);
} else {
show_help(argv[0]);
return 1;
Expand Down
34 changes: 17 additions & 17 deletions src/main_assemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,18 @@ int main_assemble(int argc, char **argv) {
// graph loading
timer.reset();
timer.start();
xinfo("Loading succinct de Bruijn graph: %s ", opt.sdbg_name.c_str());
xinfo("Loading succinct de Bruijn graph: {} ", opt.sdbg_name.c_str());
dbg.LoadFromFile(opt.sdbg_name.c_str());
timer.stop();
xinfoc("Done. Time elapsed: %lf\n", timer.elapsed());
xinfo("Number of Edges: %lld; K value: %d\n", (long long)dbg.size(), dbg.k());
xinfoc("Done. Time elapsed: {}\n", timer.elapsed());
xinfo("Number of Edges: {}; K value: {}\n", dbg.size(), dbg.k());

// set cpu threads
if (opt.num_cpu_threads == 0) {
opt.num_cpu_threads = omp_get_max_threads();
}
omp_set_num_threads(opt.num_cpu_threads);
xinfo("Number of CPU threads: %d\n", opt.num_cpu_threads);
xinfo("Number of CPU threads: {}\n", opt.num_cpu_threads);

// set tip len
if (opt.max_tip_len == -1) {
Expand All @@ -127,7 +127,7 @@ int main_assemble(int argc, char **argv) {
// set min depth
if (opt.min_depth <= 0) {
opt.min_depth = sdbg_pruning::InferMinDepth(dbg);
xinfo("min depth set to %.3lf\n", opt.min_depth);
xinfo("min depth set to {.3}\n", opt.min_depth);
}

// tips removal before building unitig graph
Expand All @@ -136,15 +136,15 @@ int main_assemble(int argc, char **argv) {
timer.start();
sdbg_pruning::RemoveTips(dbg, opt.max_tip_len);
timer.stop();
xinfo("Tips removal done! Time elapsed(sec): %lf\n", timer.elapsed());
xinfo("Tips removal done! Time elapsed(sec): {.3}\n", timer.elapsed());
}

// construct unitig graph
timer.reset();
timer.start();
UnitigGraph graph(&dbg);
timer.stop();
xinfo("unitig graph size: %u, time for building: %lf\n", graph.size(), timer.elapsed());
xinfo("unitig graph size: {}, time for building: {.3}\n", graph.size(), timer.elapsed());
CalcAndPrintStat(graph);

// set up bubble
Expand All @@ -167,15 +167,15 @@ int main_assemble(int argc, char **argv) {
uint32_t num_tips = RemoveTips(graph, opt.max_tip_len);
changed |= num_tips > 0;
timer.stop();
xinfo("Tips removed: %u, time: %lf\n", num_tips, timer.elapsed());
xinfo("Tips removed: {}, time: {.3}\n", num_tips, timer.elapsed());
}
// remove bubbles
if (opt.bubble_level >= 1) {
timer.reset();
timer.start();
uint32_t num_bubbles = naiver_bubble_remover.PopBubbles(graph, true);
timer.stop();
xinfo("Number of bubbles removed: %u, Time elapsed(sec): %lf\n", num_bubbles, timer.elapsed());
xinfo("Number of bubbles removed: {}, Time elapsed(sec): {.3}\n", num_bubbles, timer.elapsed());
changed |= num_bubbles > 0;
}
// remove complex bubbles
Expand All @@ -184,7 +184,7 @@ int main_assemble(int argc, char **argv) {
timer.start();
uint32_t num_bubbles = complex_bubble_remover.PopBubbles(graph, true);
timer.stop();
xinfo("Number of complex bubbles removed: %u, Time elapsed(sec): %lf\n", num_bubbles, timer.elapsed());
xinfo("Number of complex bubbles removed: {}, Time elapsed(sec): {}\n", num_bubbles, timer.elapsed());
changed |= num_bubbles > 0;
}

Expand All @@ -193,7 +193,7 @@ int main_assemble(int argc, char **argv) {
timer.start();
uint32_t num_disconnected = DisconnectWeakLinks(graph, 0.1);
timer.stop();
xinfo("Number unitigs disconnected: %u, time: %lf\n", num_disconnected, timer.elapsed());
xinfo("Number unitigs disconnected: {}, time: {.3}\n", num_disconnected, timer.elapsed());
changed |= num_disconnected > 0;

// excessive pruning
Expand All @@ -207,14 +207,14 @@ int main_assemble(int argc, char **argv) {
num_excessive_pruned += complex_bubble_remover.PopBubbles(graph, true);
}
timer.stop();
xinfo("Unitigs removed in (more-)excessive pruning: %llu, time: %lf\n", num_excessive_pruned, timer.elapsed());
xinfo("Unitigs removed in (more-)excessive pruning: {}, time: {.3}\n", num_excessive_pruned, timer.elapsed());
} else if (opt.prune_level >= 2) {
timer.reset();
timer.start();
RemoveLocalLowDepth(graph, opt.min_depth, opt.max_tip_len, opt.local_width, std::min(opt.low_local_ratio, 0.1),
true, &num_excessive_pruned);
timer.stop();
xinfo("Unitigs removed in excessive pruning: %llu, time: %lf\n", num_excessive_pruned, timer.elapsed());
xinfo("Unitigs removed in excessive pruning: {}, time: {.3}\n", num_excessive_pruned, timer.elapsed());
}
if (!changed) break;
}
Expand All @@ -229,12 +229,12 @@ int main_assemble(int argc, char **argv) {
timer.reset();
timer.start();
FILE *out_contig_info = xfopen((opt.contig_file() + ".info").c_str(), "w");
fprintf(out_contig_info, "%lu %lu\n", graph.size() + bubble_hist.size(), stat["total size"] + bubble_hist.sum());
pfprintf(out_contig_info, "{} {}\n", graph.size() + bubble_hist.size(), stat["total size"] + bubble_hist.sum());
fclose(out_contig_info);

OutputContigs(graph, contig_file, opt.output_standalone ? standalone_file : nullptr, false, opt.min_standalone);
timer.stop();
xinfo("Time to output: %lf\n", timer.elapsed());
xinfo("Time to output: {}\n", timer.elapsed());
}

// remove local low depth & output as contigs
Expand All @@ -253,7 +253,7 @@ int main_assemble(int argc, char **argv) {
n_bubbles = complex_bubble_remover.PopBubbles(graph, false);
timer.stop();
}
xinfo("Number of local low depth unitigs removed: %lu, complex bubbles removed: %u, time: %lf\n", num_removed,
xinfo("Number of local low depth unitigs removed: {}, complex bubbles removed: {}, time: {}\n", num_removed,
n_bubbles, timer.elapsed());
CalcAndPrintStat(graph);

Expand All @@ -264,7 +264,7 @@ int main_assemble(int argc, char **argv) {
}

auto stat_changed = CalcAndPrintStat(graph, false, true);
fprintf(add_contig_info, "%lu %lu\n", stat_changed["number contigs"], stat_changed["total size"]);
pfprintf(add_contig_info, "{} {}\n", stat_changed["number contigs"], stat_changed["total size"]);

fclose(add_contig_file);
fclose(add_contig_info);
Expand Down
2 changes: 1 addition & 1 deletion src/main_buildlib.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "sequence/lib_io.h"
#include "utils/utils.h"

void DisplayHelp(const char *program) { fprintf(stderr, "Usage %s <read_lib_file> <out_prefix>\n", program); }
void DisplayHelp(const char *program) { pfprintf(stderr, "Usage {s} <read_lib_file> <out_prefix>\n", program); }

int main_build_lib(int argc, char **argv) {
AutoMaxRssRecorder recorder;
Expand Down
12 changes: 6 additions & 6 deletions src/main_iterate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static bool ReadReadsAndProcessKernel(const Option &opt, const IndexType &index)
if (KmerType::max_size() < static_cast<unsigned>(opt.kmer_k + opt.step + 1)) {
return false;
}
xinfo("Selected kmer type size for next k: %u\n", sizeof(KmerType));
xinfo("Selected kmer type size for next k: {}\n", sizeof(KmerType));
AsyncReadReader reader(opt.read_file);
KmerCollector<KmerType> collector(opt.kmer_k + opt.step + 1, opt.output_prefix);
int64_t num_aligned_reads = 0;
Expand All @@ -121,11 +121,11 @@ static bool ReadReadsAndProcessKernel(const Option &opt, const IndexType &index)
}
num_aligned_reads += index.FindNextKmersFromReads(read_pkg, &collector);
num_total_reads += read_pkg.SeqCount();
xinfo("Processed: %lld, aligned: %lld. Iterative edges: %llu\n", num_total_reads, num_aligned_reads,
xinfo("Processed: {}, aligned: {}. Iterative edges: {}\n", num_total_reads, num_aligned_reads,
collector.collection().size());
}
collector.FlushToFile();
xinfo("Total: %lld, aligned: %lld. Iterative edges: %llu\n", num_total_reads, num_aligned_reads,
xinfo("Total: {}, aligned: {}. Iterative edges: {}\n", num_total_reads, num_aligned_reads,
collector.collection().size());
return true;
}
Expand Down Expand Up @@ -153,16 +153,16 @@ static void ReadContigsAndBuildIndex(const Option &opt, const std::string &file_
if (contig_pkg.SeqCount() == 0) {
break;
}
xinfo("Read %lu contigs\n", contig_pkg.SeqCount());
xinfo("Read {} contigs\n", contig_pkg.SeqCount());
index->FeedBatchContigs(contig_pkg, mul);
xinfo("Number of flank kmers: %lu\n", index->size());
xinfo("Number of flank kmers: {}\n", index->size());
}
}

template <class KmerType>
bool KmerTypeSelectAndRun(const Option &opt) {
if (KmerType::max_size() >= static_cast<unsigned>(opt.kmer_k + 1)) {
xinfo("Selected kmer type size for k: %u\n", sizeof(KmerType));
xinfo("Selected kmer type size for k: {}\n", sizeof(KmerType));
ContigFlankIndex<KmerType> index(opt.kmer_k, opt.step);
ReadContigsAndBuildIndex(opt, opt.contig_file, &index);
ReadContigsAndBuildIndex(opt, opt.bubble_file, &index);
Expand Down
Loading

0 comments on commit 2217fc6

Please sign in to comment.