add python interface to seqcomp
authorDiane Trout <diane@caltech.edu>
Wed, 29 Nov 2006 02:14:45 +0000 (02:14 +0000)
committerDiane Trout <diane@caltech.edu>
Wed, 29 Nov 2006 02:14:45 +0000 (02:14 +0000)
which is actually provided by the class FLP

alg/flp.hpp
py/CMakeLists.txt
py/flp.cpp [new file with mode: 0644]
py/module.cpp
py/test/TestFlp.py [new file with mode: 0644]

index 9b561874fbb1572c895fd15cc6542fc0dd52d963..2aed0ba4845dc5ba576b01b5746bde288bd67e11 100644 (file)
@@ -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<match> matches(int index) const;
     //! Return all the match indexes for a particular window?
     std::list<int> match_locations(int index) const;
index f8502ad3a52bcfc94a2b64d2fbd81bba90fb2181..c16083f33b645aec7b2c2f185d7f84ee6751058c 100644 (file)
@@ -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 (file)
index 0000000..9d6d729
--- /dev/null
@@ -0,0 +1,40 @@
+#include <boost/python.hpp>
+#include <boost/python/list.hpp>
+#include <boost/python/return_internal_reference.hpp>
+#include <boost/python/return_by_value.hpp>
+#include <boost/python/return_value_policy.hpp>
+#include <boost/python/register_ptr_to_python.hpp>
+using namespace boost::python;
+
+#include "alg/flp.hpp"
+#include "alg/sequence.hpp"
+
+struct listint_to_python {
+  static PyObject *convert(const std::list<int> l) {
+    PyObject *pylist = PyList_New(0);
+    for(std::list<int>::const_iterator li = l.begin();
+        li != l.end();
+        ++li)
+    {      
+      PyList_Append(pylist, PyInt_FromLong(*li));
+    }
+    return pylist;
+  }
+};
+
+void export_flps()
+{
+  
+  class_<FLPs>("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<match> matches(int index) const;    
+    //void save(boost::filesystem::path save_file_path);
+    //void load(boost::filesystem::path file_path);
+  to_python_converter< std::list<int>, listint_to_python>();
+}
\ No newline at end of file
index d325fdc538724564df253e51dd3928db630a02aa..1c6082551f6c5788371317f1f3b9fb48d7145b0f 100644 (file)
@@ -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 (file)
index 0000000..3974eb5
--- /dev/null
@@ -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