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