From 44711e0d708ddb210309804253550834dab1fd5f Mon Sep 17 00:00:00 2001 From: Marco Biasini <marco.biasini@unibas.ch> Date: Wed, 30 Mar 2011 14:05:59 +0200 Subject: [PATCH] fix BZDNG-187 and BZDNG-148 --- modules/seq/base/pymod/export_sequence.cc | 7 +++++-- modules/seq/base/src/sequence_handle.cc | 9 +++++++++ modules/seq/base/src/sequence_handle.hh | 12 ++++++++++++ modules/seq/base/tests/test_seq.py | 5 ++++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/modules/seq/base/pymod/export_sequence.cc b/modules/seq/base/pymod/export_sequence.cc index 454245778..87345ad2a 100644 --- a/modules/seq/base/pymod/export_sequence.cc +++ b/modules/seq/base/pymod/export_sequence.cc @@ -208,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) @@ -287,6 +288,9 @@ void export_sequence() class_<SeqListIter>("SeqListIter", no_init) .def("next", &SeqListIter::next) ; + to_python_converter<std::pair<mol::EntityView, mol::EntityView>, + PairToTupleConverter<mol::EntityView, mol::EntityView> >(); + class_<AlignmentHandle>("AlignmentHandle", init<>()) .def("GetCount", &AlignmentHandle::GetCount) .add_property("sequence_count", &AlignmentHandle::GetCount) @@ -357,8 +361,7 @@ void export_sequence() .def("__getitem__", &do_slice_b) ; implicitly_convertible<SequenceList, ConstSequenceList>(); - to_python_converter<std::pair<mol::EntityView, mol::EntityView>, - PairToTupleConverter<mol::EntityView, mol::EntityView> >(); + 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 6991a14f7..3065ae9f0 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_) { @@ -380,4 +382,11 @@ const GenericPropContainerImpl* SequenceHandle::GpImpl() const { return Impl().get(); } + +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 8d370e59e..d6fb0ab3e 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() @@ -118,6 +121,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; @@ -159,6 +164,7 @@ private: class DLLEXPORT_OST_SEQ SequenceHandle : public GenericPropContainer<SequenceHandle> { public: + typedef String::const_iterator iterator; friend class GenericPropContainer<SequenceHandle>; friend class SequenceList; @@ -255,6 +261,12 @@ 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(); } + operator ConstSequenceHandle() const; /// \brief attach entity view to sequence /// diff --git a/modules/seq/base/tests/test_seq.py b/modules/seq/base/tests/test_seq.py index 80f13e364..9ae40d5fc 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')) -- GitLab