From 9c704ecd2ba1a01f0b82d0f1ea6d9d3e3011fff7 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Thu, 6 Sep 2007 23:29:13 +0000 Subject: [PATCH] attach annotations property to seq_span --- py/annotations.cpp | 7 +++---- py/seq_span.cpp | 2 ++ py/test/TestAnnotations.py | 4 ++-- py/test/TestSeqSpan.py | 12 ++++++++++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/py/annotations.cpp b/py/annotations.cpp index 453406d..1418089 100644 --- a/py/annotations.cpp +++ b/py/annotations.cpp @@ -33,7 +33,7 @@ void export_annotations() { to_python_converter(); - class_("annotations", init()) + class_("Annotations", init()) .add_property("name", &Annotations::name, &Annotations::setName) .def("__contains__", &map_item::in) .def("__delitem__", &map_item::del) @@ -45,8 +45,7 @@ void export_annotations() .def("keys", &map_item::keys) .def("values", &map_item::values) .def("items", &map_item::items) + ; - ; - - //register_ptr_to_python< AnnotationsRef >(); + register_ptr_to_python< AnnotationsRef >(); } diff --git a/py/seq_span.cpp b/py/seq_span.cpp index d3e0b5b..74e6244 100644 --- a/py/seq_span.cpp +++ b/py/seq_span.cpp @@ -52,6 +52,8 @@ void export_seq_span() //.add_property("alphabet", // make_getter(&SeqSpan::get_alphabet, // return_value_policy())) + .add_property("annotations", &SeqSpan::annotations, + &SeqSpan::setAnnotations) .add_property("start", &SeqSpan::start, &SeqSpan::setStart, "start position relative to root sequence") .add_property("stop", &SeqSpan::stop, &SeqSpan::setStop, diff --git a/py/test/TestAnnotations.py b/py/test/TestAnnotations.py index 6c432bd..ec254ec 100644 --- a/py/test/TestAnnotations.py +++ b/py/test/TestAnnotations.py @@ -10,7 +10,7 @@ import mussa class TestAnnotations(unittest.TestCase): def testSimple(self): name_value = 'name_value' - a = mussa.annotations(name_value) + a = mussa.Annotations(name_value) self.failUnlessEqual( a['name'], name_value) self.failUnlessEqual( len(a), 1) self.failUnlessEqual( a.keys(), ['name']) @@ -18,7 +18,7 @@ class TestAnnotations(unittest.TestCase): def testIter(self): name_value = 'name_value' - a = mussa.annotations(name_value) + a = mussa.Annotations(name_value) l = [ x for x in a ] self.failUnlessEqual(len(l), 1) self.failUnlessEqual(l[0], ('name', 'name_value')) diff --git a/py/test/TestSeqSpan.py b/py/test/TestSeqSpan.py index de10824..3a56d92 100644 --- a/py/test/TestSeqSpan.py +++ b/py/test/TestSeqSpan.py @@ -42,6 +42,18 @@ class TestSeqSpan(unittest.TestCase): # self.failUnless(sparent is s1.parent()) # self.failUnlessEqual(sparent == s1.parent()) + def testAnnotations(self): + seq_text = "AAAAAG" + name = "As" + s = mussa.SeqSpan(seq_text) + s.annotations = mussa.Annotations(name) + self.failUnlessEqual(s.annotations.name, name) + self.failUnlessEqual(s.annotations['name'], name) + + term_key = 'GO term' + term = "term" + s.annotations[term_key] = term + self.failUnlessEqual(s.annotations[term_key], term) def suite(): return unittest.makeSuite(TestSeqSpan, 'test') -- 2.30.2