5f42599fb78111ea323fda0813c1dc3f43598c0f
[mussa.git] / py / mussa.cpp
1 #include <boost/python.hpp>
2 namespace py = boost::python;
3
4 #include "alg/mussa.hpp"
5 #include "alg/sequence.hpp"
6 #include "stl_container_adapter.hpp"
7
8 void export_mussa()
9 {
10   void (Mussa::*load_mupa_string)(std::string) = &Mussa::load_mupa_file;
11   void (Mussa::*append_sequence_ref)(const Sequence&) = &Mussa::append_sequence;
12   void (Mussa::*append_sequence_ptr)(const boost::shared_ptr<Sequence>) = &Mussa::append_sequence;
13
14   py::class_<Mussa::vector_sequence_type>("Sequences")
15     .def("__len__", &Mussa::vector_sequence_type::size, "return length of sequences")
16     .def("__contains__", &std_item<Mussa::vector_sequence_type>::in)
17     .def("__iter__", py::iterator<Mussa::vector_sequence_type>())
18     .def("clear", &Mussa::vector_sequence_type::clear, "remove all the sequences")
19     .def("append", &std_item<Mussa::vector_sequence_type>::add,
20         py::with_custodian_and_ward<1,2>()) // to let container keep value
21     .def("__getitem__", &std_item<Mussa::vector_sequence_type>::get,
22         py::return_value_policy<py::copy_non_const_reference>())
23     .def("__setitem__", &std_item<Mussa::vector_sequence_type>::set,
24         py::with_custodian_and_ward<1,2>()) // to let container keep value
25     .def("__delitem__", &std_item<Mussa::vector_sequence_type>::del)
26   ;
27  
28   py::class_<Mussa>("_Mussa", py::no_init)
29     .def("save", &Mussa::save)
30     .def("load", &Mussa::load, "Load previous run analysis")
31     .def("load_mupa", load_mupa_string, "Load mussa parameter file")
32     .def("clear", &Mussa::clear, "Clear the current analysis")
33     .add_property("name", &Mussa::get_name, &Mussa::set_name, "Set the name of the analysis")
34     .def("size", &Mussa::size, "Number of sequences attached to "
35                                "this analysis")
36     .add_property("window", &Mussa::get_window, &Mussa::set_window,
37                   "the number of base pairs in the sliding window")
38     .add_property("threshold", &Mussa::get_threshold, &Mussa::set_threshold,
39                   "how many base pairs must match between two windows")
40     .def("softThreshold", &Mussa::set_soft_threshold)
41     .add_property("analysisMode", &Mussa::get_analysis_mode, 
42                                    &Mussa::set_analysis_mode)
43     .add_property("analysisModeName", &Mussa::get_analysis_mode_name)
44     .def("analyze", &Mussa::analyze, "Run the analysis")
45     .def("paths", &Mussa::paths, py::return_internal_reference<>(), "return list of paths")
46     .def("sequences", &Mussa::sequences, py::return_internal_reference<>(), "return list of sequences")
47     .def("add_sequence", append_sequence_ref, "attach a sequence to the analysis")  
48   ;
49   py::def("Mussa", &Mussa::init, "Construct a new Mussa object");
50   py::register_ptr_to_python< boost::shared_ptr<Mussa> >();
51   
52   py::enum_<Mussa::analysis_modes>("analysis_modes")
53     .value("TransitiveNway", Mussa::TransitiveNway )
54     .value("RadialNway", Mussa::RadialNway )
55     .value("EntropyNway", Mussa::EntropyNway )
56     .value("RecursiveNway", Mussa::RecursiveNway )
57   ;
58 }