From 0442acb63b83e33aaf16e20f6a3efd1d92677fc0 Mon Sep 17 00:00:00 2001 From: Marco Biasini <marco.biasini@unibas.ch> Date: Fri, 15 Oct 2010 10:34:31 +0200 Subject: [PATCH] make AttachView stricter The method now checks for agreement of the one letter code in the structure and the character in the sequence. If there is a mismatch, AttachView throws an IntegrityError telling you where in the sequence the problem was detected. The one letter code of the residue and the character in the sequence agree, if either one of the is X or they are identical. --- modules/seq/base/doc/seq.rst | 6 ++++++ modules/seq/base/src/impl/sequence_impl.cc | 22 +++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/modules/seq/base/doc/seq.rst b/modules/seq/base/doc/seq.rst index 243ec0d49..7a849093b 100644 --- a/modules/seq/base/doc/seq.rst +++ b/modules/seq/base/doc/seq.rst @@ -322,6 +322,12 @@ an alignment: Attach the given view to the sequence at index `seq_index`. + The method now checks for agreement of the one letter code in the structure + and the character in the sequence. If there is a mismatch, AttachView throws + an IntegrityError telling you where in the sequence the problem was + detected. The one letter code of the residue and the character in the + sequence agree, if either one of the is X or they are identical. + .. method:: Cut(start, end) Removes the columns in the half-closed interval `start`, `end` from the diff --git a/modules/seq/base/src/impl/sequence_impl.cc b/modules/seq/base/src/impl/sequence_impl.cc index a99ea9b63..15fc8f986 100644 --- a/modules/seq/base/src/impl/sequence_impl.cc +++ b/modules/seq/base/src/impl/sequence_impl.cc @@ -233,10 +233,26 @@ mol::EntityView SequenceImpl::GetAttachedView() const void SequenceImpl::AttachView(const mol::EntityView& view) { - static const char* msg="Expected 1 chain, but %d chains found"; + static const char* msg_1="Expected 1 chain, but %d chains found"; + if (view.IsValid() && view.GetChainCount()!=1) { + throw IntegrityError(str(format(msg_1) % view.GetChainCount())); + } attached_view_=view; - if (view.IsValid() && attached_view_.GetChainCount()!=1) { - throw IntegrityError(str(format(msg) % attached_view_.GetChainCount())); + if (!attached_view_.IsValid()) { + return; + } + for (size_t i=0; i<seq_string_.size(); ++i) { + if (mol::ResidueView res=this->GetResidue(i)) { + char olc1=res.GetOneLetterCode(); + char olc2=seq_string_[i]; + if (olc1!='X' && olc2!='X' && olc1!=olc2) { + std::stringstream ss; + ss << "One letter code of residue and sequence does not agree " + "at position " << i << " in sequence (" << res.GetOneLetterCode() + << "!=" << seq_string_[i] << ")"; + throw IntegrityError(ss.str()); + } + } } } -- GitLab