3 """@namespace IMP.isd.TALOSReader
4 Classes to handle TALOS files or folders.
14 """ reads a TALOS file, or a TALOS folder, and stores the data """
16 def __init__(self, sequence, detailed_input, keep_all=False,
17 sequence_match=(1, 1)):
18 """start the TALOSReader
19 sequence : a dictionary of sequence number keys and 3-letter code
21 detailed_input : True if the input will be either predAll.tab or the
22 pred/res???.tab files. False if it's pred.tab
23 keep_all : whether to keep outliers or not, when detailed_input==True.
24 sequence_match : in the form (talos_no, sequence_no), assigns a
25 correspondence between residue numberings.
27 self.detailed_input = detailed_input
29 self.keep_all = keep_all
30 self.sequence = sequence
31 self.offset = sequence_match[1] - sequence_match[0]
34 """in the case of a list of predictions for one residue, add an entry
37 'num' : number of predictions
38 'phi' : the list of predictions for phi
42 if resno
not in self.data:
44 'full':
True,
'num': len(phi),
'phi': phi,
'psi': psi}
46 raise RuntimeError(
"would overwrite data for residue %d" % resno)
49 """in the case of a single (average) prediction output by talos for a
50 given residue, add an entry to data which is:
52 'num' : the number of matches this average was calculated from
53 'phi' : a tuple in the form (mean, error)
58 if resno
not in self.data:
66 raise RuntimeError(
"would overwrite data for residue %d" % resno)
68 def _read_one_residue(self, fname):
70 resno = int(os.path.basename(fname)[3:6]) + self.offset
77 if tokens[1] ==
'RESNAMES':
78 check_residue(self.sequence[resno], tokens[3])
80 if not tokens[0].isdigit():
82 if float(tokens[4]) < 0.999
and not self.keep_all:
84 phi.append(float(tokens[1]) * 2 * pi / 360.)
85 psi.append(float(tokens[2]) * 2 * pi / 360.)
88 def _read_predAll(self, fname):
95 if len(tokens) == 0
or not tokens[0].isdigit():
98 resno = int(tokens[1]) + self.offset
104 resname = tokens[2][1]
105 check_residue(self.sequence[resno], resname)
106 if float(tokens[6]) < 0.999
and not self.keep_all:
108 phi.append(float(tokens[3]) * 2 * pi / 360.)
109 psi.append(float(tokens[4]) * 2 * pi / 360.)
111 def _read_observations(self, fname):
112 if fname.endswith(
'predAll.tab'):
113 self._read_predAll(fname)
115 self._read_one_residue(fname)
117 def _read_averages(self, fname):
120 tokens = line.split()
121 if not tokens[0].isdigit():
123 resno = int(tokens[0]) + self.offset
124 check_residue(resno, tokens[1])
125 phi, psi, dphi, dpsi = [2 * pi * float(a) / 360.
126 for a
in tokens[2:6]]
133 "reads a TALOS file and returns data. See add_datum methods."
134 if self.detailed_input:
135 self._read_observations(fname)
137 self._read_averages(fname)
143 if __name__ ==
'__main__':
146 sequence = read_sequence_file(
'seq.dat', sequence_match=(1, 5))
149 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...