1 from ost
import io, seq, mol, conop
5 def _RenumberSeq(seq_handle):
6 if not seq_handle.HasAttachedView():
7 raise RuntimeError(
"Sequence Handle has no attached view")
8 ev = seq_handle.attached_view.CreateEmptyView()
9 new_numbers = mol.ResNumList()
10 for pos
in range(len(seq_handle)):
11 if seq_handle[pos]!=
'-':
12 r=seq_handle.GetResidue(pos)
15 ev.AddResidue(r, mol.INCLUDE_ALL)
16 new_numbers.append(pos+1)
18 raise RuntimeError(
'Error: renumbering failed at position %s' %pos)
19 return ev, new_numbers
21 def _RenumberAln(aln, seq_index):
22 if not aln.sequences[seq_index].HasAttachedView():
23 raise RuntimeError(
"Sequence Handle has no attached view")
25 ev = aln.sequences[seq_index].attached_view.CreateEmptyView()
26 new_numbers = mol.ResNumList()
28 if col[0]!=
'-' and col[seq_index]!=
'-':
29 if col[0]!=col[seq_index]:
30 raise RuntimeError(
"residue mismatch at position %d (%s vs %s) (renumbering failed)"%(counter, col[0],col[1]))
31 rnum=aln.GetSequence(seq_index).GetResidueIndex(counter)
32 r=aln.GetSequence(seq_index).GetResidue(counter)
34 raise RuntimeError(
"invalid residue at postion %s (renumbering failed)" %(counter))
35 ev.AddResidue(r, mol.INCLUDE_ALL)
36 new_numbers.append(counter+1)
38 return ev, new_numbers
41 def Renumber(seq_handle, sequence_number_with_attached_view=1):
43 Function to renumber an entity according to an alignment between the model sequence
44 and the full-length target sequence. The aligned model sequence or the alignment itself
45 with an attached view needs to be provided. Upon succcess, the renumbered entity is returned.
47 .. code-block:: python
49 from ost.seq.alg import renumber
50 from ost.bindings.clustalw import *
51 ent=io.LoadPDB("path_to_model")
52 s=io.LoadSequence("path_to_full_length_fasta_seqeunce")
53 pdb_seq=seq.SequenceFromChain("model", ent.chains[0])
54 aln=ClustalW(s,pdb_seq)
55 aln.AttachView(1,ent.chains[0].Select(""))
56 e=Renumber(aln.GetSequence(sequence_number_with_attached_view))
57 io.SavePDB(e, "renum.pdb")
61 ev, new_numbers = _RenumberSeq(seq_handle)
63 ev, new_numbers = _RenumberAln(seq_handle, sequence_number_with_attached_view)
65 ev.AddAllInclusiveBonds()
66 new_ent = mol.CreateEntityFromView(ev,
False);
67 new_ent.EditXCS().RenumberChain(new_ent.chains[0], new_numbers)