1
2
3
4
5
6
7 from __future__ import generators
8
9 from Bio.PDB import *
10
11 __doc__="""
12 Map the residues of two structures to each other based on
13 a FASTA alignment file.
14 """
15
16
18 """
19 This class aligns two structures based on a FASTA alignment of their
20 sequences.
21 """
22 - def __init__(self, fasta_align, m1, m2, si=0, sj=1):
23 """
24 fasta_align --- A Bio.Fasta.FastaAlign object
25 m1, m2 --- two models
26 si, sj --- the sequences in the Bio.Fasta.FastaAlign object that
27 correspond to the structures
28 """
29 l=fasta_align.get_alignment_length()
30 s1=fasta_align.get_seq_by_num(si)
31 s2=fasta_align.get_seq_by_num(sj)
32
33 rl1=Selection.unfold_entities(m1, 'R')
34 rl2=Selection.unfold_entities(m2, 'R')
35
36 p1=0
37 p2=0
38
39 map12={}
40 map21={}
41
42 duos=[]
43 for i in range(0, l):
44 column=fasta_align.get_column(i)
45 aa1=column[si]
46 aa2=column[sj]
47 if aa1!="-":
48
49 while 1:
50
51 r1=rl1[p1]
52 p1=p1+1
53 if is_aa(r1):
54 break
55 self._test_equivalence(r1, aa1)
56 else:
57 r1=None
58 if aa2!="-":
59
60 while 1:
61
62 r2=rl2[p2]
63 p2=p2+1
64 if is_aa(r2):
65 break
66 self._test_equivalence(r2, aa2)
67 else:
68 r2=None
69 if r1:
70
71 map12[r1]=r2
72 if r2:
73
74 map21[r2]=r1
75
76 duos.append((r1, r2))
77 self.map12=map12
78 self.map21=map21
79 self.duos=duos
80
86
88 """
89 Return two dictionaries that map a residue in one structure to
90 the equivealent residue in the other structure.
91 """
92 return self.map12, self.map21
93
95 """
96 Iterator over all residue pairs.
97 """
98 for i in range(0, len(self.duos)):
99 yield self.duos[i]
100
101
102 if __name__=="__main__":
103 import sys
104 import Bio.Fasta.FastaAlign
105 from Bio.PDB import *
106
107
108 fa=Bio.Fasta.FastaAlign.parse_file(sys.argv[1], 'PROTEIN')
109
110 pdb_file1=sys.argv[2]
111 pdb_file2=sys.argv[3]
112
113
114 p=PDBParser()
115 s1=p.get_structure('1', pdb_file1)
116 p=PDBParser()
117 s2=p.get_structure('2', pdb_file2)
118
119
120 m1=s1[0]
121 m2=s2[0]
122
123 al=StructureAlignment(fa, m1, m2)
124
125
126 for (r1,r2) in al.get_iterator():
127 print r1, r2
128