Extend the python mussa interface.
authorDiane Trout <diane@caltech.edu>
Fri, 11 Apr 2008 04:08:04 +0000 (21:08 -0700)
committerDiane Trout <diane@caltech.edu>
Fri, 11 Apr 2008 04:08:04 +0000 (21:08 -0700)
I needed to provide mussa load functions that take strings instead
of boost::filesystem::paths to make it easier to load analyses
from the python interpreter.

I also added code to allow directly accessing base pairs in a seq.

Lastly I disabled linking against the python interpreter for the
main mussa gui, again to simplify the problem of os x 10.4/10.5 support

CMakeLists.txt
alg/CMakeLists.txt
alg/mussa.cpp
alg/mussa.hpp
alg/seq.hpp
py/mussa.cpp
py/sequence.cpp
py/sequencebrowserwidget.cpp
py/test/CMakeLists.txt
py/test/TestSequence.py

index 40c557263285030f77fcd153ba5f6c758f547c92..1a9bbb34b22d6377b5338c8c76614cf876d76fd7 100644 (file)
@@ -24,7 +24,8 @@ FIND_PACKAGE(OpenGL)
 FIND_PACKAGE(Boost 1.34.1 COMPONENTS filesystem serialization program_options python)
 FIND_PACKAGE(PythonLibs)
 
-SET(USE_PYTHON 1)
+SET(USE_PYTHON 0 CACHE BOOL
+    "Build mussa executable linked to python interpreter")
 
 INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH} 
                     ${QT_INCLUDES}
index ddcc92f51b1a4b1a9502bf1e0d1d7555ac441d67..1e5ba63bd5286e68c34010fe21540453845a4ae6 100644 (file)
@@ -1,5 +1,5 @@
 FIND_PACKAGE(OpenGL )
-FIND_PACKAGE(Boost 1.34.1 COMPONENTS filesystem unit_test_framework serialization program_options python2.3 )
+FIND_PACKAGE(Boost 1.34.1 COMPONENTS filesystem unit_test_framework serialization program_options python )
 FIND_PACKAGE(Qt4)
 INCLUDE( ${QT_USE_FILE} )
 INCLUDE( Platform )
index b538eccf0946bc8f992c62ea8cb81f8b6269c550..0b93e99d24da3ec3e543e3e0e5cde8ad35678cef 100644 (file)
@@ -198,11 +198,13 @@ void
 Mussa::set_soft_threshold(int new_threshold)
 {
   if (new_threshold < threshold) {
-    soft_thres = threshold;
+    new_threshold = threshold;
   } else if (new_threshold > window) {
-    soft_thres = window; 
-  } else {
+    new_threshold = window; 
+  }
+  if (soft_thres != new_threshold) {
     soft_thres = new_threshold;
+    nway();
   }
 }
 
@@ -375,10 +377,6 @@ void Mussa::load_sequence(fs::path seq_file, fs::path annot_file,
   set_dirty(true);
 }
 
-void Mussa::load_mupa_file(std::string para_file_path) {
-  load_mupa_file(boost::filesystem::path(para_file_path));
-}
-
 void
 Mussa::load_mupa_file(fs::path para_file_path)
 {
index fb05ec704af23cabf1911bf20bac84758c5f6757..1e519955f32b8a8c6da67c7fcf444cae98e92395 100644 (file)
@@ -59,10 +59,18 @@ public:
     
     //! save all of mussa
     void save(boost::filesystem::path save_path="");
+    //! save all of mussa
+    void save(const std::string& save_path) {
+      save(boost::filesystem::path(save_path));
+    }
     //! save the nway comparison
     void save_muway(boost::filesystem::path save_path);
     //! load a saved analysis directory
     void load(boost::filesystem::path ana_path);
+    //! load a saved analysis 
+    void load(const std::string& ana_path) { 
+       load(boost::filesystem::path(ana_path)); 
+    }
     // ! return path to the where the analysis is stored
     boost::filesystem::path get_analysis_path() const;
     //! set analysis path
@@ -72,7 +80,9 @@ public:
     void clear();
 
     //! set parameters from a file - 'mupa' ~ mussa parameters
-    void load_mupa_file(std::string para_file_path);
+    void Mussa::load_mupa_file(const std::string& para_file_path) {
+      load_mupa_file(boost::filesystem::path(para_file_path));
+    }
     void load_mupa_file(boost::filesystem::path para_file_path);
     //! load mussa parameters from a stream, specifing output location
     void load_mupa_stream(
@@ -150,7 +160,7 @@ public:
      */
     void analyze();
     /*! Run the nway filtering algorithm, 
-     *  this might be used when changing the soft threshhold?
+     *  automatically called when the soft threshhold has changed?
      */
     void nway();
 
index 467fcaf9eb7ceafdb50bfd7b34ea118c4c824cf0..08abcbbe1dbf1af3441cf77b023c60cbb6ee0f29 100644 (file)
@@ -52,9 +52,11 @@ public:
   
   std::string create_reverse_complement_map() const;
   
-  const std::string rc_map;
 private:
   AlphabetRef alphabet;
+public:
+  const std::string rc_map;
+private:  
   friend class boost::serialization::access;
   template<class Archive>
   void serialize(Archive& ar, const unsigned int /*version*/) {
index 5f42599fb78111ea323fda0813c1dc3f43598c0f..cd46d4941ff1e9de5f168e82ac595e7b7d48c268 100644 (file)
@@ -7,7 +7,9 @@ namespace py = boost::python;
 
 void export_mussa()
 {
-  void (Mussa::*load_mupa_string)(std::string) = &Mussa::load_mupa_file;
+  void (Mussa::*save_string)(const std::string &) = &Mussa::save;
+  void (Mussa::*load_mupa_string)(const std::string &) = &Mussa::load_mupa_file;
+  void (Mussa::*load_string)(const std::string &) = &Mussa::load;
   void (Mussa::*append_sequence_ref)(const Sequence&) = &Mussa::append_sequence;
   void (Mussa::*append_sequence_ptr)(const boost::shared_ptr<Sequence>) = &Mussa::append_sequence;
 
@@ -26,8 +28,8 @@ void export_mussa()
   ;
  
   py::class_<Mussa>("_Mussa", py::no_init)
-    .def("save", &Mussa::save)
-    .def("load", &Mussa::load, "Load previous run analysis")
+    .def("save", save_string, "Save analysis in the specified directory")
+    .def("load", load_string, "Load previous run analysis")
     .def("load_mupa", load_mupa_string, "Load mussa parameter file")
     .def("clear", &Mussa::clear, "Clear the current analysis")
     .add_property("name", &Mussa::get_name, &Mussa::set_name, "Set the name of the analysis")
@@ -37,7 +39,8 @@ void export_mussa()
                   "the number of base pairs in the sliding window")
     .add_property("threshold", &Mussa::get_threshold, &Mussa::set_threshold,
                   "how many base pairs must match between two windows")
-    .def("softThreshold", &Mussa::set_soft_threshold)
+    .add_property("softThreshold", &Mussa::get_soft_threshold,
+                  &Mussa::set_soft_threshold)
     .add_property("analysisMode", &Mussa::get_analysis_mode, 
                                    &Mussa::set_analysis_mode)
     .add_property("analysisModeName", &Mussa::get_analysis_mode_name)
@@ -46,7 +49,10 @@ void export_mussa()
     .def("sequences", &Mussa::sequences, py::return_internal_reference<>(), "return list of sequences")
     .def("add_sequence", append_sequence_ref, "attach a sequence to the analysis")  
   ;
-  py::def("Mussa", &Mussa::init, "Construct a new Mussa object");
+  py::def("Mussa", &Mussa::init, 
+          "Construct a new Mussa object.\n"
+          "You can use this to load a previous analysis or to construct\n"
+          "a new analysis.\n");
   py::register_ptr_to_python< boost::shared_ptr<Mussa> >();
   
   py::enum_<Mussa::analysis_modes>("analysis_modes")
index 4d650c84890f77c79184d74522823c80207c21b5..a4ef37981360b0b00c31b08ad82b5dbf04b08cb8 100644 (file)
@@ -26,6 +26,8 @@ void export_sequence()
   
   class_<Sequence>("Sequence")
     .def(init<std::string>())
+    .def("__getitem__", &Sequence::at, "return base pair at specified location",
+         return_value_policy<return_by_value>())
     .def("__len__", &Sequence::size, "return the length of the sequence")
     .def("__repr__", &Sequence::get_sequence, "display as string")
     .def("__str__", &Sequence::get_sequence, "cast to string")
index c644ea122b5274e2b6ab65d39fe835dbf626d562..60560896e42c8094dc66db00c1adb3bf5fd5d06c 100644 (file)
@@ -2,7 +2,7 @@
 namespace py = boost::python;
 #include <vector>
 
-#include "alg/sequence.hpp"
+#include "alg/Sequence.hpp"
 #include "alg/glsequence.cpp"
 #include "alg/glseqbrowser.cpp"
 #include "qui/seqbrowser/SequenceBrowserWidget.hpp"
index 62fc91df210f0b80fd90cba43e6354e28e809ca2..2cf195124ee643183e236e8b11b931a008492292 100644 (file)
@@ -1,6 +1,6 @@
 FIND_PACKAGE(PythonLibs)
 
-FIND_PACKAGE(Boost 1.34.1 COMPONENTS program_options filesystem serialization python2.3 unit_test_framework )
+FIND_PACKAGE(Boost 1.34.1 COMPONENTS program_options filesystem serialization python unit_test_framework )
 INCLUDE(Platform)
 
 SET(SOURCES test_python.cpp )
index 80fc3e68e84f5489169b011207d489c0023049a5..e9d816e2665f7e844d9e84a1e57d16035530107a 100644 (file)
@@ -16,6 +16,9 @@ class TestSequence(unittest.TestCase):
     self.failUnless(str(s) == seq_text)
     self.failUnless(str(s) == seq_text)
 
+    for i in range(len(seq_text)):
+      self.failUnlessEqual(s[i], seq_text[i])
+
   def testNames(self):
     seq_text = "AAGGCCTT"
     header_text = "hello"