1 from ost
import io, seq, mol, conop
4 def Renumber(seq_handle, sequence_number_with_attached_view=1):
6 Function to renumber an entity according to an alignment between the model sequence
7 and the full-length target sequence. The aligned model sequence or the alignment itself
8 with an attached view needs to be provided. Upon succcess, the renumbered entity is returned.
10 .. code-block:: python
12 from ost.seq.alg import renumber
13 from ost.bindings.clustalw import *
14 ent=io.LoadPDB("path_to_model")
15 s=io.LoadSequence("path_to_full_length_fasta_seqeunce")
16 pdb_seq=seq.SequenceFromChain("model", ent.chains[0])
17 aln=ClustalW(s,pdb_seq)
18 aln.AttachView(1,ent.chains[0].Select(""))
19 e=Renumber(aln.GetSequence(sequence_number_with_attached_view))
20 io.SavePDB(e, "renum.pdb")
24 if seq_handle.HasAttachedView()==
False:
25 raise RuntimeError,
"Sequence Handle has no attached view"
26 changed_residue_count=0
27 renumberingFlag =
False
28 ent_n=mol.CreateEntity()
31 for pos
in range(len(seq_handle)):
32 if seq_handle[pos]!=
'-':
33 r=seq_handle.GetResidue(pos)
36 if r.number.num!=pos+1:
37 changed_residue_count+=1
38 renumberingFlag =
True
39 r_n=ed.AppendResidue(c,r.name,
mol.ResNum(pos+1))
41 ed.InsertAtom(r_n,atom.name,atom.pos,element=atom.element)
43 err=
'Error: renumbering failed at position %s' %pos
44 raise RuntimeError, err
45 if renumberingFlag ==
True:
46 err =
'Warning: %s residues have been renumbered!' %changed_residue_count
48 conop.ConnectAll(ent_n)
52 if seq_handle.GetSequence(sequence_number_with_attached_view).HasAttachedView()==
False:
53 raise RuntimeError,
"Sequence Handle has no attached view"
56 changed_residue_count=0
57 renumberingFlag =
False
58 ent_n=mol.CreateEntity()
60 c=ed.InsertChain(seq_handle.GetSequence(sequence_number_with_attached_view).GetAttachedView().chains[0].name)
61 for col
in seq_handle:
62 if col[0]!=
'-' and col[1]!=
'-':
64 rnum=seq_handle.GetSequence(sequence_number_with_attached_view).GetResidueIndex(counter)
65 r=seq_handle.GetSequence(sequence_number_with_attached_view).GetResidue(counter)
67 if r.number.num!=counter+1:
68 changed_residue_count+=1
69 renumberingFlag =
True
70 r_n=ed.AppendResidue(c,r.name,
mol.ResNum(counter+1))
72 ed.InsertAtom(r_n,atom.name,atom.pos,atom.element, atom.b_factor,
73 atom.occupancy, atom.is_hetatom)
76 raise RuntimeError(
"invalide residue at postion %s (renumbering failed)" %(counter))
78 raise RuntimeError(
"residue mismatch at position %d (%s vs %s) (renumbering failed)"%(counter, col[0],col[1]))
80 if renumberingFlag ==
True:
81 err =
'Warning: %s residues have been renumbered!' %changed_residue_count
83 conop.ConnectAll(ent_n)