3 """@namespace IMP.isd.TALOSReader
4 Classes to handle TALOS files or folders.
7 from __future__
import print_function
15 """ reads a TALOS file, or a TALOS folder, and stores the data """
17 def __init__(self, sequence, detailed_input, keep_all=False,
18 sequence_match=(1, 1)):
19 """start the TALOSReader
20 sequence : a dictionary of sequence number keys and 3-letter code
22 detailed_input : True if the input will be either predAll.tab or the
23 pred/res???.tab files. False if it's pred.tab
24 keep_all : whether to keep outliers or not, when detailed_input==True.
25 sequence_match : in the form (talos_no, sequence_no), assigns a
26 correspondence between residue numberings.
28 self.detailed_input = detailed_input
30 self.keep_all = keep_all
31 self.sequence = sequence
32 self.offset = sequence_match[1] - sequence_match[0]
35 """in the case of a list of predictions for one residue, add an entry
38 'num' : number of predictions
39 'phi' : the list of predictions for phi
43 if resno
not in self.data:
45 'full':
True,
'num': len(phi),
'phi': phi,
'psi': psi}
47 raise RuntimeError(
"would overwrite data for residue %d" % resno)
50 """in the case of a single (average) prediction output by talos for a
51 given residue, add an entry to data which is:
53 'num' : the number of matches this average was calculated from
54 'phi' : a tuple in the form (mean, error)
59 if resno
not in self.data:
67 raise RuntimeError(
"would overwrite data for residue %d" % resno)
69 def _read_one_residue(self, fname):
71 resno = int(os.path.basename(fname)[3:6]) + self.offset
78 if tokens[1] ==
'RESNAMES':
79 check_residue(self.sequence[resno], tokens[3])
81 if not tokens[0].isdigit():
83 if float(tokens[4]) < 0.999
and not self.keep_all:
85 phi.append(float(tokens[1]) * 2 * pi / 360.)
86 psi.append(float(tokens[2]) * 2 * pi / 360.)
89 def _read_predAll(self, fname):
96 if len(tokens) == 0
or not tokens[0].isdigit():
99 resno = int(tokens[1]) + self.offset
100 if resno != oldresno:
105 resname = tokens[2][1]
106 check_residue(self.sequence[resno], resname)
107 if float(tokens[6]) < 0.999
and not self.keep_all:
109 phi.append(float(tokens[3]) * 2 * pi / 360.)
110 psi.append(float(tokens[4]) * 2 * pi / 360.)
112 def _read_observations(self, fname):
113 if fname.endswith(
'predAll.tab'):
114 self._read_predAll(fname)
116 self._read_one_residue(fname)
118 def _read_averages(self, fname):
121 tokens = line.split()
122 if not tokens[0].isdigit():
124 resno = int(tokens[0]) + self.offset
125 check_residue(resno, tokens[1])
126 phi, psi, dphi, dpsi = [2 * pi * float(a) / 360.
127 for a
in tokens[2:6]]
134 "reads a TALOS file and returns data. See add_datum methods."
135 if self.detailed_input:
136 self._read_observations(fname)
138 self._read_averages(fname)
144 if __name__ ==
'__main__':
147 sequence = read_sequence_file(
'seq.dat', sequence_match=(1, 5))
150 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 ...
def __init__
start the TALOSReader sequence : a dictionary of sequence number keys and 3-letter code values...
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...