add callback for tracking analysis progress
[mussa.git] / alg / mussa.cpp
index 003f68aac8e045e2b8b309133c2914b75b167f2e..0dabf5b435274af524935f8654212c1f28d73a14 100644 (file)
@@ -24,6 +24,11 @@ namespace fs = boost::filesystem;
 
 using namespace std;
 
+void callback(const std::string& desc, int cur, int end)
+{
+  std::cout << "analysis:" << desc << " " << cur << "/" << end << std::endl;
+}
+
 Mussa::Mussa()
 {
   clear();
@@ -37,6 +42,7 @@ Mussa::Mussa(const Mussa& m)
     ana_mode(m.ana_mode),
     win_append(m.win_append),
     thres_append(m.thres_append),
+    analysis_cb(m.analysis_cb),
     motif_sequences(m.motif_sequences),
     color_mapper(m.color_mapper)
 {
@@ -53,6 +59,7 @@ Mussa::clear()
   soft_thres = 0;
   win_append = false;
   thres_append = false;
+  analysis_cb = callback;
   motif_sequences.clear();
   color_mapper.clear();
 }
@@ -80,6 +87,17 @@ Mussa::size() const
     return 0;
 }
 
+
+void Mussa::set_analysis_callback(analysis_callback cb)
+{
+  analysis_cb = cb;
+}
+
+analysis_callback Mussa::get_analysis_calback() const
+{
+  return analysis_cb;
+}
+
 void
 Mussa::set_window(int a_window)
 {
@@ -388,23 +406,13 @@ Mussa::load_mupa_file(fs::path para_file_path)
 
 
 void
-Mussa::analyze(int w, int t, enum Mussa::analysis_modes the_ana_mode, double new_ent_thres)
+Mussa::analyze()
 {
   time_t t1, t2, begin, end;
   double seqloadtime, seqcomptime, nwaytime, savetime, totaltime;
 
   begin = time(NULL);
 
-  ana_mode = the_ana_mode;
-  ent_thres = new_ent_thres;
-  if (w > 0)
-    window  = w;
-  if (t > 0)
-  {
-    threshold = t;
-    soft_thres = t;
-  }
-
   t1 = time(NULL);
         
   if (the_seqs.size() < 2) {
@@ -421,7 +429,6 @@ Mussa::analyze(int w, int t, enum Mussa::analysis_modes the_ana_mode, double new
   t2 = time(NULL);
   seqcomptime = difftime(t2, t1);
 
-
   t1 = time(NULL);
   the_paths.setup(window, threshold);
   nway();
@@ -463,6 +470,9 @@ Mussa::seqcomp()
   for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
     seq_lens.push_back(the_seqs[i].size());
 
+  int seqcomps_done = 0;
+  int seqcomps_todo = (the_seqs.size() * (the_seqs.size()-1)) / 2;
+
   for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
     for(vector<Sequence>::size_type i2 = i+1; i2 < the_seqs.size(); i2++)
     {
@@ -470,6 +480,10 @@ Mussa::seqcomp()
       all_comps[i][i2].setup(window, threshold);
       all_comps[i][i2].seqcomp(the_seqs[i].get_seq(), the_seqs[i2].get_seq(), false);
       all_comps[i][i2].seqcomp(the_seqs[i].get_seq(),the_seqs[i2].rev_comp(),true);
+      ++seqcomps_done;
+      if (analysis_cb) {
+        analysis_cb("seqcomp", seqcomps_done, seqcomps_todo);
+      } 
     }
 }
 
@@ -479,6 +493,7 @@ Mussa::nway()
   vector<string> some_Seqs;
 
   the_paths.set_soft_threshold(soft_thres);
+  the_paths.set_progress_callback(analysis_cb);
 
   if (ana_mode == TransitiveNway) {
     the_paths.trans_path_search(all_comps);