static const std::string name_str;
public:
- typedef std::map<std::string, std::string> metadata_map;
+ typedef std::string key_type;
+ typedef std::string mapped_type;
+ typedef std::map<key_type, mapped_type> metadata_map;
+ typedef metadata_map::iterator iterator;
+ typedef metadata_map::const_iterator const_iterator;
typedef metadata_map::size_type size_type;
Annotations();
//! make a shared pointer copy of our object
AnnotationsRef copy() const;
+
+ mapped_type& operator[](const key_type& k) { return metadata[k]; }
//! provide a special case for accessing a name
std::string name() const { return metadata.find(name_str)->second; }
//! Generic metadata handling
//@{
+ //! begin iterator
+ iterator begin() { return metadata.begin(); }
+ //! const begin iterator
+ const_iterator begin() const { return metadata.begin(); }
+ //! end iterator
+ iterator end() { return metadata.end(); }
+ //! const end iterator
+ const_iterator end() const { return metadata.end(); }
//! remove some key from our "dictionary"
void erase(const std::string& key);
+ //! find an element in the map
+ iterator find( const key_type& key) { return metadata.find(key); }
+ const_iterator find( const key_type& key) const { return metadata.find(key); }
//! set a metadata element
void set(const std::string key, const std::string value );
//! look for a key, \throws annotation_key_error if it doesn't find it
std::string getdefault(const std::string key, std::string default_value) const;
//! check for a key
bool has_key(const std::string key) const;
- //! return all the keys of our metadata map
- //std::list<std::string> keys() const;
+ //! return number of items in the map
size_type size() const { return metadata.size(); }
//@}
protected:
alphabet.cpp
annot.cpp
annotation_colors.cpp
+ annotations.cpp
conserved_path.cpp
flp.cpp
glsequence.cpp
IF(PYTHON_EXECUTABLE)
SET(PYTEST_DIR ${CMAKE_SOURCE_DIR}/py/test/)
+ ADD_TEST(TestAnnotations
+ ${PYTHON_EXECUTABLE} ${PYTEST_DIR}/TestAnnotations.py)
ADD_TEST(TestSeqSpan ${PYTHON_EXECUTABLE} ${PYTEST_DIR}/TestSeqSpan.py)
ADD_TEST(TestSequence ${PYTHON_EXECUTABLE} ${PYTEST_DIR}/TestSequence.py)
ADD_TEST(TestFlp ${PYTHON_EXECUTABLE} ${PYTEST_DIR}/TestFlp.py)
--- /dev/null
+#include <boost/iterator.hpp>
+
+#include <boost/python.hpp>
+#include <boost/python/return_value_policy.hpp>
+#include <boost/python/manage_new_object.hpp>
+
+#include <boost/python/register_ptr_to_python.hpp>
+using namespace boost::python;
+
+#include "alg/annotations.hpp"
+
+#include "stl_container_adapter.hpp"
+
+void export_annotations()
+{
+
+ class_<Annotations>("annotations", init<std::string>())
+ .add_property("name", &Annotations::name, &Annotations::setName)
+ .def("__contains__", &map_item<Annotations>::in)
+ .def("__delitem__", &map_item<Annotations>::del)
+ .def("__getitem__", &map_item<Annotations>::get,
+ return_value_policy<copy_non_const_reference>())
+ .def("__setitem__", &map_item<Annotations>::set)
+ .def("__len__", &Annotations::size)
+ .def("keys", &map_item<Annotations>::keys)
+ .def("values", &map_item<Annotations>::values)
+ .def("items", &map_item<Annotations>::items)
+ ;
+
+ //register_ptr_to_python< AnnotationsRef >();
+}
void export_alphabet();
void export_annot();
void export_annotation_colors();
+void export_annotations();
void export_container_exceptions();
void export_conserved_path();
void export_flps();
export_alphabet();
export_annot();
export_annotation_colors();
+ export_annotations();
export_conserved_path();
export_flps();
export_seq_span();
{
typedef typename T::key_type K;
typedef typename T::mapped_type V;
- static V& get(T const& x, K const& i)
+ static V& get(T & x, K const& i)
{
if( x.find(i) != x.end() ) return x[i];
throw KeyError();
}
- static void set(T const& x, K const& i, V const& v)
+ static void set(T & x, K const& i, V const& v)
{
x[i]=v; // use map autocreation feature
}
- static void del(T const& x, K const& i)
+ static void del(T & x, K const& i)
{
if( x.find(i) != x.end() ) x.erase(i);
else throw KeyError();
static boost::python::list keys(T const& x)
{
boost::python::list t;
- for(typename T::const_iterator it=x.begin; it!=x.end(); ++it)
+ for(typename T::const_iterator it=x.begin(); it!=x.end(); ++it)
t.append(it->first);
return t;
}
static boost::python::list values(T const& x)
{
boost::python::list t;
- for(typename T::const_iterator it=x.begin; it!=x.end(); ++it)
+ for(typename T::const_iterator it=x.begin(); it!=x.end(); ++it)
t.append(it->second);
return t;
}
static boost::python::list items(T const& x)
{
boost::python::list t;
- for(typename T::const_iterator it=x.begin; it!=x.end(); ++it)
+ for(typename T::const_iterator it=x.begin(); it!=x.end(); ++it)
t.append(boost::python::make_tuple(it->first,it->second));
return t;
}
static int index(T const& x, K const& k)
{
int i=0;
- for(typename T::const_iterator it=x.begin; it!=x.end(); ++it,++i)
+ for(typename T::const_iterator it=x.begin(); it!=x.end(); ++it,++i)
if( it->first == k ) return i;
return -1;
}
--- /dev/null
+import os
+import sys
+import unittest
+
+# kinda hackish but it makes it possible to runi under ctest
+sys.path.append(os.getcwd())
+
+import mussa
+
+class TestAnnotations(unittest.TestCase):
+ def testSimple(self):
+ name_value = 'name_value'
+ a = mussa.annotations(name_value)
+ self.failUnlessEqual( a['name'], name_value)
+ self.failUnlessEqual( len(a), 1)
+ self.failUnlessEqual( a.keys(), ['name'])
+ self.failUnlessEqual( a.values(), ['name_value'])
+
+ def testIter(self):
+ name_value = 'name_value'
+ a = mussa.annotations(name_value)
+ # It'd be nice if this worked.
+ # l = [ x for x in a ]
+
+def suite():
+ return unittest.makeSuite(TestAnnotations, 'test')
+
+if __name__ == "__main__":
+ sys.exit(unittest.main(defaultTest='suite'))