diff --git a/modules/seq/base/pymod/export_sequence.cc b/modules/seq/base/pymod/export_sequence.cc index c431dfa9b51a47a3c7a6a43eae25ab8a8c574a5e..ca673fcbaddf717080740931f2dcb8d76182b6ce 100644 --- a/modules/seq/base/pymod/export_sequence.cc +++ b/modules/seq/base/pymod/export_sequence.cc @@ -21,6 +21,8 @@ #include <boost/python/register_ptr_to_python.hpp> #include <boost/python/suite/indexing/vector_indexing_suite.hpp> + +#include <ost/export_helper/pair_to_tuple_conv.hh> #include <ost/generic_property.hh> #include <ost/export_helper/generic_property_def.hh> #include <ost/info/info.hh> @@ -206,6 +208,7 @@ void const_seq_handle_def(O& bp_class) .def("GetLength", &C::GetLength) .def("GetResidue", &C::GetResidue) .def("GetOneLetterCode", &C::GetOneLetterCode) + .def("__iter__", iterator<C>()) .def("__getitem__", &C::GetOneLetterCode) .def("GetOffset", &C::GetOffset) .def("Copy", &C::Copy) @@ -297,8 +300,6 @@ void export_sequence() .def("Copy", &AlignmentHandle::Copy) .def("ToString", &AlignmentHandle::ToString) .def("GetLength", &AlignmentHandle::GetLength) - .def("GetMatchingBackboneViews", &AlignmentHandle::GetMatchingBackboneViews, - (arg("index1")=0, arg("index2")=1)) .def("__len__", &AlignmentHandle::GetLength) .def("GetSequences", &AlignmentHandle::GetSequences) .def("GetCoverage", &AlignmentHandle::GetSequences) @@ -357,7 +358,7 @@ void export_sequence() .def("__getitem__", &do_slice_b) ; implicitly_convertible<SequenceList, ConstSequenceList>(); - + def("CreateSequenceList", &CreateSequenceList); def("SequenceFromChain", seq_from_chain_a); def("SequenceFromChain", seq_from_chain_b); diff --git a/modules/seq/base/src/sequence_handle.cc b/modules/seq/base/src/sequence_handle.cc index 2e7c675a16e0824f902644da6880331b70dcc5a0..caeccfaececda45b3f61efc37f44201385607523 100644 --- a/modules/seq/base/src/sequence_handle.cc +++ b/modules/seq/base/src/sequence_handle.cc @@ -58,6 +58,8 @@ char ConstSequenceHandle::operator[](int index) const } + + void ConstSequenceHandle::CheckValidity() const { if (!impl_) { @@ -398,4 +400,11 @@ int SequenceHandle::GetIndex(const String& substr) const this->CheckValidity(); return Impl()->GetIndex(substr); } + +char SequenceHandle::operator[](size_t index) const +{ + this->CheckValidity(); + return this->GetString()[index]; +} + }} diff --git a/modules/seq/base/src/sequence_handle.hh b/modules/seq/base/src/sequence_handle.hh index 7db1f08ef1e5db2d05f700f89b3efba0337607be..a84e1b18db19cef0b35a4e2cdf1d8f954d458fec 100644 --- a/modules/seq/base/src/sequence_handle.hh +++ b/modules/seq/base/src/sequence_handle.hh @@ -49,6 +49,9 @@ public: friend class AlignmentHandle; friend class ConstSequenceList; friend class SequenceList; + + typedef String::const_iterator iterator; + /// \brief create invalid sequence handle /// /// \sa IsValid() @@ -121,6 +124,8 @@ public: char operator[](int index) const; + iterator begin() const { return this->GetString().begin(); } + iterator end() const { return this->GetString().end(); } /// \brief whether the sequence is valid bool IsValid() const; @@ -162,6 +167,7 @@ private: class DLLEXPORT_OST_SEQ SequenceHandle : public GenericPropContainer<SequenceHandle> { public: + typedef String::const_iterator iterator; friend class GenericPropContainer<SequenceHandle>; friend class SequenceList; @@ -261,6 +267,10 @@ public: void SetOneLetterCode(int position, char new_char); + char operator[](size_t index) const; + + iterator begin() const { return this->GetString().begin(); } + iterator end() const { return this->GetString().end(); } void Append(char olc); operator ConstSequenceHandle() const; diff --git a/modules/seq/base/tests/test_seq.py b/modules/seq/base/tests/test_seq.py index 80f13e364c07e3ba9665f34e62a462af79ae79ec..9ae40d5fc98cba9e64d15efe67dabd0978fc718b 100644 --- a/modules/seq/base/tests/test_seq.py +++ b/modules/seq/base/tests/test_seq.py @@ -30,7 +30,10 @@ class TestSeq(unittest.TestCase): string_b=''.join([r.one_letter_code for r in b.residues]) self.assertEqual(string_a, 'ABCDFGH') self.assertEqual(string_b, 'ABCDFGH') - + def testSeqIterBZDNG148(self): + s=seq.CreateSequence('A', 'abcdef') + for x in s: + pass def testViewsFromSequences_02(self): seq_a=seq.CreateSequence("A", "ABCD-FGH") seq_a.AttachView(self.ent.Select('rname=A,B,C,D,F,G,H'))