From: Diane Trout Date: Wed, 9 Aug 2006 00:15:44 +0000 (+0000) Subject: add dirty flag X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=mussa.git;a=commitdiff_plain;h=389fb87da59d3437ec08df8453225b91c2ccd1ae add dirty flag Before we can have Mussa track if it needs to be saved we need some flag to indicate when we have unsaved changes. --- diff --git a/alg/mussa.cpp b/alg/mussa.cpp index 95a0a7d..dc86cba 100644 --- a/alg/mussa.cpp +++ b/alg/mussa.cpp @@ -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 seq_copy(new Sequence(a_seq)); the_seqs.push_back(seq_copy); + dirty = true; } void Mussa::append_sequence(boost::shared_ptr 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 diff --git a/alg/mussa.hpp b/alg/mussa.hpp index 5713a6d..d673b7b 100644 --- a/alg/mussa.hpp +++ b/alg/mussa.hpp @@ -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 motif_sequences; //! color manager boost::shared_ptr color_mapper; + //! flag indicating if we have unsaved changes + bool dirty; // Private methods //! runs all the seqcomps needed to support the nway comparison diff --git a/alg/test/test_mussa.cpp b/alg/test/test_mussa.cpp index 8961a1c..4a0a476 100644 --- a/alg/test/test_mussa.cpp +++ b/alg/test/test_mussa.cpp @@ -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); +} +