diff --git a/modules/seq/alg/doc/seqalg.rst b/modules/seq/alg/doc/seqalg.rst index ca6476b663e7ccfe637bf083ed31ef63cdb3d383..66cbb0f41eb3f10c9455b7aad7f9e821cacaf27d 100644 --- a/modules/seq/alg/doc/seqalg.rst +++ b/modules/seq/alg/doc/seqalg.rst @@ -1,4 +1,4 @@ -:mod:`mol.alg <ost.seq.alg>` -- Algorithms for Sequences +:mod:`seq.alg <ost.seq.alg>` -- Algorithms for Sequences ================================================================================ .. currentmodule:: ost.seq.alg @@ -30,4 +30,6 @@ considered as aligned. There is no information in the pairwise alignment to guide the merging, the result is undefined. -.. autofunction:: AlignToSEQRES \ No newline at end of file +.. autofunction:: AlignToSEQRES + +.. autofunction:: AlignmentFromChainView \ No newline at end of file diff --git a/modules/seq/alg/pymod/__init__.py b/modules/seq/alg/pymod/__init__.py index 1862fc812427adfb37c9758786f39007f8e4352c..ce80e939ef6597794402510610253bc38694b1c8 100644 --- a/modules/seq/alg/pymod/__init__.py +++ b/modules/seq/alg/pymod/__init__.py @@ -39,5 +39,40 @@ def AlignToSEQRES(chain, seqres): return seq.CreateAlignment(seq.CreateSequence('SEQRES', str(seqres)), seq.CreateSequence('atoms', aln_seq)) - + +def AlignmentFromChainView(chain, handle_seq_name='handle', + view_seq_name='view'): + """ + Creates and returns the sequence alignment of the given chain view to the + chain handle. The alignment contains two sequences, the first containing all + non-ligand peptide-linking residues, the second containing all non-ligand + peptide-linking residues that are part of the view. + :param chain: A valid chain + :type chain: :class:`~ost.mol.ChainView` + + :param handle_seq_name: Name of the handle sequence in the output alignment + :param view_seq_name: Name of the view sequence in the output alignment + :returns: The alignment + :rtype: :class:`~ost.seq.AlignmentHandle` + + """ + from ost import seq + v0=chain.handle.Select('ligand=false and peptide=true') + v1=chain.Select('ligand=false and peptide=true') + s0=seq.CreateSequence(handle_seq_name, '') + s1=seq.CreateSequence(view_seq_name, '') + s0.AttachView(v0) + s1.AttachView(v1) + res0=v0.residues + res1=v1.residues + idx0, idx1=(0, 0) + while idx0<len(res0): + s0.Append(res0[idx0].one_letter_code) + if idx1<len(res1) and res1[idx1].handle==res0[idx0].handle: + s1.Append(res1[idx1].one_letter_code) + idx1+=1 + else: + s1.Append('-') + idx0+=1 + return seq.CreateAlignment(s0, s1) diff --git a/modules/seq/base/pymod/export_sequence.cc b/modules/seq/base/pymod/export_sequence.cc index ca673fcbaddf717080740931f2dcb8d76182b6ce..c72fe3ae8e65f0f65d78e6751d57655b61711eb4 100644 --- a/modules/seq/base/pymod/export_sequence.cc +++ b/modules/seq/base/pymod/export_sequence.cc @@ -256,6 +256,7 @@ void export_sequence() .def("SetOffset", &SequenceHandle::SetOffset) .def("AttachView", attach_one) .def("AttachView", attach_two) + .def("Append", &SequenceHandle::Append) .def("SetString", &SequenceHandle::SetString) .add_property("string", make_function(&SequenceHandle::GetString,