test motif editor
[mussa.git] / alg / mussa.cpp
index 6978ef24356f0775ead016f6deabb8aabe9bbca1..4b96d1b4d115a6f12915d1b3fd5a1d082d43212e 100644 (file)
@@ -32,8 +32,8 @@ Mussa::Mussa()
   : color_mapper(new AnnotationColors)
 {
   clear();
-  connect(&the_paths, SIGNAL(progress(const std::string&, int, int)), 
-          this, SIGNAL(progress(const std::string&, int, int)));
+  connect(&the_paths, SIGNAL(progress(const QString&, int, int)), 
+          this, SIGNAL(progress(const QString&, int, int)));
 }
 
 Mussa::Mussa(const Mussa& m)
@@ -49,8 +49,14 @@ Mussa::Mussa(const Mussa& m)
     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)));
+  connect(&the_paths, SIGNAL(progress(const QString&, int, int)), 
+          this, SIGNAL(progress(const QString&, int, int)));
+}
+
+MussaRef Mussa::init() 
+{
+  boost::shared_ptr<Mussa> m(new Mussa());
+  return m;
 }
 
 boost::filesystem::path Mussa::get_analysis_path() const
@@ -79,7 +85,15 @@ Mussa::clear()
   the_seqs.clear();
   the_paths.clear();
   analysis_path = fs::path();
-  dirty = false;
+  set_dirty(false);
+}
+
+void Mussa::set_dirty(bool new_state)
+{
+  if (dirty != new_state) {
+    dirty = new_state;
+    emit isModified(dirty);
+  }
 }
 
 bool Mussa::is_dirty() const
@@ -100,7 +114,7 @@ void
 Mussa::set_name(string a_name)
 {
   analysis_name = a_name;
-  dirty = true;
+  set_dirty(true);
 }
 
 string Mussa::get_name() const
@@ -133,7 +147,7 @@ void
 Mussa::set_window(int a_window)
 {
   window = a_window;
-  dirty = true;
+  set_dirty(true);
 }
 
 int Mussa::get_window() const
@@ -145,7 +159,7 @@ void
 Mussa::set_threshold(int a_threshold)
 {
   threshold = a_threshold;
-  dirty = true;
+  set_dirty(true);
   if (a_threshold > soft_thres) {
     soft_thres = a_threshold;
   }
@@ -177,7 +191,7 @@ void
 Mussa::set_analysis_mode(enum analysis_modes new_ana_mode)
 {
   ana_mode = new_ana_mode;
-  dirty = true;
+  set_dirty(true);
 }
 
 enum Mussa::analysis_modes Mussa::get_analysis_mode() const
@@ -304,17 +318,17 @@ 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;
+  set_dirty(true);
 }
 
 void Mussa::append_sequence(boost::shared_ptr<Sequence> a_seq)
 {
   the_seqs.push_back(a_seq);
-  dirty = true;
+  set_dirty(true);
 }
 
 
-const vector<boost::shared_ptr<Sequence> >& 
+const vector<SequenceRef>& 
 Mussa::sequences() const
 {
   return the_seqs;
@@ -333,7 +347,7 @@ void Mussa::load_sequence(fs::path seq_file, fs::path annot_file,
     aseq->set_species(*name);
   }
   the_seqs.push_back(aseq);
-  dirty = true;
+  set_dirty(true);
 }
 
 void
@@ -449,7 +463,7 @@ Mussa::load_mupa_file(fs::path para_file_path)
     //     << " threshold = " << threshold << endl;
   }
   // no file was loaded, signal error
-  dirty = true;
+  set_dirty(true);
 }
 
 
@@ -602,7 +616,7 @@ Mussa::save(fs::path save_path)
     }
   }
 
-  dirty = false;
+  set_dirty(false);
   analysis_path = save_path;
 }
 
@@ -627,8 +641,8 @@ Mussa::load(fs::path ana_file)
 
   analysis_path = ana_file;
   analysis_name = ana_path.leaf();
-  file_path_base =  ana_path.branch_path() / analysis_name;
-  a_file_path = file_path_base / (analysis_name + ".muway");
+  fs::path muway(analysis_name+".muway", fs::native);
+  a_file_path = analysis_path / muway;
   the_paths.load(a_file_path);
   // perhaps this could be more elegent, but at least this'll let
   // us know what our threshold and window sizes were when we load a muway
@@ -638,7 +652,8 @@ Mussa::load(fs::path ana_file)
 
   int seq_num = the_paths.sequence_count();
 
-  a_file_path = file_path_base / (analysis_name + ".museq");
+  fs::path museq(analysis_name + ".museq", fs::native);
+  a_file_path = analysis_path / museq;
 
   // this is a bit of a hack due to C++ not acting like it should with files
   for (i = 1; i <= seq_num; i++)
@@ -648,7 +663,8 @@ Mussa::load(fs::path ana_file)
     the_seqs.push_back(tmp_seq);
   }
   
-  fs::path motif_file = file_path_base / (analysis_name + ".mtl");
+  fs::path mtl(analysis_name + ".mtl", fs::native);
+  fs::path motif_file = analysis_path / mtl;
   if (fs::exists(motif_file)) {
     load_motifs(motif_file);
   }
@@ -667,15 +683,13 @@ Mussa::load(fs::path ana_file)
       append_info.str("");
       append_info << analysis_name <<  "_sp_" << i << "v" << i2 << ".flp";
       //clog << append_info.str() << endl;
-      a_file_path = file_path_base / append_info.str();
-      //clog << "path " << a_file_path.string() << endl;
+      fs::path flp(append_info.str(), fs::native);
+      a_file_path = analysis_path / flp;
       all_comps[i][i2].load(a_file_path);
-      //clog << "real size = " << all_comps[i][i2].size() << endl;
     }
   }
 }
 
-
 void
 Mussa::save_old()
 {
@@ -752,7 +766,7 @@ void Mussa::add_motif(const Sequence& motif, const Color& color)
 {
   motif_sequences.insert(motif);
   color_mapper->appendInstanceColor("motif", motif.get_sequence(), color);
-  dirty = true;
+  set_dirty(true);
 }
 
 void Mussa::set_motifs(const vector<Sequence>& motifs, 
@@ -780,7 +794,7 @@ void Mussa::load_motifs(fs::path filename)
 void Mussa::load_motifs(std::istream &in)
 {
   std::string data;
-  const char *alphabet = Alphabet::nucleic_cstr;
+  const char *alphabet = Alphabet::dna_cstr;
   motif_parser::ParsedMotifs parsed_motifs(motif_sequences, color_mapper);
 
   // slurp our data into a string