use Qt Signals & Slots for progress tracking
[mussa.git] / alg / mussa.cpp
index 0dabf5b435274af524935f8654212c1f28d73a14..26ff98a8d9cef4a8bb213c1b0c8a8a2027981a9a 100644 (file)
@@ -11,6 +11,7 @@
 //                        ----------------------------------------
 //                          ---------- mussa_class.cc -----------
 //                        ----------------------------------------
+
 #include <boost/filesystem/operations.hpp>
 #include <boost/filesystem/fstream.hpp>
 namespace fs = boost::filesystem;
@@ -24,14 +25,12 @@ 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();
+  connect(&the_paths, SIGNAL(progress(const std::string&, int, int)), 
+          this, SIGNAL(progress(const std::string&, int, int)));
 }
 
 Mussa::Mussa(const Mussa& m)
@@ -42,10 +41,11 @@ 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)
 {
+  connect(&the_paths, SIGNAL(progress(const std::string&, int, int)), 
+          this, SIGNAL(progress(const std::string&, int, int)));
 }
 
 // set all parameters to null state
@@ -59,9 +59,9 @@ Mussa::clear()
   soft_thres = 0;
   win_append = false;
   thres_append = false;
-  analysis_cb = callback;
   motif_sequences.clear();
   color_mapper.clear();
+  the_paths.clear();
 }
 
 // these 5 simple methods manually set the parameters for doing an analysis
@@ -87,17 +87,6 @@ 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)
 {
@@ -443,7 +432,6 @@ Mussa::analyze()
   end = time(NULL);
   totaltime = difftime(end, begin);
 
-
   //cout << "seqload\tseqcomp\tnway\tsave\ttotal\n";
   //cout << seqloadtime << "\t";
   //cout << seqcomptime << "\t";
@@ -467,11 +455,12 @@ Mussa::seqcomp()
     for(vector<Sequence>::size_type i2 = 0; i2 < the_seqs.size(); i2++)
       all_comps[i].push_back(dummy_comp);
   }
-  for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
+  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;
+  emit progress("seqcomp", seqcomps_done, seqcomps_todo);
 
   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++)
@@ -481,9 +470,7 @@ Mussa::seqcomp()
       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);
-      } 
+      emit progress("seqcomp", seqcomps_done, seqcomps_todo);
     }
 }
 
@@ -493,7 +480,6 @@ 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);