diff --git a/modules/seq/base/doc/seq.rst b/modules/seq/base/doc/seq.rst index 243ec0d49108938923169456f4ba9e9cef8a927f..7a849093bc80ecc8921010dab1ee3fe2eaeb0048 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 a99ea9b6389bcc2655db1bdc459ce6e243253aa7..15fc8f986db9701832b8267e444bbe14622c534a 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()); + } + } } }