python wrap mussa, nwaypaths, and conservedpaths
authorDiane Trout <diane@caltech.edu>
Sat, 4 Mar 2006 09:02:28 +0000 (09:02 +0000)
committerDiane Trout <diane@caltech.edu>
Sat, 4 Mar 2006 09:02:28 +0000 (09:02 +0000)
provide a python interface to at least some of Mussa, NwayPaths, and
ConservedPaths so I can get some idea of how much more efficient a
graph representation for paths would be than the current linear structure.
(AKA how often is a a path segment shared?)

Makefile.noqt
alg/nway_paths.cxx
alg/nway_paths.hh
py/conserved_path.cxx [new file with mode: 0644]
py/module.cxx [new file with mode: 0644]
py/module.mk [new file with mode: 0644]
py/mussa.cxx [new file with mode: 0644]
py/nway_paths.cxx [new file with mode: 0644]

index 572619fdd83c70e24f13bac05120d7d77fa67ad1..0c9e60e6eb47bab264fe3ae1e7e79ba04dc9d332 100644 (file)
@@ -5,7 +5,7 @@ OBJEXT := .o
 LIBEXT := .a
 
 CXX := g++ 
-CXXFLAGS :=  
+CXXFLAGS := -g -fPIC -I/usr/include/python2.3
 LDFLAGS := 
 
 CURDIR := $(shell pwd)
index 86dc577ab5316edf014948a9f85aaa815ad7b99c..2dd22598555f6a8608680b031040825484e6ff09 100644 (file)
@@ -444,6 +444,3 @@ void NwayPaths::print(list<vector<int> >& dump_path)
     cout << endl;
   }
 }
-
-
-
index 38214057525780cfae648dbc7cdde4ddc0deb2ec..ee1f07c8ec053bf23249d9489b11cd84a0235a86 100644 (file)
@@ -65,6 +65,10 @@ class NwayPaths
     void save_old(std::string save_file_path);
     void print(std::list<std::vector<int> >&);
 
+    std::list<ConservedPath>::iterator pbegin() { return pathz.begin() ; }
+    std::list<ConservedPath>::iterator pend() { return pathz.end() ; }
+    std::list<ExtendedConservedPath>::iterator rpbegin() { return refined_pathz.begin() ; }
+    std::list<ExtendedConservedPath>::iterator rpend() { return refined_pathz.end() ; }
     // these probably shouldn't be public, but lets start 
     // simple
     std::list<ConservedPath> pathz;
diff --git a/py/conserved_path.cxx b/py/conserved_path.cxx
new file mode 100644 (file)
index 0000000..2b23428
--- /dev/null
@@ -0,0 +1,26 @@
+#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
+#include <boost/python.hpp>
+#include <vector>
+using namespace boost::python;
+
+#include "alg/conserved_path.h"
+
+void export_conserved_path()
+{
+  class_<std::vector<int> >("intvec")
+    .def(vector_indexing_suite<std::vector<int> >())
+  ;
+
+  class_<ConservedPath>("ConservedPath")
+    .def_readwrite("score", &ConservedPath::score)
+    .def_readwrite("track_indexes", &ConservedPath::track_indexes)
+    //.add_property("track_indexes", //iterator<std::vector<int> >())
+    //    range(&ConservedPath::track_indexes.begin(),
+    //                                 &ConservedPath::track_indexes.end()))
+  ;
+
+  class_<ExtendedConservedPath, bases<ConservedPath> >("ExtendedConservedPath")
+    .def_readwrite("window_size", &ExtendedConservedPath::window_size)
+  ;
+}
diff --git a/py/module.cxx b/py/module.cxx
new file mode 100644 (file)
index 0000000..fbacede
--- /dev/null
@@ -0,0 +1,13 @@
+#include <boost/python.hpp>
+using namespace boost::python;
+
+void export_mussa();
+void export_nway_paths();
+void export_conserved_path();
+
+BOOST_PYTHON_MODULE(mussa)
+{
+  export_mussa();
+  export_nway_paths();
+  export_conserved_path();
+}
diff --git a/py/module.mk b/py/module.mk
new file mode 100644 (file)
index 0000000..ba63363
--- /dev/null
@@ -0,0 +1,19 @@
+CURDIR := $(BASEDIR)py/
+
+SOURCES.cxx := module.cxx \
+               conserved_path.cxx \
+               mussa.cxx \
+              nway_paths.cxx
+
+
+MUSSA_PY_SRC := $(addprefix $(CURDIR), $(SOURCES.cxx))
+MUSSA_PY_OBJ := $(MUSSA_PY_SRC:.cxx=$(OBJEXT))
+
+SRC += $(MUSSA_PY_SRC)
+CXXFLAGS += 
+
+MUSSAPY := $(BASEDIR)/mussa.so
+TARGETBINS += $(MUSSAPY)
+
+$(MUSSAPY): $(MUSSA_PY_OBJ) $(MUSSA_ALG_OBJ)
+       g++ -shared $(CXXFLAGS) -lpython2.3 -lboost_python -o $@ $^
diff --git a/py/mussa.cxx b/py/mussa.cxx
new file mode 100644 (file)
index 0000000..690928f
--- /dev/null
@@ -0,0 +1,39 @@
+#include <boost/python.hpp>
+
+using namespace boost::python;
+
+#include "alg/mussa_class.hh"
+
+void export_mussa()
+{
+  //BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(mussa_analyze_overloads, 
+  //                                       &Mussa::analyze, 0, 4);
+
+  class_<Mussa>("Mussa")
+    .def("save", &Mussa::save)
+    .def("load", &Mussa::load, "Load previous run analysis")
+    .def("load_mupa", &Mussa::load_mupa_file, "Load mussa parameter file")
+    .def("clear", &Mussa::clear, "Clear the current analysis")
+    .add_property("name", &Mussa::get_name, &Mussa::set_name)
+    .def("size", &Mussa::size, "Number of sequences to be used "
+                               "in this analysis")
+    .add_property("window", &Mussa::get_window, &Mussa::set_window,
+                  "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_thres)
+    .add_property("analysisMode", &Mussa::get_analysis_mode, 
+                                   &Mussa::set_analysis_mode)
+    .add_property("analysisModeName", &Mussa::get_analysis_mode_name)
+    .def("analyze", &Mussa::analyze)
+    .def("paths", &Mussa::paths, return_internal_reference<>())
+    //.def("sequences", &Mussa::sequences)
+    .def("addSequence", &Mussa::add_a_seq)  ;
+
+  enum_<Mussa::analysis_modes>("analysis_modes")
+    .value("TransitiveNway", Mussa::TransitiveNway )
+    .value("RadialNway", Mussa::RadialNway )
+    .value("EntropyNway", Mussa::EntropyNway )
+    .value("RecursiveNway", Mussa::RecursiveNway )
+  ;
+}
diff --git a/py/nway_paths.cxx b/py/nway_paths.cxx
new file mode 100644 (file)
index 0000000..3a03323
--- /dev/null
@@ -0,0 +1,15 @@
+#include <boost/python.hpp>
+using namespace boost::python;
+
+#include "alg/nway_paths.hh"
+
+void export_nway_paths()
+{
+  class_<NwayPaths>("NwayPaths")
+    .add_property("pathz", range(&NwayPaths::pbegin, 
+                                 &NwayPaths::pend))
+    .add_property("refinedPathz", range(&NwayPaths::rpbegin,
+                                        &NwayPaths::rpend))
+  ;
+}
+