start breaking save out from Mussa::analyze()
authorDiane Trout <diane@caltech.edu>
Wed, 9 Aug 2006 01:08:35 +0000 (01:08 +0000)
committerDiane Trout <diane@caltech.edu>
Wed, 9 Aug 2006 01:08:35 +0000 (01:08 +0000)
This patch changes Mussa::save() to take a boost::filesystem::path
so we have some hope of saving to a specified location.

However so the application will continue to work while I go try
the boost::serialize path, I left the save() call in analyze(), so
it will continue to auto-save.

For this to work I'll need to add a save option to the gui and
remove the save call in analyze.

(Though I did leave the save() call in parse_option that will
force saving a run when launched from the command line.

alg/mussa.cpp
alg/mussa.hpp
alg/parse_options.cpp
alg/test/test_mussa.cpp
mussa_exceptions.hpp

index dc86cba1b8bc97230d1e7e4faa01c5cc543e9046..1c35273afffc485217abedf4b37bb8c86fd4bcf2 100644 (file)
@@ -416,47 +416,19 @@ Mussa::load_mupa_file(fs::path para_file_path)
 void
 Mussa::analyze()
 {
-  time_t t1, t2, begin, end;
-  double seqloadtime, seqcomptime, nwaytime, savetime, totaltime;
-
-  begin = time(NULL);
-
-  t1 = time(NULL);
-        
   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);
-
-  t1 = time(NULL);
   seqcomp();
-  t2 = time(NULL);
-  seqcomptime = difftime(t2, t1);
-
-  t1 = time(NULL);
   the_paths.setup(window, threshold);
   nway();
-  t2 = time(NULL);
-  nwaytime = difftime(t2, t1);
-
-  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";
-  //cout << seqloadtime << "\t";
-  //cout << seqcomptime << "\t";
-  //cout << nwaytime << "\t";
-  //cout << savetime << "\t";
-  //cout << totaltime << "\n";
+  // FIXME: once we implement a save feature we should remove this
+  if (not analysis_name.empty()) {
+    save();
+  }
 }
 
 void
@@ -527,62 +499,59 @@ Mussa::nway()
 }
 
 void
-Mussa::save()
+Mussa::save(fs::path save_path)
 {
-  string save_name;
   fs::path flp_filepath;
   fs::fstream save_file;
   ostringstream append_info;
   int dir_create_status;
 
-  if (not analysis_name.empty()) {
-    // not sure why, but gotta close file each time since can't pass 
-    // file streams
-    save_name = analysis_name;
-
-    // gotta do bit with adding win & thres if to be appended
-    if (win_append)
-    {
-      append_info.str("");
-      append_info <<  "_w" << window;
-      save_name += append_info.str();
-    }
+  if (save_path.empty()) {
+    if (not analysis_name.empty()) {
+      std::string save_name = analysis_name;
+       // gotta do bit with adding win & thres if to be appended
+       if (win_append) {
+        append_info.str("");
+        append_info <<  "_w" << window;
+        save_name += append_info.str();
+      }
 
-    if (thres_append)
-    {
-      append_info.str("");
-      append_info <<  "_t" << threshold;
-      save_name += append_info.str();
+      if (thres_append) {
+        append_info.str("");
+        append_info <<  "_t" << threshold;
+        save_name += append_info.str();
+      }
+      save_path = save_name;
+    } else {
+      throw mussa_save_error("Need filename or analysis name to save");
     }
-    fs::path save_path( save_name);
+  }
 
-    if (not fs::exists(save_path)) {
-      fs::create_directory(save_path);
-    }
-    // save sequence and annots to a special mussa file
-    save_file.open(save_path / (save_name+".museq"), ios::out);
-    save_file << "<Mussa_Sequence>" << endl;
+  if (not fs::exists(save_path)) {
+    fs::create_directory(save_path);
+  }
+  // save sequence and annots to a special mussa file
+  save_file.open(save_path / (save_path.leaf()+".museq"), ios::out);
+  save_file << "<Mussa_Sequence>" << endl;
 
-    for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
-    {
-      the_seqs[i]->save(save_file);
-    }
+  for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
+  {
+    the_seqs[i]->save(save_file);
+  }
 
-    save_file << "</Mussa_Sequence>" << endl;
-    save_file.close();
+  save_file << "</Mussa_Sequence>" << endl;
+  save_file.close();
 
-    // save nway paths to its mussa save file
-    the_paths.save(save_path / (save_name + ".muway"));
+  // save nway paths to its mussa save file
+  the_paths.save(save_path / (save_path.leaf()+ ".muway"));
 
-    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++)
-      {
-        append_info.str("");
-        append_info <<  "_sp_" << i << "v" << i2;
-        all_comps[i][i2].save(save_path/(save_name+append_info.str()+".flp"));
-      }
-  } else {
-    throw mussa_error("Can't save analysis without an analysis name");
+  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++)
+    {
+      append_info.str("");
+      append_info <<  "_sp_" << i << "v" << i2;
+      all_comps[i][i2].save(save_path/(save_path.leaf()+append_info.str()+".flp"));
+    }
   }
   dirty = false;
 }
index dbb04f5ce9dfab73e9d84d13dbae142b06f9d78c..7aa9c465d9b53cebfeb48e064ee49e8836fc3311 100644 (file)
@@ -46,7 +46,8 @@ public:
     Mussa();
     Mussa(const Mussa &);
 
-    void save();
+    //! save all of mussa
+    void save(boost::filesystem::path save_path="");
     //! save the nway comparison
     void save_muway(boost::filesystem::path save_path);
     //! load a saved analysis directory
index 4cafee0d213924f4c111ee455c012141cacc86c4..cc7ec632a48a884edbeca26350971b8a11aa162d 100644 (file)
@@ -48,6 +48,8 @@ void initialize_mussa(MussaOptions& opts, int argc, char **argv)
     std::cout << "I apologize for blocking the gui while running the analysis"
               << std::endl;
     opts.analysis->analyze();
+    if (opts.analysis->is_dirty())
+      opts.analysis->save();
   }
   else if (vm.count("view-analysis")) {
     opts.analysis->load( vm["view-analysis"].as< std::string >() );
index 4a0a4765f45069e8fc7c6d40e0476499c20ec65e..7340feb86e7609bda2c606e1eeb300e354b1ca70 100644 (file)
@@ -91,20 +91,20 @@ BOOST_AUTO_TEST_CASE ( empty_mussa_set_threshold )
 BOOST_AUTO_TEST_CASE( mussa_load_mupa )
 {
   fs::path mupa_path(EXAMPLE_DIR);
+  fs::path result_path = fs::initial_path() / "mck3test_w30_t20";
   mupa_path /= "mck3test.mupa";
 
   Mussa m1;
   m1.load_mupa_file( mupa_path );
   m1.analyze();
+  m1.save( result_path );
   BOOST_CHECK_EQUAL( m1.get_name(), std::string("mck3test") );
   BOOST_CHECK( m1.size() > 0 );
 
   Mussa m2;
-  fs::path result_path = fs::initial_path() / "mck3test_w30_t20";
   m2.load( result_path );
   BOOST_CHECK_EQUAL( m2.get_name(), result_path.leaf() );
   BOOST_CHECK_EQUAL( m1.size(), m2.size() );
-
 }
 
 BOOST_AUTO_TEST_CASE( mussa_load_full_path )
index 2f327b73859a54c579ad9bee64939ff18c81eb4f..9adb5299f58dee677f2633f03488e163e69f91fb 100644 (file)
@@ -16,7 +16,13 @@ class cmdline_error : public mussa_error
 public:
   explicit cmdline_error(const std::string& msg): mussa_error(msg) {};
 };
-
+//! Error trying to save 
+class mussa_save_error : public mussa_error
+{
+public:
+  explicit mussa_save_error(const std::string& msg) :
+    mussa_error(msg) {};
+};
 //! Error loading information
 class mussa_load_error : public mussa_error
 {