From de84c0a72c8d284e3d124d38699ac065ffe37e3c Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Thu, 10 Apr 2008 21:08:04 -0700 Subject: [PATCH] Extend the python mussa interface. 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 | 3 ++- alg/CMakeLists.txt | 2 +- alg/mussa.cpp | 12 +++++------- alg/mussa.hpp | 14 ++++++++++++-- alg/seq.hpp | 4 +++- py/mussa.cpp | 16 +++++++++++----- py/sequence.cpp | 2 ++ py/sequencebrowserwidget.cpp | 2 +- py/test/CMakeLists.txt | 2 +- py/test/TestSequence.py | 3 +++ 10 files changed, 41 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40c5572..1a9bbb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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} diff --git a/alg/CMakeLists.txt b/alg/CMakeLists.txt index ddcc92f..1e5ba63 100644 --- a/alg/CMakeLists.txt +++ b/alg/CMakeLists.txt @@ -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 ) diff --git a/alg/mussa.cpp b/alg/mussa.cpp index b538ecc..0b93e99 100644 --- a/alg/mussa.cpp +++ b/alg/mussa.cpp @@ -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) { diff --git a/alg/mussa.hpp b/alg/mussa.hpp index fb05ec7..1e51995 100644 --- a/alg/mussa.hpp +++ b/alg/mussa.hpp @@ -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(); diff --git a/alg/seq.hpp b/alg/seq.hpp index 467fcaf..08abcbb 100644 --- a/alg/seq.hpp +++ b/alg/seq.hpp @@ -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 void serialize(Archive& ar, const unsigned int /*version*/) { diff --git a/py/mussa.cpp b/py/mussa.cpp index 5f42599..cd46d49 100644 --- a/py/mussa.cpp +++ b/py/mussa.cpp @@ -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) = &Mussa::append_sequence; @@ -26,8 +28,8 @@ void export_mussa() ; py::class_("_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 >(); py::enum_("analysis_modes") diff --git a/py/sequence.cpp b/py/sequence.cpp index 4d650c8..a4ef379 100644 --- a/py/sequence.cpp +++ b/py/sequence.cpp @@ -26,6 +26,8 @@ void export_sequence() class_("Sequence") .def(init()) + .def("__getitem__", &Sequence::at, "return base pair at specified location", + return_value_policy()) .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") diff --git a/py/sequencebrowserwidget.cpp b/py/sequencebrowserwidget.cpp index c644ea1..6056089 100644 --- a/py/sequencebrowserwidget.cpp +++ b/py/sequencebrowserwidget.cpp @@ -2,7 +2,7 @@ namespace py = boost::python; #include -#include "alg/sequence.hpp" +#include "alg/Sequence.hpp" #include "alg/glsequence.cpp" #include "alg/glseqbrowser.cpp" #include "qui/seqbrowser/SequenceBrowserWidget.hpp" diff --git a/py/test/CMakeLists.txt b/py/test/CMakeLists.txt index 62fc91d..2cf1951 100644 --- a/py/test/CMakeLists.txt +++ b/py/test/CMakeLists.txt @@ -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 ) diff --git a/py/test/TestSequence.py b/py/test/TestSequence.py index 80fc3e6..e9d816e 100644 --- a/py/test/TestSequence.py +++ b/py/test/TestSequence.py @@ -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" -- 2.30.2