From: Diane Trout Date: Fri, 30 Jun 2006 20:37:58 +0000 (+0000) Subject: fix boost::python sequence interface X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=mussa.git;a=commitdiff_plain;h=0818838b775023e1fe9adf7417a9c39a95147033 fix boost::python sequence interface Making sequence a subclass of string caused some problems for the boost::python sequence class. This updates the interface so it works again. --- diff --git a/alg/sequence.cpp b/alg/sequence.cpp index b8488dc..ee0f9f7 100644 --- a/alg/sequence.cpp +++ b/alg/sequence.cpp @@ -443,7 +443,7 @@ void Sequence::set_species(const std::string& name) species = name; } -const std::string& Sequence::get_species() const +std::string Sequence::get_species() const { return species; } diff --git a/alg/sequence.hpp b/alg/sequence.hpp index 407168e..4781365 100644 --- a/alg/sequence.hpp +++ b/alg/sequence.hpp @@ -104,7 +104,7 @@ class Sequence : public std::string const std::list& annotations() const; const std::list& motifs() const; void set_species(const std::string &); - const std::string& get_species() const; + std::string get_species() const; //! return a subsequence, copying over any appropriate annotation Sequence subseq(int start=0, int count = std::string::npos) const; diff --git a/py/CMakeLists.txt b/py/CMakeLists.txt index a717e5d..8e0a6ff 100644 --- a/py/CMakeLists.txt +++ b/py/CMakeLists.txt @@ -23,13 +23,13 @@ INCLUDE( ${QT_USE_FILE} ) #SET_SOURCE_FILES_PROPERTIES(${SOURCES} COM - ADD_LIBRARY(_mussa MODULE ${SOURCES}) + ADD_LIBRARY(mussa MODULE ${SOURCES}) ADD_LIBRARY(mussa_py STATIC ${SOURCES}) - ADD_CUSTOM_TARGET(_mussa.so ALL - COMMAND cp lib_mussa.so _mussa.so - DEPENDS _mussa) + ADD_CUSTOM_TARGET(mussa.so ALL + COMMAND cp libmussa.so mussa.so + DEPENDS mussa) LINK_DIRECTORIES(${MUSSA_BINARY_DIR}/alg) - TARGET_LINK_LIBRARIES(_mussa + TARGET_LINK_LIBRARIES(mussa mussa_core mussa_qui ${BOOST_PYTHON_LIBRARY} @@ -41,7 +41,8 @@ INCLUDE( ${QT_USE_FILE} ) IF(PYTHON_EXECUTABLE) SET(PYTHON_TEST_DIR ${CMAKE_SOURCE_DIR}/py/test/) - ADD_TEST(sequence ${PYTHON_EXECUTABLE} ${PYTHON_TEST_DIR}/TestSequence.py) + ADD_TEST(sequence_py + ${PYTHON_EXECUTABLE} ${PYTHON_TEST_DIR}/TestSequence.py) ENDIF(PYTHON_EXECUTABLE) #ELSE(BOOST_PYTHON_LIB) #ENDIF(BOOST_PYTHON_LIB) diff --git a/py/module.cpp b/py/module.cpp index 9f3a145..448b523 100644 --- a/py/module.cpp +++ b/py/module.cpp @@ -8,7 +8,7 @@ void export_nway_paths(); void export_sequence(); void export_mussa_window(); -BOOST_PYTHON_MODULE(_mussa) +BOOST_PYTHON_MODULE(mussa) { export_conserved_path(); export_glsequence(); diff --git a/py/sequence.cpp b/py/sequence.cpp index b64565a..3bdca90 100644 --- a/py/sequence.cpp +++ b/py/sequence.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -7,15 +8,19 @@ using namespace boost::python; #include #include "alg/glsequence.hpp" +PyObject* seq_to_string(const Sequence& s) { + ::PyString_FromStringAndSize(s.data(), s.size()); +} + void export_sequence() { class_("Sequence") .def(init()) - //.def("__str__", &Sequence::get_seq, return_value_policy()) + .def("__str__", &seq_to_string) .def("size", &Sequence::size) .def("__len__", &Sequence::size) .add_property("header", &Sequence::get_header, &Sequence::set_header) - //.add_property("seq", &Sequence::get_seq, &Sequence::set_seq) + .add_property("species", &Sequence::get_species, &Sequence::set_species) .def("rcseq", &Sequence::rev_comp, return_value_policy()) ; } diff --git a/py/test/TestSequence.py b/py/test/TestSequence.py index 23cdc93..274fbdb 100644 --- a/py/test/TestSequence.py +++ b/py/test/TestSequence.py @@ -14,7 +14,20 @@ class TestSequence(unittest.TestCase): self.failUnless(len(seq_text) == len(s)) self.failUnless(len(s) == s.size()) self.failUnless(str(s) == seq_text) - + self.failUnless(str(s) == seq_text) + + def testNames(self): + seq_text = "AAGGCCTT" + header_text = "hello" + species = "Goo Gooerific" + + s = mussa.Sequence(seq_text) + + s.header = header_text + s.species = species + self.failUnless(s.header == header_text) + self.failUnless(s.species == species) + def suite(): return unittest.makeSuite(TestSequence, 'test')