attach annotations property to seq_span
[mussa.git] / py / seq_span.cpp
1 #include <boost/iterator.hpp>
2
3 #include <boost/python.hpp>
4 #include <boost/python/return_value_policy.hpp>
5 #include <boost/python/manage_new_object.hpp>
6
7 #include <boost/python/register_ptr_to_python.hpp>
8 using namespace boost::python;
9
10 #include "alg/seq_span.hpp"
11
12 #include "stl_container_adapter.hpp"
13
14 SeqSpanRef seq_span_factory(
15   const std::string& s, 
16   AlphabetRef a = dna_alphabet, 
17   SeqSpan::strand_type strand = SeqSpan::PlusStrand)
18 {
19   SeqSpanRef seq(new SeqSpan(s, a, strand));
20   return seq;
21 }
22
23 BOOST_PYTHON_FUNCTION_OVERLOADS(
24   seq_span_factory_overloads, 
25   seq_span_factory,
26   1, // minimum arguments
27   3 // maximum arguments
28 );
29
30 void export_seq_span()
31 {
32   enum_<SeqSpan::strand_type>("strand")
33     .value("unknown", SeqSpan::UnknownStrand)
34     .value("minus", SeqSpan::MinusStrand)
35     .value("plus", SeqSpan::PlusStrand)
36     .value("both", SeqSpan::BothStrand)
37     .value("same", SeqSpan::SameStrand)
38     .value("opposite", SeqSpan::OppositeStrand)
39     .value("single", SeqSpan::SingleStrand)
40     ;
41
42   def("SeqSpan", seq_span_factory, 
43       seq_span_factory_overloads(args("sequence", "alphabet", "strand"))
44       );
45
46   class_<SeqSpan>("_SeqSpan", no_init)
47     .def("__getitem__", &std_item<SeqSpan>::get_const,
48         return_value_policy<copy_const_reference>())
49     .def("__len__", &SeqSpan::size)
50     .def("__str__", &SeqSpan::sequence)
51     .def("empty", &SeqSpan::empty)
52     //.add_property("alphabet", 
53     //              make_getter(&SeqSpan::get_alphabet,
54     //                          return_value_policy<copy_const_reference>()))
55     .add_property("annotations", &SeqSpan::annotations, 
56                                  &SeqSpan::setAnnotations)
57     .add_property("start", &SeqSpan::start, &SeqSpan::setStart,
58                   "start position relative to root sequence")
59     .add_property("stop", &SeqSpan::stop, &SeqSpan::setStop,
60                   "one past the last position relative to the root sequence.")
61     .add_property("strand", &SeqSpan::strand, 
62                   "describe which strand the span is on")
63
64     .add_property("parentStart", &SeqSpan::parentStart, &SeqSpan::setParentStart,
65                   "start position relative to parent sequence")
66     .add_property("parentStop", &SeqSpan::parentStop, &SeqSpan::setParentStop,
67                   "one past the last position relative to the parent sequence.")
68     // doesn't work because I keep getting new python objects for the same
69     // shared ptr
70     //.def("parent", &SeqSpan::parent)
71     .def("subseq", &SeqSpan::subseq)
72     ;
73  
74   register_ptr_to_python< SeqSpanRef >();
75 }