Skip to content

Commit fafe54d

Browse files
author
Rob Patro
committed
quiet mode and fix some typos
1 parent 227a83e commit fafe54d

3 files changed

Lines changed: 57 additions & 16 deletions

File tree

include/RapMapConfig.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626

2727
namespace rapmap {
2828
constexpr char majorVersion[] = "0";
29-
constexpr char minorVersion[] = "3";
29+
constexpr char minorVersion[] = "4";
3030
constexpr char patchVersion[] = "0";
31-
constexpr char version [] = "0.3.0";
32-
constexpr uint32_t indexVersion = 2;
31+
constexpr char version [] = "0.4.0";
32+
constexpr uint32_t indexVersion = 3;
3333
}
3434

3535
#endif //__RAPMAP_CONFIG_HPP__

include/ScopedTimer.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@ struct ScopedTimer
2929
{
3030
std::chrono::high_resolution_clock::time_point t0;
3131

32-
ScopedTimer()
33-
: t0(std::chrono::high_resolution_clock::now())
32+
ScopedTimer(bool print=true)
33+
: t0(std::chrono::high_resolution_clock::now()), print_(print)
3434
{ }
3535
~ScopedTimer(void)
3636
{
3737
auto t1 = std::chrono::high_resolution_clock::now();
3838
std::chrono::duration<double> elapsedSec = t1 - t0;
39-
std::cerr << "Elapsed time: " << elapsedSec.count() << "s\n";
39+
if (print_) { std::cerr << "Elapsed time: " << elapsedSec.count() << "s\n"; }
4040
}
41+
42+
private:
43+
bool print_;
4144
};
4245

4346
#endif //__SCOPED_TIMER_HPP__

src/RapMapSAMapper.cpp

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ struct MappingOpts {
127127
bool strictCheck{false};
128128
bool fuzzy{false};
129129
bool consistentHits{false};
130+
bool quiet{false};
130131
};
131132

132133
template <typename RapMapIndexT, typename MutexT>
@@ -196,7 +197,7 @@ void processReadsSingleSA(single_parser * parser,
196197

197198
if (hctr.numReads > hctr.lastPrint + 1000000) {
198199
hctr.lastPrint.store(hctr.numReads.load());
199-
if (iomutex->try_lock()){
200+
if (!mopts->quiet and iomutex->try_lock()){
200201
if (hctr.numReads > 0) {
201202
#if defined(__DEBUG__) || defined(__TRACK_CORRECT__)
202203
std::cerr << "\033[F\033[F\033[F";
@@ -332,7 +333,7 @@ void processReadsPairSA(paired_parser* parser,
332333

333334
if (hctr.numReads > hctr.lastPrint + 1000000) {
334335
hctr.lastPrint.store(hctr.numReads.load());
335-
if (iomutex->try_lock()) {
336+
if (!mopts->quiet and iomutex->try_lock()) {
336337
if (hctr.numReads > 0) {
337338
std::cerr << "\r\r";
338339
}
@@ -422,7 +423,7 @@ template <typename RapMapIndexT>
422423
bool mapReads(RapMapIndexT& rmi,
423424
std::shared_ptr<spdlog::logger> consoleLog,
424425
MappingOpts* mopts) {
425-
std::cerr << "\n\n\n\n";
426+
if (!mopts->quiet) { std::cerr << "\n\n\n\n"; }
426427

427428
bool pairedEnd = mopts->pairedEnd;//(read1.isSet() or read2.isSet());
428429
// from: http://stackoverflow.com/questions/366955/obtain-a-stdostream-either-from-stdcout-or-stdofstreamfile
@@ -460,7 +461,7 @@ bool mapReads(RapMapIndexT& rmi,
460461
size_t chunkSize{10000};
461462
SpinLockT iomutex;
462463
{
463-
ScopedTimer timer;
464+
ScopedTimer timer(!mopts->quiet);
464465
HitCounters hctrs;
465466
consoleLog->info("mapping reads . . . \n\n\n");
466467
if (pairedEnd) {
@@ -489,7 +490,7 @@ bool mapReads(RapMapIndexT& rmi,
489490
spawnProcessReadsThreads(nthread, singleParserPtr.get(), rmi, iomutex,
490491
outLog, hctrs, mopts);
491492
}
492-
std::cerr << "\n\n";
493+
if (!mopts->quiet) { std::cerr << "\n\n"; }
493494

494495

495496
consoleLog->info("Done mapping reads.");
@@ -510,9 +511,32 @@ bool mapReads(RapMapIndexT& rmi,
510511
return true;
511512
}
512513

513-
int rapMapSAMap(int argc, char* argv[]) {
514-
std::cerr << "RapMap Mapper (SA-based)\n";
514+
void displayOpts(MappingOpts& mopts, spdlog::logger* log) {
515+
fmt::MemoryWriter optWriter;
516+
optWriter.write("\ncommand line options\n"
517+
"====================\n");
518+
optWriter.write("index: {}\n", mopts.index);
519+
if (mopts.pairedEnd) {
520+
optWriter.write("read(s) 1: {}\n", mopts.read1);
521+
optWriter.write("read(s) 2: {}\n", mopts.read2);
522+
} else {
523+
optWriter.write("unmated read(s): {}\n", mopts.unmatedReads);
524+
}
525+
optWriter.write("output: {}\n", mopts.outname);
526+
optWriter.write("num. threads: {}\n", mopts.numThreads);
527+
optWriter.write("max num. hits: {}\n", mopts.maxNumHits);
528+
optWriter.write("quasi-coverage: {}\n", mopts.quasiCov);
529+
optWriter.write("no output: {}\n", mopts.noOutput);
530+
optWriter.write("sensitive: {}\n", mopts.sensitive);
531+
optWriter.write("strict check: {}\n", mopts.strictCheck);
532+
optWriter.write("fuzzy intersection: {}\n", mopts.fuzzy);
533+
optWriter.write("consistent hits: {}\n", mopts.consistentHits);
534+
optWriter.write("====================");
535+
log->info(optWriter.str());
536+
}
515537

538+
539+
int rapMapSAMap(int argc, char* argv[]) {
516540
std::string versionString = rapmap::version;
517541
TCLAP::CmdLine cmd(
518542
"RapMap Mapper",
@@ -533,6 +557,7 @@ int rapMapSAMap(int argc, char* argv[]) {
533557
TCLAP::SwitchArg strict("s", "strictCheck", "Perform extra checks to try and assure that only equally \"best\" mappings for a read are reported", false);
534558
TCLAP::SwitchArg fuzzy("f", "fuzzyIntersection", "Find paired-end mapping locations using fuzzy intersection", false);
535559
TCLAP::SwitchArg consistent("c", "consistentHits", "Ensure that the hits collected are consistent (co-linear)", false);
560+
TCLAP::SwitchArg quiet("q", "quiet", "Disable all console output apart from warnings and errors", false);
536561
cmd.add(index);
537562
cmd.add(noout);
538563

@@ -547,16 +572,21 @@ int rapMapSAMap(int argc, char* argv[]) {
547572
cmd.add(strict);
548573
cmd.add(fuzzy);
549574
cmd.add(consistent);
550-
575+
cmd.add(quiet);
551576

552577
auto rawConsoleSink = std::make_shared<spdlog::sinks::stderr_sink_mt>();
553578
auto consoleSink =
554579
std::make_shared<spdlog::sinks::ansicolor_sink>(rawConsoleSink);
555580
auto consoleLog = spdlog::create("stderrLog", {consoleSink});
556-
581+
557582
try {
558583

559584
cmd.parse(argc, argv);
585+
// If we're supposed to be quiet, only print out warnings and above
586+
if (quiet.getValue()) {
587+
consoleLog->set_level(spdlog::level::warn);
588+
}
589+
560590
bool pairedEnd = (read1.isSet() or read2.isSet());
561591
if (pairedEnd and (read1.isSet() != read2.isSet())) {
562592
consoleLog->error("You must set both the -1 and -2 arguments to align "
@@ -587,7 +617,7 @@ int rapMapSAMap(int argc, char* argv[]) {
587617
"doesn't exist", indexPrefix);
588618
std::exit(1);
589619
}
590-
620+
591621
MappingOpts mopts;
592622
if (pairedEnd) {
593623
mopts.read1 = read1.getValue();
@@ -605,6 +635,14 @@ int rapMapSAMap(int argc, char* argv[]) {
605635
mopts.strictCheck = strict.getValue();
606636
mopts.consistentHits = consistent.getValue();
607637
mopts.fuzzy = fuzzy.getValue();
638+
mopts.quiet = quiet.getValue();
639+
640+
if (quasiCov.isSet() and !sensitive.isSet()) {
641+
consoleLog->info("The --quasiCoverage option is set to {}, but the --sensitive flag was not set. The former implies the later. Enabling sensitive mode.", quasiCov.getValue());
642+
mopts.sensitive = true;
643+
}
644+
645+
displayOpts(mopts, consoleLog.get());
608646

609647
IndexHeader h;
610648
std::ifstream indexStream(indexPrefix + "header.json");

0 commit comments

Comments
 (0)