add dirty flag
authorDiane Trout <diane@caltech.edu>
Wed, 9 Aug 2006 00:15:44 +0000 (00:15 +0000)
committerDiane Trout <diane@caltech.edu>
Wed, 9 Aug 2006 00:15:44 +0000 (00:15 +0000)
Before we can have Mussa track if it needs to be saved we need some
flag to indicate when we have unsaved changes.

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

index 95a0a7daca91ec0564ddbbf55110c439b62749c2..dc86cba1b8bc97230d1e7e4faa01c5cc543e9046 100644 (file)
@@ -43,7 +43,8 @@ Mussa::Mussa(const Mussa& m)
     win_append(m.win_append),
     thres_append(m.thres_append),
     motif_sequences(m.motif_sequences),
-    color_mapper(m.color_mapper)
+    color_mapper(m.color_mapper),
+    dirty(m.dirty)
 {
   connect(&the_paths, SIGNAL(progress(const std::string&, int, int)), 
           this, SIGNAL(progress(const std::string&, int, int)));
@@ -63,6 +64,7 @@ Mussa::clear()
   motif_sequences.clear();
   if(color_mapper) color_mapper->clear();
   the_paths.clear();
+  dirty = false;
 }
 
 // these 5 simple methods manually set the parameters for doing an analysis
@@ -72,6 +74,7 @@ void
 Mussa::set_name(string a_name)
 {
   analysis_name = a_name;
+  dirty = true;
 }
 
 string Mussa::get_name()
@@ -92,6 +95,7 @@ void
 Mussa::set_window(int a_window)
 {
   window = a_window;
+  dirty = true;
 }
 
 int Mussa::get_window() const
@@ -103,8 +107,10 @@ void
 Mussa::set_threshold(int a_threshold)
 {
   threshold = a_threshold;
-  if (a_threshold > soft_thres) 
+  dirty = true;
+  if (a_threshold > soft_thres) {
     soft_thres = a_threshold;
+  }
 }
 
 int Mussa::get_threshold() const
@@ -133,6 +139,7 @@ void
 Mussa::set_analysis_mode(enum analysis_modes new_ana_mode)
 {
   ana_mode = new_ana_mode;
+  dirty = true;
 }
 
 enum Mussa::analysis_modes Mussa::get_analysis_mode() const
@@ -259,11 +266,13 @@ void Mussa::append_sequence(const Sequence& a_seq)
 {
   boost::shared_ptr<Sequence> seq_copy(new Sequence(a_seq));
   the_seqs.push_back(seq_copy);
+  dirty = true;
 }
 
 void Mussa::append_sequence(boost::shared_ptr<Sequence> a_seq)
 {
   the_seqs.push_back(a_seq);
+  dirty = true;
 }
 
 
@@ -286,6 +295,7 @@ void Mussa::load_sequence(fs::path seq_file, fs::path annot_file,
     aseq->set_species(*name);
   }
   the_seqs.push_back(aseq);
+  dirty = true;
 }
 
 void
@@ -399,6 +409,7 @@ Mussa::load_mupa_file(fs::path para_file_path)
   {
     throw mussa_load_error("Config File: " + para_file_path.string() + " not found");
   }
+  dirty = true;
 }
 
 
@@ -573,6 +584,7 @@ Mussa::save()
   } else {
     throw mussa_error("Can't save analysis without an analysis name");
   }
+  dirty = false;
 }
 
 void
index 5713a6dd9f0523bc8a71968c6ba09c0596f6f14f..d673b7b8a681c09f4ce94e71533aa0919a9ed271 100644 (file)
@@ -90,6 +90,8 @@ public:
     enum analysis_modes get_analysis_mode() const;
     //! 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; }
 
     //! return the refined paths found by the nway analysis.
     const NwayPaths& paths() const;
@@ -203,6 +205,8 @@ public:
     std::set<Sequence> motif_sequences;
     //! color manager
     boost::shared_ptr<AnnotationColors> color_mapper;
+    //! flag indicating if we have unsaved changes
+    bool dirty;
 
     // Private methods
     //! runs all the seqcomps needed to support the nway comparison
index 8961a1c3f17578b0a66a76de9137acb15833e9c5..4a0a4765f45069e8fc7c6d40e0476499c20ec65e 100644 (file)
@@ -305,3 +305,23 @@ BOOST_AUTO_TEST_CASE( subanalysis )
   BOOST_CHECK( perfect_match_count < one_mismatch_count );
 }
 
+BOOST_AUTO_TEST_CASE( dirty_flag )
+{
+  Mussa m;
+  BOOST_CHECK_EQUAL(m.is_dirty(), false);
+  m.set_name("foo");
+  BOOST_CHECK_EQUAL(m.is_dirty(), true);
+  m.clear();
+  m.set_window(30);
+  BOOST_CHECK_EQUAL(m.is_dirty(), true);
+  m.clear(); 
+  m.set_threshold(1);
+  BOOST_CHECK_EQUAL(m.is_dirty(), true);
+  m.clear();
+  m.set_soft_threshold(1);
+  BOOST_CHECK_EQUAL(m.is_dirty(), false);
+  m.clear();
+  m.append_sequence("AAGGCCTT");
+  BOOST_CHECK_EQUAL(m.is_dirty(), true);
+}
+