From a0cc0d20f7739de0ba33f7293fb682d58e394eb9 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Wed, 29 Nov 2006 02:14:45 +0000 Subject: [PATCH] add python interface to seqcomp which is actually provided by the class FLP --- alg/flp.hpp | 2 +- py/CMakeLists.txt | 7 ++++--- py/flp.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ py/module.cpp | 2 ++ py/test/TestFlp.py | 24 ++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 py/flp.cpp create mode 100644 py/test/TestFlp.py diff --git a/alg/flp.hpp b/alg/flp.hpp index 9b56187..2aed0ba 100644 --- a/alg/flp.hpp +++ b/alg/flp.hpp @@ -52,7 +52,7 @@ public: void seqcomp(const Sequence& seq1, const Sequence& seq2, bool is_RC); //bool FLPs::match_less(match *match1, match *match2); //void FLPs::sort(); - //! Return all the matches for a particular window? + //! Return all the matches for a particular window? (index and score pairs) std::list matches(int index) const; //! Return all the match indexes for a particular window? std::list match_locations(int index) const; diff --git a/py/CMakeLists.txt b/py/CMakeLists.txt index f8502ad..c16083f 100644 --- a/py/CMakeLists.txt +++ b/py/CMakeLists.txt @@ -13,6 +13,7 @@ IF(BOOST_PYTHON_LIBRARY) annot.cpp annotation_colors.cpp conserved_path.cpp + flp.cpp glsequence.cpp module.cpp mussa.cpp @@ -60,9 +61,9 @@ IF(BOOST_PYTHON_LIBRARY) ) IF(PYTHON_EXECUTABLE) - SET(PYTHON_TEST_DIR ${CMAKE_SOURCE_DIR}/py/test/) - ADD_TEST(sequence_py - ${PYTHON_EXECUTABLE} ${PYTHON_TEST_DIR}/TestSequence.py) + SET(PYTEST_DIR ${CMAKE_SOURCE_DIR}/py/test/) + ADD_TEST(TestSequence ${PYTHON_EXECUTABLE} ${PYTEST_DIR}/TestSequence.py) + ADD_TEST(TestFlp ${PYTHON_EXECUTABLE} ${PYTEST_DIR}/TestFlp.py) ENDIF(PYTHON_EXECUTABLE) ELSE(BOOST_PYTHON_LIBRARY) ENDIF(BOOST_PYTHON_LIBRARY) diff --git a/py/flp.cpp b/py/flp.cpp new file mode 100644 index 0000000..9d6d729 --- /dev/null +++ b/py/flp.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include +using namespace boost::python; + +#include "alg/flp.hpp" +#include "alg/sequence.hpp" + +struct listint_to_python { + static PyObject *convert(const std::list l) { + PyObject *pylist = PyList_New(0); + for(std::list::const_iterator li = l.begin(); + li != l.end(); + ++li) + { + PyList_Append(pylist, PyInt_FromLong(*li)); + } + return pylist; + } +}; + +void export_flps() +{ + + class_("FLP") + .def("setup", &FLPs::setup, "set window size and lowest threshold") + .def("seqcomp", &FLPs::seqcomp, "compare two sequences\n" + "takes: sequence, seqeuence, bool is_reveresed flag") + .def("size", &FLPs::size, "return the length of the sequence") + .def("match_locations", &FLPs::match_locations, "return list of matches at a window location") + .def("thres_matches", &FLPs::thres_matches, "return list of matches at a window location above a threshold") + ; + //std::list matches(int index) const; + //void save(boost::filesystem::path save_file_path); + //void load(boost::filesystem::path file_path); + to_python_converter< std::list, listint_to_python>(); +} \ No newline at end of file diff --git a/py/module.cpp b/py/module.cpp index d325fdc..1c60825 100644 --- a/py/module.cpp +++ b/py/module.cpp @@ -4,6 +4,7 @@ using namespace boost::python; void export_annot(); void export_annotation_colors(); void export_conserved_path(); +void export_flps(); void export_glsequence(); void export_mussa(); void export_nway_paths(); @@ -15,6 +16,7 @@ BOOST_PYTHON_MODULE(mussa) export_annot(); export_annotation_colors(); export_conserved_path(); + export_flps(); export_glsequence(); export_mussa(); export_nway_paths(); diff --git a/py/test/TestFlp.py b/py/test/TestFlp.py new file mode 100644 index 0000000..3974eb5 --- /dev/null +++ b/py/test/TestFlp.py @@ -0,0 +1,24 @@ +import os +import sys +import unittest + +# kinda hackish but it makes it possible to runi under ctest +sys.path.append(os.getcwd()) + +import mussa + +class TestFLP(unittest.TestCase): + def testSimple(self): + s1 = mussa.Sequence("A"*10) + s2 = mussa.Sequence("A"*10) + cmp = mussa.FLP() + cmp.setup(10,8) + cmp.seqcomp(s1,s2,False) + self.failUnlessEqual(cmp.size(), 1) + self.failUnlessEqual(cmp.match_locations(0), [0]) + +def suite(): + return unittest.makeSuite(TestFLP, 'test') + +if __name__ == "__main__": + sys.exit(unittest.main(defaultTest='suite')) \ No newline at end of file -- 2.30.2