track where our analysis is saved and if the analysis is empty
authorDiane Trout <diane@caltech.edu>
Tue, 12 Sep 2006 23:00:07 +0000 (23:00 +0000)
committerDiane Trout <diane@caltech.edu>
Tue, 12 Sep 2006 23:00:07 +0000 (23:00 +0000)
This will be useful for getting typical office application like save/save as
conventions working.

alg/mussa.cpp
alg/mussa.hpp
alg/test/test_mussa.cpp
qui/mussagl.cpp

index 6990db7bac926b554651cc151f4959c12c5e9a0e..194501dad670fbb497756da0f507ffac40f4d79e 100644 (file)
@@ -44,12 +44,18 @@ Mussa::Mussa(const Mussa& m)
     thres_append(m.thres_append),
     motif_sequences(m.motif_sequences),
     color_mapper(m.color_mapper),
+    analysis_path(m.analysis_path),
     dirty(m.dirty)
 {
   connect(&the_paths, SIGNAL(progress(const std::string&, int, int)), 
           this, SIGNAL(progress(const std::string&, int, int)));
 }
 
+boost::filesystem::path Mussa::get_analysis_path() const
+{
+  return analysis_path;
+}
+
 // set all parameters to null state
 void
 Mussa::clear()
@@ -63,10 +69,23 @@ Mussa::clear()
   thres_append = false;
   motif_sequences.clear();
   if(color_mapper) color_mapper->clear();
+  the_seqs.clear();
   the_paths.clear();
+  analysis_path = fs::path();
   dirty = false;
 }
 
+bool Mussa::is_dirty() const
+{
+  return dirty;
+}
+
+bool Mussa::empty() const
+{
+  return the_seqs.empty();
+}
+
+
 // these 5 simple methods manually set the parameters for doing an analysis
 // used so that the gui can take input from user and setup the analysis
 // note - still need a set_append(bool, bool) method...
@@ -556,6 +575,7 @@ Mussa::save(fs::path save_path)
     }
   }
   dirty = false;
+  analysis_path = save_path;
 }
 
 void
@@ -577,6 +597,7 @@ Mussa::load(fs::path ana_file)
   vector<FLPs> empty_FLP_vector;
   FLPs dummy_comp;
 
+  analysis_path = ana_file;
   //clog << "ana_file name " << ana_file.string() << endl;
   analysis_name = ana_path.leaf();
   //clog << " ana_name " << analysis_name << endl;
index 7aa9c465d9b53cebfeb48e064ee49e8836fc3311..28c75ca28614ea6db87e4e70d8db8b154299c680 100644 (file)
@@ -52,6 +52,8 @@ public:
     void save_muway(boost::filesystem::path save_path);
     //! load a saved analysis directory
     void load(boost::filesystem::path ana_path);
+    // ! return path to the where the analysis is stored
+    boost::filesystem::path get_analysis_path() const;
 
     //! clear parameters and initialize data lists
     void clear();
@@ -92,7 +94,9 @@ public:
     //! return a string name for an analysis mode
     std::string get_analysis_mode_name() const;
     //! return if we have unsaved changes
-    bool is_dirty() const { return dirty; }
+    bool is_dirty() const;
+    //! is there anything loaded into this analysis?
+    bool empty() const;
 
     //! return the refined paths found by the nway analysis.
     const NwayPaths& paths() const;
@@ -207,6 +211,8 @@ public:
     std::set<Sequence> motif_sequences;
     //! color manager
     boost::shared_ptr<AnnotationColors> color_mapper;
+    //! path to our analysis
+    boost::filesystem::path analysis_path;
     //! flag indicating if we have unsaved changes
     bool dirty;
 
index d8b2ab51fdbf00b3d43db1f6387c25c5ee09c2a6..4b88c242e5ff4b5dfb8a6342cfeea1e3009c79fb 100644 (file)
@@ -1,4 +1,5 @@
 #include <boost/test/auto_unit_test.hpp>
+#include <boost/filesystem/path.hpp>
 #include <boost/filesystem/operations.hpp>
 namespace fs = boost::filesystem;
 #include <boost/assign/list_of.hpp>
@@ -19,6 +20,7 @@ using namespace std;
 BOOST_AUTO_TEST_CASE( mussa_simple )
 {
   Mussa m;
+  BOOST_CHECK_EQUAL(m.empty(), true);
   BOOST_CHECK_EQUAL(m.get_name(), "" );
   BOOST_CHECK_EQUAL(m.get_window(), 0);
   BOOST_CHECK_EQUAL(m.get_threshold(), 0);
@@ -38,6 +40,8 @@ BOOST_AUTO_TEST_CASE( mussa_simple )
   BOOST_CHECK_EQUAL(m.get_soft_threshold(), 25);
   m.set_analysis_mode(Mussa::RadialNway);
   BOOST_CHECK_EQUAL(m.get_analysis_mode(), Mussa::RadialNway);
+  // make sure our path is empty
+  BOOST_CHECK_EQUAL(m.get_analysis_path().string(), fs::path().string() );
     
   m.clear();
   BOOST_CHECK_EQUAL(m.get_name(), "" );
@@ -66,10 +70,12 @@ BOOST_AUTO_TEST_CASE( mussa_sequences )
   std::string s2("TTTTNNNN");
 
   Mussa analysis;
+  BOOST_CHECK_EQUAL(analysis.empty(), true);
   analysis.append_sequence(s0);
   analysis.append_sequence(s1);
   analysis.append_sequence(s2);
 
+  BOOST_CHECK_EQUAL( analysis.empty(), false);
   BOOST_CHECK_EQUAL( analysis.sequences().size(), 3 );
   BOOST_CHECK_EQUAL( *(analysis.sequences()[0]), s0);
   BOOST_CHECK_EQUAL( *(analysis.sequences()[1]), s1);
@@ -99,13 +105,23 @@ BOOST_AUTO_TEST_CASE( mussa_load_mupa )
   m1.load_mupa_file( mupa_path );
   m1.analyze();
   m1.save( result_path );
+  BOOST_CHECK_EQUAL( m1.empty(), false);
   BOOST_CHECK_EQUAL( m1.get_name(), std::string("mck3test") );
   BOOST_CHECK( m1.size() > 0 );
+  BOOST_CHECK_EQUAL( m1.get_analysis_path().string(), result_path.string());
 
   Mussa m2;
   m2.load( result_path );
+  BOOST_CHECK_EQUAL( m2.empty(), false);
   BOOST_CHECK_EQUAL( m2.get_name(), result_path.leaf() );
   BOOST_CHECK_EQUAL( m1.size(), m2.size() );
+  BOOST_CHECK_EQUAL( result_path.string(), m2.get_analysis_path().string() );
+
+  // check clear a bit
+  m2.clear();
+  BOOST_CHECK_EQUAL( m2.empty(), true);
+  BOOST_CHECK_EQUAL( m2.is_dirty(), false );
+  BOOST_CHECK_EQUAL( m2.get_analysis_path().string(), fs::path().string());
 }
 
 BOOST_AUTO_TEST_CASE( mussa_load_full_path )
@@ -118,9 +134,12 @@ BOOST_AUTO_TEST_CASE( mussa_load_full_path )
   BOOST_CHECK( m1.size() > 0);
   BOOST_CHECK_EQUAL( m1.get_window(), 30 );
   BOOST_CHECK_EQUAL( m1.get_threshold(), 20);
+  BOOST_CHECK_EQUAL( m1.is_dirty(), true);
+  BOOST_CHECK_EQUAL( m1.get_analysis_path().string(), "");
 }
 
-BOOST_AUTO_TEST_CASE( mussa_mupa_directory )
+// make sure we know that mupa files cannot be directories 
+BOOST_AUTO_TEST_CASE( mussa_mupa_is_file_not_directory )
 {
   fs::path curdir(".");
   Mussa m1;
@@ -135,11 +154,13 @@ BOOST_AUTO_TEST_CASE( mussa_load_analysis )
   m1.analyze();
 
   Mussa m2;
-  m2.load( fs::initial_path() / "mck3test_w30_t20");
+  fs::path analysis_path = fs::initial_path() / "mck3test_w30_t20";
+  m2.load( analysis_path );
 
   BOOST_CHECK_EQUAL( m1.size(), m2.size() );
   BOOST_CHECK_EQUAL( m1.get_window(), m2.get_window() );
   BOOST_CHECK_EQUAL( m1.get_threshold(), m2.get_threshold() );
+  BOOST_CHECK_EQUAL( m2.get_analysis_path().string(), analysis_path.string());
 }
 
 BOOST_AUTO_TEST_CASE( mussa_load_motif )
index 4a4363808120801a6b878d8d1f32846f56c5c71c..60f14f904720fcbe9ff38a18ceaf046c6e5b0ff1 100644 (file)
@@ -47,7 +47,6 @@ int main(int argc, char **argv)
   Q_INIT_RESOURCE(icons);
 
   initialize_mussa(opts, argc, argv);
-
   if (opts.analysis == 0) {
     return 1;
   }