X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=mussa.git;a=blobdiff_plain;f=py%2Fseq_span.cpp;h=d3e0b5b9bcb1563ebb162f08912e910447dfaabd;hp=aa484c99ddba1a965f16eaa122a08e3974a0544f;hb=7a55c95eeeb792f89df39dc9375040dcbd415dfd;hpb=64fee605ec84d0923384f9a709d4471b6030862f diff --git a/py/seq_span.cpp b/py/seq_span.cpp index aa484c9..d3e0b5b 100644 --- a/py/seq_span.cpp +++ b/py/seq_span.cpp @@ -2,6 +2,7 @@ #include #include +#include #include using namespace boost::python; @@ -10,9 +11,25 @@ using namespace boost::python; #include "stl_container_adapter.hpp" +SeqSpanRef seq_span_factory( + const std::string& s, + AlphabetRef a = dna_alphabet, + SeqSpan::strand_type strand = SeqSpan::PlusStrand) +{ + SeqSpanRef seq(new SeqSpan(s, a, strand)); + return seq; +} + +BOOST_PYTHON_FUNCTION_OVERLOADS( + seq_span_factory_overloads, + seq_span_factory, + 1, // minimum arguments + 3 // maximum arguments +); + void export_seq_span() { - enum_("strand_type") + enum_("strand") .value("unknown", SeqSpan::UnknownStrand) .value("minus", SeqSpan::MinusStrand) .value("plus", SeqSpan::PlusStrand) @@ -22,16 +39,19 @@ void export_seq_span() .value("single", SeqSpan::SingleStrand) ; + def("SeqSpan", seq_span_factory, + seq_span_factory_overloads(args("sequence", "alphabet", "strand")) + ); - class_("SeqSpan", - init - >() ) - .def("__len__", &SeqSpan::size) + class_("_SeqSpan", no_init) .def("__getitem__", &std_item::get_const, return_value_policy()) + .def("__len__", &SeqSpan::size) .def("__str__", &SeqSpan::sequence) .def("empty", &SeqSpan::empty) + //.add_property("alphabet", + // make_getter(&SeqSpan::get_alphabet, + // return_value_policy())) .add_property("start", &SeqSpan::start, &SeqSpan::setStart, "start position relative to root sequence") .add_property("stop", &SeqSpan::stop, &SeqSpan::setStop, @@ -43,10 +63,11 @@ void export_seq_span() "start position relative to parent sequence") .add_property("parentStop", &SeqSpan::parentStop, &SeqSpan::setParentStop, "one past the last position relative to the parent sequence.") - .add_property("parent", &SeqSpan::parent) - + // doesn't work because I keep getting new python objects for the same + // shared ptr + //.def("parent", &SeqSpan::parent) .def("subseq", &SeqSpan::subseq) ; - register_ptr_to_python< boost::shared_ptr >(); + register_ptr_to_python< SeqSpanRef >(); }