use exceptions to indicate Mussa::analyze failed
authorDiane Trout <diane@caltech.edu>
Fri, 24 Feb 2006 01:08:54 +0000 (01:08 +0000)
committerDiane Trout <diane@caltech.edu>
Fri, 24 Feb 2006 01:08:54 +0000 (01:08 +0000)
also modified the fltk gui code to report the exception text.

alg/mussa_class.cxx
alg/mussa_class.hh
gui/ConnWindow.cxx
gui/SetupWindow.cxx
gui/SubAnalysisWindow.cxx
mussa.cxx
mussa_exceptions.hh

index 72390925a6e850c9ded516e1db53da6c7f0c5d52..2efdcddc80fb234916ef6b52da1f831adb1fed5d 100644 (file)
@@ -126,6 +126,11 @@ string Mussa::get_analysis_mode_name() const
   }
 }
 
+Nway_Paths& Mussa::get_paths()
+{
+  return the_paths;
+}
+
 // takes a string and sets it as the next seq 
 void
 Mussa::add_a_seq(string a_seq)
@@ -283,24 +288,14 @@ Mussa::load_mupa_file(string para_file_path)
 }
 
 
-string
+void
 Mussa::analyze(int w, int t, enum Mussa::analysis_modes the_ana_mode, double new_ent_thres)
 {
-  string err_msg;
   time_t t1, t2, begin, end;
   double setuptime, seqloadtime, seqcomptime, nwaytime, savetime, totaltime;
 
-
-  cout << "nway ana: sequence count = " << the_seqs.size() << endl;
-
   begin = time(NULL);
 
-  // now loading parameters from file must be done separately
-  //t1 = time(NULL);
-  //err_msg = load_mupa_file(para_file_path);
-  //t2 = time(NULL);
-  //setuptime = difftime(t2, t1);
-
   ana_mode = the_ana_mode;
   ent_thres = new_ent_thres;
   if (w > 0)
@@ -311,60 +306,52 @@ Mussa::analyze(int w, int t, enum Mussa::analysis_modes the_ana_mode, double new
     soft_thres = t;
   }
 
-  //if (err_msg == "")
-  //{
-    cout << "fee\n";
-    t1 = time(NULL);
-    try {
-      load_sequence_data();
-    } catch(sequence_load_error e) {
-      cerr << "Unable to load sequence" << endl;
-      cerr << e.what() << endl;
-    }
+  t1 = time(NULL);
+  try {
+    load_sequence_data();
+  } catch(sequence_load_error e) {
+    cerr << "Unable to load sequence" << endl;
+    cerr << e.what() << endl;
+  }
         
-    t2 = time(NULL);
-    seqloadtime = difftime(t2, t1);
+  if (the_seqs.size() < 2) {
+    throw mussa_analysis_error("you need to have at least 2 sequences to "
+                               "do an analysis.");
+  }
+  cout << "nway ana: seq_num = " << the_seqs.size() << endl;
 
+  t2 = time(NULL);
+  seqloadtime = difftime(t2, t1);
 
-    if (err_msg == "")
-    {
-      t1 = time(NULL);
-      seqcomp();
-      t2 = time(NULL);
-      seqcomptime = difftime(t2, t1);
+  t1 = time(NULL);
+  seqcomp();
+  t2 = time(NULL);
+  seqcomptime = difftime(t2, t1);
 
 
-      t1 = time(NULL);
-      the_paths.setup(the_seqs.size(), window, threshold);
-      nway();
-      t2 = time(NULL);
-      nwaytime = difftime(t2, t1);
+  t1 = time(NULL);
+  the_paths.setup(the_seqs.size(), window, threshold);
+  nway();
+  t2 = time(NULL);
+  nwaytime = difftime(t2, t1);
 
+  t1 = time(NULL);
+  save();
+  t2 = time(NULL);
+  savetime = difftime(t2, t1);
 
-      cout << "fum\n";
-      t1 = time(NULL);
-      save();
-      t2 = time(NULL);
-      savetime = difftime(t2, t1);
-
-      end = time(NULL);
-      totaltime = difftime(end, begin);
-
-
-      cout << "seqload\tseqcomp\tnway\tsave\ttotal\n";
-      //setup\t
-      //cout << setuptime << "\t"; 
-      cout << seqloadtime << "\t";
-      cout << seqcomptime << "\t";
-      cout << nwaytime << "\t";
-      cout << savetime << "\t";
-      cout << totaltime << "\n";
-    }
-    else
-      return err_msg;
-  //}
-  //else
-  //return err_msg;
+  end = time(NULL);
+  totaltime = difftime(end, begin);
+
+
+  cout << "seqload\tseqcomp\tnway\tsave\ttotal\n";
+  //setup\t
+  //cout << setuptime << "\t"; 
+  cout << seqloadtime << "\t";
+  cout << seqcomptime << "\t";
+  cout << nwaytime << "\t";
+  cout << savetime << "\t";
+  cout << totaltime << "\n";
 }
 
 
index 06466ca56afcca80b9bbb4270218aed245c54705..c85ceed04e134b91129008b523f389cd339d323c 100644 (file)
@@ -32,12 +32,6 @@ class Mussa
 
     Mussa();  
 
-    // parameters need to be set before calling this
-    // w & t are for command line override functionality, set to 0 to ignore
-    std::string analyze(int w=0, 
-                        int t=0, 
-                        enum analysis_modes ana_mode=TransitiveNway,
-                        double ent_thres=0.0);
     void save();
     void save_muway(std::string save_path);
     std::string load(std::string ana_file);
@@ -70,7 +64,22 @@ class Mussa
     enum analysis_modes get_analysis_mode() const;
     //! return a string name for an analysis mode
     std::string get_analysis_mode_name() const;
-    //! actually run the nway comparison
+
+    //! return the refined paths found by the nway analysis.
+    Nway_Paths& get_paths();
+
+    //! run seqcomp and the nway filtering algorithm.
+    /*!analyze will run seqcomp and then the nway algorithm
+     * on whatever sequences have been loaded into this mussa instance.
+     * w & t are for command line override functionality, set to 0 to ignore
+     * \throws mussa_analysis_error 
+     */
+    void analyze(int w=0, int t=0, 
+                 enum analysis_modes ana_mode=TransitiveNway,
+                 double ent_thres=0.0);
+    /*! Run the nway filtering algorithm, 
+     *  this might be used when changing the soft threshhold?
+     */
     void nway();
 
     //! appends a string sequence to the list of the_seqs
index f4638b423a6198f27951b1033b0d6020422187aa..50fda13a078d57428e9f050182dd3b7b7aa473f6 100644 (file)
@@ -9,6 +9,7 @@
 
 
 #include "ConnWindow.hh"
+#include "mussa_exceptions.hh"
 
 #include <iostream>
 using namespace std;
@@ -85,13 +86,8 @@ ConnWindow::real_do_ana_cb()
     an_analysis = new Mussa();
     err_msg = an_analysis->load_mupa_file(a_file_path);
 
-    if (err_msg == "")
-    {
-      err_msg = an_analysis->analyze(0, 0, Mussa::TransitiveNway, 0.0);
-    }
-
-    if (err_msg == "")
-    {
+    try {
+      an_analysis->analyze(0, 0, Mussa::TransitiveNway, 0.0);
       // relabel window with the analysis name
       window_name = "Mussa: " + an_analysis->get_name();
       label((const char*)window_name.c_str());
@@ -100,11 +96,8 @@ ConnWindow::real_do_ana_cb()
                      an_analysis->get_window(), &(an_analysis->the_seqs), 
                      &(an_analysis->the_paths));
       conn_box->scale_paths();
-    }
-    else
-    {
-      fl_alert(err_msg.c_str());
-      cout << err_msg;
+    } catch (mussa_analysis_error e) {
+      fl_alert(e.what());
     }
   }
 }
index f2695fbd2edf4c5d1a7f7717e4fe45f3b21f7616..4115218fdfa7de1a41db64466ea4b57c54094ce7 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "SetupWindow.hh"
 #include "alg/mussa_class.hh"
+#include "mussa_exceptions.hh"
 #include <iostream>
 #include <FL/Fl_File_Chooser.H>
 
@@ -48,12 +49,10 @@ SetupWindow::real_do_analysis()
     an_analysis->set_seq_info(seq_files[i], annot_files[i], fasta_indices[i],
                              sub_seq_starts[i], sub_seq_ends[i]);
 
-  err_msg = an_analysis->analyze();
-  //cout << "Feel the tribal beat\n";
-  if (!(err_msg == ""))
-  {
-    //fl_alert(err_msg.c_str());
-    cout << err_msg;
+  try {
+    an_analysis->analyze();
+  } catch (mussa_analysis_error e) {
+    fl_alert(e.what());
   }
 
   all_done = true;
index 89bccba8af450950580bbc092084baebc6f8d627..b808f4a1668876dc3d335f1a251f8eb77d376acf 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "SubAnalysisWindow.hh"
 #include "alg/mussa_class.hh"
+#include "mussa_exceptions.hh"
 
 #include <iostream>
 using namespace std;
@@ -46,13 +47,10 @@ SubAnalysisWindow::real_do_subana()
     an_analysis->add_a_seq(a_sequence);
   }
 
-  err_msg = an_analysis->analyze();
-
-  cout << "Feel the tribal beat\n";
-  if (!(err_msg == ""))
-  {
-    //fl_alert(err_msg.c_str());
-    cout << err_msg;
+  try {
+    an_analysis->analyze();
+  } catch( mussa_analysis_error e) {
+    fl_alert( e.what() );
   }
 
   all_done = true;
index f9fb661007c5c9b8539c86fb2dd934c6a596f966..6a54d01c0a24e95425cc59161d07ef7b3127cb92 100644 (file)
--- a/mussa.cxx
+++ b/mussa.cxx
@@ -52,7 +52,7 @@ int main(int argc, char **argv)
     if ((run_mode == 'f') || (run_mode == 'n'))
     {
       err_msg = an_analysis.load_mupa_file(a_file_path);
-      err_msg = an_analysis.analyze(window, threshold, ana_mode, ent_thres);
+      an_analysis.analyze(window, threshold, ana_mode, ent_thres);
       //an_overlord.do_analysis();
     }
 
index a0fb2ba2379664fc0c9f3b7a06e83754d13a4228..2054f096f96852b5f2034e454f43563251a873e7 100644 (file)
@@ -16,4 +16,12 @@ public:
   explicit sequence_load_error(const std::string& msg) : 
     std::runtime_error(msg) {};
 };
+
+//! failure running analysis
+class mussa_analysis_error : public std::runtime_error
+{
+public:
+  explicit mussa_analysis_error(const std::string& msg) : 
+    std::runtime_error(msg) {};
+};
 #endif