Skip to content

Commit

Permalink
fixing printout
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-james committed Oct 22, 2018
1 parent 61e031e commit b7ff713
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Usage: bin/meshclust2 --id 0.x [OPTIONS] *.fasta
--threads sets the number of threads to be used. By default OpenMP uses the number of available cores
on your machine, but this parameter overwrites that.

--quiet (no arguments) removes the progress bars from output

--output specifies the output file, in CD-HIT's CLSTR format, described below:
A '>Cluster ' followed by an increasing index designates a cluster.
Otherwise, the sequence is printed out.
Expand Down
10 changes: 7 additions & 3 deletions src/cluster/src/Predictor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,16 @@ void Predictor<T>::train(const vector<Point<T> *> &points, const vector<Point<T>
size_t counter = 0;
// struct timespec start, stop;
// clock_gettime(CLOCK_MONOTONIC, &start);
Progress prog(f_points_tr.size(), "Generating training data");
#pragma omp parallel for
for (size_t i = 0; i < f_points_tr.size(); i++) {
auto p = f_points_tr[i];
mutate_seqs(p, 5, pos_buf, neg_buf, 100 * id, 100, _id);
mutate_seqs(p, 5, pos_buf, neg_buf, min_id, 100 * id, _id);
#pragma omp critical
cout << "Generated " << ++counter << " / " << f_points_tr.size() << endl;
prog++;
}
prog.end();
// clock_gettime(CLOCK_MONOTONIC, &stop);
// printf("took %lu\n", stop.tv_sec - start.tv_sec);

Expand All @@ -387,14 +389,16 @@ void Predictor<T>::train(const vector<Point<T> *> &points, const vector<Point<T>
}
pos_buf.clear();
neg_buf.clear();
Progress prog2(f_points_test.size(), "Generating test data");
#pragma omp parallel for
for (size_t i = 0; i < f_points_test.size(); i++) {
auto p = f_points_test[i];
mutate_seqs(p, 5, pos_buf, neg_buf, 100 * id, 100, _id);
mutate_seqs(p, 5, pos_buf, neg_buf, min_id, 100 * id, _id);
#pragma omp critical
cout << "Generated " << ++counter << " / " << f_points_test.size() << endl;
prog2++;
}
prog2.end();
buf_size = std::min(pos_buf.size(), neg_buf.size());
cout << "testing +: " << pos_buf.size() << endl;
cout << "testing -: " << neg_buf.size() << endl;
Expand Down Expand Up @@ -739,7 +743,7 @@ void Predictor<T>::train_class(Feature<T>* feat)
feat->finalize();
abs_best_acc = best_class_acc;
used_list.push_back(best_idx);
oss << "Feature added: " << best_class_feat.first << " " << (int)best_class_feat.second << endl;
// oss << "Feature added: " << best_class_feat.first << " " << (int)best_class_feat.second << endl;
oss << "Accuracy: " << best_class_acc << endl;
possible_feats.erase(std::remove(possible_feats.begin(), possible_feats.end(), best_class_feat), possible_feats.end());
}
Expand Down
9 changes: 9 additions & 0 deletions src/cluster/src/Progress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
#include <iostream>
#include <sstream>

bool Progress::is_quiet = false;

void Progress::set_quiet(bool is_quiet_)
{
is_quiet = is_quiet_;
}
Progress::Progress(long num, std::string prefix_)
{
pmax = num;
Expand All @@ -15,6 +21,9 @@ Progress::Progress(long num, std::string prefix_)

void Progress::print()
{
if (is_quiet) {
return;
}
std::ostringstream oss;
double prog = (double)pcur / pmax;
oss << prefix << " [";
Expand Down
2 changes: 2 additions & 0 deletions src/cluster/src/Progress.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

class Progress {
public:
static void set_quiet(bool is_quiet_=true);
static bool is_quiet;
Progress(long num, std::string prefix_);
~Progress() { end(); }
void end();
Expand Down
2 changes: 2 additions & 0 deletions src/cluster/src/Runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ void Runner::get_opts(int argc, char **argv)
}

i++;
} else if (arg == "-q" || arg == "--quiet") {
Progress::set_quiet(true);
} else if ((arg == "-t" || arg == "--threads") && i + 1 < argc) {
try {
std::string opt = argv[i+1];
Expand Down
1 change: 0 additions & 1 deletion src/cluster/src/Trainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,6 @@ void Trainer<T>::train(int min_n_feat, int max_n_feat, uint64_t feat_type, int m
{

if (k != 0) {
std::cout << "Splitting data" << endl;
uintmax_t _id = points.size();
Predictor<T> pred(k, cutoff, PRED_MODE_CLASS, feat_type,
mut_type, min_n_feat, max_n_feat, min_id);
Expand Down

0 comments on commit b7ff713

Please sign in to comment.