3 """@namespace IMP.isd.TALOSReader
4 Classes to handle TALOS files or folders.
12 """ reads a TALOS file, or a TALOS folder, and stores the data """
14 def __init__(self, sequence, detailed_input, keep_all=False,
15 sequence_match=(1,1)):
16 """start the TALOSReader
17 sequence : a dictionnary of sequence number keys and 3-letter code
19 detailed_input : True if the input will be either predAll.tab or the
20 pred/res???.tab files. False if it's pred.tab
21 keep_all : whether to keep outliers or not, when detailed_input==True.
22 sequence_match : in the form (talos_no, sequence_no), assigns a
23 correspondence between residue numberings.
25 self.detailed_input = detailed_input
27 self.keep_all=keep_all
28 self.sequence=sequence
29 self.offset = sequence_match[1]-sequence_match[0]
32 """in the case of a list of predictions for one residue, add an entry to
35 'num' : number of predictions
36 'phi' : the list of predictions for phi
40 if resno
not in self.data:
41 self.data[resno]={
'full':
True,
'num':len(phi),
'phi':phi,
'psi':psi}
43 raise RuntimeError,
"would overwrite data for residue %d" % resno
46 """in the case of a single (average) prediction output by talos for a
47 given residue, add an entry to data which is:
49 'num' : the number of matches this average was calculated from
50 'phi' : a tuple in the form (mean, error)
55 if resno
not in self.data:
56 self.data[resno]={
'full':
False,
'num':num,
'phi':phi,
'psi':psi}
58 raise RuntimeError,
"would overwrite data for residue %d" % resno
60 def _read_one_residue(self,fname):
62 resno = int(os.path.basename(fname)[3:6]) + self.offset
69 if tokens[1] ==
'RESNAMES':
70 check_residue(self.sequence[resno], tokens[3])
72 if not tokens[0].isdigit():
74 if float(tokens[4]) < 0.999
and not self.keep_all:
76 phi.append(float(tokens[1])*2*pi/360.)
77 psi.append(float(tokens[2])*2*pi/360.)
80 def _read_predAll(self, fname):
85 if len(tokens) == 0
or not tokens[0].isdigit():
88 resno = int(tokens[1]) + self.offset
94 resname = tokens[2][1]
95 check_residue(self.sequence[resno], resname)
96 if float(tokens[6]) < 0.999
and not self.keep_all:
98 phi.append(float(tokens[3])*2*pi/360.)
99 psi.append(float(tokens[4])*2*pi/360.)
101 def _read_observations(self,fname):
102 if fname.endswith(
'predAll.tab'):
103 self._read_predAll(fname)
105 self._read_one_residue(fname)
107 def _read_averages(self, fname):
111 if not tokens[0].isdigit():
113 resno = int(tokens[0]) + self.offset
114 check_residue(resno,tokens[1])
115 phi,psi,dphi,dpsi = map(
lambda a: 2*pi*float(a)/360.,
123 "reads a TALOS file and returns data. See add_datum methods."
124 if self.detailed_input:
125 self._read_observations(fname)
127 self._read_averages(fname)
134 if __name__ ==
'__main__':
137 sequence = read_sequence_file(
'seq.dat', sequence_match=(1,5))
140 data=reader.get_data()
def add_full_datum
in the case of a list of predictions for one residue, add an entry to data which is: 'full' : always ...
reads a TALOS file, or a TALOS folder, and stores the data
def read
reads a TALOS file and returns data.
def add_mean_datum
in the case of a single (average) prediction output by talos for a given residue, add an entry to dat...