From: Diane Trout Date: Wed, 9 Aug 2006 01:08:35 +0000 (+0000) Subject: start breaking save out from Mussa::analyze() X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=mussa.git;a=commitdiff_plain;h=f464cbe60bbb56066a8120a760802b53c398e062 start breaking save out from Mussa::analyze() 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. --- diff --git a/alg/mussa.cpp b/alg/mussa.cpp index dc86cba..1c35273 100644 --- a/alg/mussa.cpp +++ b/alg/mussa.cpp @@ -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 << "" << 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 << "" << endl; - for(vector::size_type i = 0; i < the_seqs.size(); i++) - { - the_seqs[i]->save(save_file); - } + for(vector::size_type i = 0; i < the_seqs.size(); i++) + { + the_seqs[i]->save(save_file); + } - save_file << "" << endl; - save_file.close(); + save_file << "" << 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::size_type i = 0; i < the_seqs.size(); i++) - for(vector::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::size_type i = 0; i < the_seqs.size(); i++) { + for(vector::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; } diff --git a/alg/mussa.hpp b/alg/mussa.hpp index dbb04f5..7aa9c46 100644 --- a/alg/mussa.hpp +++ b/alg/mussa.hpp @@ -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 diff --git a/alg/parse_options.cpp b/alg/parse_options.cpp index 4cafee0..cc7ec63 100644 --- a/alg/parse_options.cpp +++ b/alg/parse_options.cpp @@ -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 >() ); diff --git a/alg/test/test_mussa.cpp b/alg/test/test_mussa.cpp index 4a0a476..7340feb 100644 --- a/alg/test/test_mussa.cpp +++ b/alg/test/test_mussa.cpp @@ -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 ) diff --git a/mussa_exceptions.hpp b/mussa_exceptions.hpp index 2f327b7..9adb529 100644 --- a/mussa_exceptions.hpp +++ b/mussa_exceptions.hpp @@ -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 {