8 """ reads a TALOS file, or a TALOS folder, and stores the data """
10 def __init__(self, sequence, detailed_input, keep_all=False,
11 sequence_match=(1,1)):
12 """start the TALOSReader
13 sequence : a dictionnary of sequence number keys and 3-letter code
15 detailed_input : True if the input will be either predAll.tab or the
16 pred/res???.tab files. False if it's pred.tab
17 keep_all : whether to keep outliers or not, when detailed_input==True.
18 sequence_match : in the form (talos_no, sequence_no), assigns a
19 correspondence between residue numberings.
21 self.detailed_input = detailed_input
23 self.keep_all=keep_all
24 self.sequence=sequence
25 self.offset = sequence_match[1]-sequence_match[0]
28 """in the case of a list of predictions for one residue, add an entry to
31 'num' : number of predictions
32 'phi' : the list of predictions for phi
36 if resno
not in self.data:
37 self.data[resno]={
'full':
True,
'num':len(phi),
'phi':phi,
'psi':psi}
39 raise RuntimeError,
"would overwrite data for residue %d" % resno
42 """in the case of a single (average) prediction output by talos for a
43 given residue, add an entry to data which is:
45 'num' : the number of matches this average was calculated from
46 'phi' : a tuple in the form (mean, error)
51 if resno
not in self.data:
52 self.data[resno]={
'full':
False,
'num':num,
'phi':phi,
'psi':psi}
54 raise RuntimeError,
"would overwrite data for residue %d" % resno
56 def _read_one_residue(self,fname):
58 resno = int(os.path.basename(fname)[3:6]) + self.offset
65 if tokens[1] ==
'RESNAMES':
66 check_residue(self.sequence[resno], tokens[3])
68 if not tokens[0].isdigit():
70 if float(tokens[4]) < 0.999
and not self.keep_all:
72 phi.append(float(tokens[1])*2*pi/360.)
73 psi.append(float(tokens[2])*2*pi/360.)
76 def _read_predAll(self, fname):
81 if len(tokens) == 0
or not tokens[0].isdigit():
84 resno = int(tokens[1]) + self.offset
90 resname = tokens[2][1]
91 check_residue(self.sequence[resno], resname)
92 if float(tokens[6]) < 0.999
and not self.keep_all:
94 phi.append(float(tokens[3])*2*pi/360.)
95 psi.append(float(tokens[4])*2*pi/360.)
97 def _read_observations(self,fname):
98 if fname.endswith(
'predAll.tab'):
99 self._read_predAll(fname)
101 self._read_one_residue(fname)
103 def _read_averages(self, fname):
107 if not tokens[0].isdigit():
109 resno = int(tokens[0]) + self.offset
110 check_residue(resno,tokens[1])
111 phi,psi,dphi,dpsi = map(
lambda a: 2*pi*float(a)/360.,
118 def read(self,fname):
119 "reads a TALOS file and returns data. See add_datum methods."
120 if self.detailed_input:
121 self._read_observations(fname)
123 self._read_averages(fname)
130 if __name__ ==
'__main__':
133 sequence = read_sequence_file(
'seq.dat', sequence_match=(1,5))
136 data=reader.get_data()