1
2
3
4
5
6 """Class that maps (chain_id, residue_id) to a residue property."""
7
8
9
11 - def __init__(self, property_dict, property_keys, property_list):
12 self.property_dict=property_dict
13 self.property_keys=property_keys
14 self.property_list=property_list
15
18
20 """True if the mapping has a property for this residue.
21
22 Example:
23 >>> if (chain_id, res_id) in apmap:
24 ... res, prop = apmap[(chain_id, res_id)]
25
26 @param chain_id: chain id
27 @type chain_id: char
28
29 @param res_id: residue id
30 @type res_id: char
31 """
32 translated_id = self._translate_id(id)
33 return (translated_id in self.property_dict)
34
36 """
37 Return property for a residue.
38
39 @param chain_id: chain id
40 @type chain_id: char
41
42 @param res_id: residue id
43 @type res_id: int or (char, int, char)
44
45 @return: some residue property
46 @rtype: anything (can be a tuple)
47 """
48 translated_id=self._translate_id(key)
49 return self.property_dict[translated_id]
50
52 """
53 Return number of residues for which the property is available.
54
55 @return: number of residues
56 @rtype: int
57 """
58 return len(self.property_dict)
59
61 """True if the mapping has a property for this residue.
62
63 (Obsolete; use "id in mapping" instead.)
64
65 Example:
66
67 >>> if apmap.has_key((chain_id, res_id)):
68 ... res, prop = apmap[(chain_id, res_id)]
69
70 Is equivalent to:
71
72 >>> if (chain_id, res_id) in apmap:
73 ... res, prop = apmap[(chain_id, res_id)]
74
75 @param chain_id: chain id
76 @type chain_id: char
77
78 @param res_id: residue id
79 @type res_id: char
80 """
81 import warnings
82 from Bio import BiopythonDeprecationWarning
83 warnings.warn("This function is deprecated; use 'id in mapping' instead", BiopythonDeprecationWarning)
84 return (id in self)
85
87 """
88 Return the list of residues.
89
90 @return: list of residues for which the property was calculated
91 @rtype: [(chain_id, res_id), (chain_id, res_id),...]
92 """
93 return self.property_keys
94
96 """
97 Iterate over the (entity, property) list. Handy alternative to
98 the dictionary-like access.
99
100 Example:
101 >>> for (res, property) in iter(map):
102 ... print res, property
103
104 @return: iterator
105 """
106 for i in range(0, len(self.property_list)):
107 yield self.property_list[i]
108
109
111 - def __init__(self, property_dict, property_keys, property_list):
114
116 chain_id, res_id=ent_id
117 if isinstance(res_id, int):
118 ent_id=(chain_id, (' ', res_id, ' '))
119 return ent_id
120
121
123 - def __init__(self, property_dict, property_keys, property_list):
126
128 if len(ent_id)==4:
129 chain_id, res_id, atom_name, icode=ent_id
130 else:
131 chain_id, res_id, atom_name=ent_id
132 icode=None
133 if isinstance(res_id, int):
134 ent_id=(chain_id, (' ', res_id, ' '), atom_name, icode)
135 return ent_id
136