Skip to content

Commit

Permalink
Silent mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jnalanko committed Nov 24, 2021
1 parent f18aa8f commit 27bcca8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/KMC_wrapper.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
using namespace std;

// Only works for alphabet {a,c,g,t,A,C,G,T}
void KMC_wrapper(int64_t k, int64_t ram_gigas, int64_t n_threads, string fastafile, string tempdir, string database_filename_prefix, bool only_canonical_kmers);
void KMC_wrapper(int64_t k, int64_t ram_gigas, int64_t n_threads, string fastafile, string tempdir, string database_filename_prefix, bool only_canonical_kmers, bool silent);
2 changes: 1 addition & 1 deletion include/Themisto.hh
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public:

write_log("Building KMC database", LogLevel::MAJOR);
string KMC_db_path_prefix = get_temp_file_manager().create_filename("KMC-");
KMC_wrapper(k+1, max(1LL, memory_bytes / (1LL << 30)), n_threads, fastafile, get_temp_file_manager().get_dir(), KMC_db_path_prefix, revcomps);
KMC_wrapper(k+1, max(1LL, memory_bytes / (1LL << 30)), n_threads, fastafile, get_temp_file_manager().get_dir(), KMC_db_path_prefix, revcomps, get_log_level() == LogLevel::OFF);
write_log("Building KMC database finished", LogLevel::MAJOR);
Kmer_stream_from_KMC_DB edgemer_stream(KMC_db_path_prefix, revcomps);
BOSS_builder<BOSS<sdsl::bit_vector>, Kmer_stream_from_KMC_DB> builder;
Expand Down
1 change: 1 addition & 0 deletions include/globals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ long long cur_time_millis();
double seconds_since_program_start();
string getTimeString();
void set_log_level(LogLevel level);
LogLevel get_log_level();
void write_log(string message, LogLevel level);
map<string,vector<string> > parse_args(int argc, char** argv);
string figure_out_file_format(string filename);
Expand Down
2 changes: 1 addition & 1 deletion include/libwheeler/BOSS_tests.hh
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void test_construction(BOSS_TestCase& tcase, bool reverse_complements){
for(string S : tcase.reads) out << ">\n" << S << "\n";
out.flush();
string KMC_db_path_prefix = get_temp_file_manager().create_filename("KMC");
KMC_wrapper(tcase.k+1, 1, 2, fastafile, get_temp_file_manager().get_dir(), KMC_db_path_prefix, reverse_complements);
KMC_wrapper(tcase.k+1, 1, 2, fastafile, get_temp_file_manager().get_dir(), KMC_db_path_prefix, reverse_complements, get_log_level() == LogLevel::OFF);
Kmer_stream_from_KMC_DB kmer_stream(KMC_db_path_prefix, reverse_complements);
BOSS_builder<boss_t, Kmer_stream_from_KMC_DB> bb;
boss_t boss_KMC = bb.build(kmer_stream, 1e9, 2);
Expand Down
25 changes: 17 additions & 8 deletions src/KMC_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,12 @@ void call_kmc(int argc, _TCHAR* argv[])
}

// Only works for alphabet {a,c,g,t,A,C,G,T}
void KMC_wrapper(int64_t k, int64_t ram_gigas, int64_t n_threads, string fastafile, string tempdir, string database_filename_prefix, bool only_canonical_kmers){
void KMC_wrapper(int64_t k, int64_t ram_gigas, int64_t n_threads, string fastafile, string tempdir, string database_filename_prefix, bool only_canonical_kmers, bool silent){

// Check that the alphabet is {a,c,g,t,A,C,G,T} (otherwise k-mers would be dropped silently)
throwing_ifstream fasta_input(fastafile);
string line;
cerr << "Validating input alphabet" << endl;
if(!silent) cerr << "Validating input alphabet" << endl;
while(getline(fasta_input.stream, line)){
if(line.size() > 0 && line[0] != '>'){
for(char c : line){
Expand All @@ -511,13 +511,22 @@ void KMC_wrapper(int64_t k, int64_t ram_gigas, int64_t n_threads, string fastafi
if(!only_canonical_kmers){
argv.insert(argv.begin()+1, "-b");
}
if(silent){
std::stringstream buffer; // Redirect stderr here
std::streambuf* old = std::cerr.rdbuf(buffer.rdbuf());

cerr << "Calling KMC with: ";
for(string S : argv) cerr << S << " ";
cerr << endl;

Argv A(argv);
call_kmc(argv.size(), A.array);
Argv A(argv);
call_kmc(argv.size(), A.array);

std::cerr.rdbuf(old); // Restore cerr
}

else{ // Not silent
cerr << "Calling KMC with: ";
for(string S : argv) cerr << S << " ";
cerr << endl;
Argv A(argv);
call_kmc(argv.size(), A.array);
}
}

3 changes: 3 additions & 0 deletions src/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ static LogLevel loglevel = MAJOR;
void set_log_level(LogLevel level){
loglevel = level;
}
LogLevel get_log_level(){
return loglevel;
}

static std::mutex write_log_mutex;
void write_log(string message, LogLevel level){
Expand Down

0 comments on commit 27bcca8

Please sign in to comment.