annotate append_fdr.py @ 0:ef7cc296f063 draft default tip

Initial commit.
author galaxyp
date Fri, 10 May 2013 16:42:08 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
1 #!/usr/bin/env python
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
2 import optparse
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
3 import sys
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
4
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
5 try:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
6 # Ubuntu deps: gfortan libblas-dev liblapack-dev
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
7 # pip deps: numpy scipy
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
8 from math import sqrt
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
9 from scipy.optimize import root
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
10 from numpy import arange, exp, concatenate, sum, log, array, seterr
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
11 except ImportError:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
12 # Allow this script to be used for global FDR even
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
13 # if these dependencies are not present.
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
14 pass
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
15
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
16
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
17 SEPARATORS = {"TAB": "\t",
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
18 "SPACE": " ",
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
19 "COMMA": ","
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
20 }
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
21
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
22
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
23 def __main__():
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
24 run_script()
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
25
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
26
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
27 def append_fdr(input_file, output, settings):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
28 sorted_scores, accum_hits, accum_decoys = _accum_decoys(input_file, settings)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
29 fdr_array = compute_fdr(sorted_scores, accum_hits, accum_decoys, settings)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
30 index = 0
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
31 for line in __read_lines(input_file):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
32 if not line or line.startswith('#'):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
33 continue
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
34 entry = Entry(line, settings, index)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
35 this_fdr = fdr_array[entry.score]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
36 new_line = "%s%s%f" % (line, settings["separator"], this_fdr)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
37 print >> output, new_line
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
38 index += 1
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
39
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
40
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
41 def compute_fdr(sorted_scores, accum_hits, accum_decoys, settings):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
42 fdr_type = settings["fdr_type"]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
43 compute_functions = {"global_conservative": _compute_fdr_global_conservative,
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
44 "global_permissive": _compute_fdr_global_permissive,
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
45 #"pspep": _compute_pspep
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
46 }
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
47 return compute_functions[fdr_type](sorted_scores, accum_hits, accum_decoys, settings)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
48 #return compute_functions[fdr_type](all_hits_array, decoy_hits_array, settings)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
49
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
50
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
51 def _compute_pspep(all_hits, decoy_hits, settings):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
52 scaling = _get_scaling(settings)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
53 seterr(all="ignore")
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
54 sigma = array([sqrt(x) if x > 0 else 0.2 for x in decoy_hits])
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
55 if isinstance(all_hits, list):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
56 all_hits = array(all_hits)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
57 if isinstance(decoy_hits, list):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
58 decoy_hits = array(decoy_hits)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
59 searchSeg = concatenate((exp(arange(-8, 9, 2)), -1 * exp(arange(-8, 9, 2))))
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
60 bestResids = sys.float_info.max
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
61 bestResidsComb = [0.0, 0.0, 0.0]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
62 for aEst in searchSeg:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
63 for bEst in searchSeg:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
64 for cEst in searchSeg:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
65 try:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
66 sol = _non_linear_fit(aEst, bEst, cEst, all_hits, decoy_hits, sigma)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
67 if sol[3] and sol[3] < bestResids:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
68 bestResids = sol[3]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
69 bestResidsComb = sol[0:3]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
70 except:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
71 pass
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
72 (a, b, c) = bestResidsComb[0:3]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
73 fdr_local = scaling * (exp(b * (all_hits - a)) / (exp(b * (all_hits - a)) + 1)) * c
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
74 return fdr_local
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
75
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
76
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
77 def _get_scaling(settings):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
78 scaling = float(settings.get("scaling", "2.0"))
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
79 return scaling
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
80
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
81
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
82 def _non_linear_fit(aEst, bEst, cEst, all_hits, decoy_hits, sigma, scaling=2):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
83 guess = [aEst, bEst, cEst]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
84
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
85 def f(a, b, c):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
86 return c * (log(exp(b * (all_hits - a)) + 1) - log(exp(-b * a) + 1)) / b
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
87
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
88 def fcn(p):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
89 a = p[0]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
90 b = p[1]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
91 c = p[2]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
92 return (decoy_hits - f(a, b, c)) / sigma
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
93
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
94 solution = root(fcn, guess, method='lm')
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
95 a = solution.x[0]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
96 b = solution.x[1]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
97 c = solution.x[2]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
98 resids = sum((decoy_hits - f(a, b, c)) ** 2) / len(all_hits)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
99 return (a, b, c, resids)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
100
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
101
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
102 def _compute_fdr_global_conservative(sorted_scores, accum_hits, accum_decoys, settings):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
103 raw_fdrs = build_raw_fdr_dict(sorted_scores, accum_hits, accum_decoys, settings)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
104 fdrs = {}
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
105 max_fdr = -1
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
106 for score in sorted_scores:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
107 raw_fdr = raw_fdrs[score]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
108 if raw_fdr > max_fdr:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
109 max_fdr = raw_fdr
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
110 fdrs[score] = max_fdr
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
111 return fdrs
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
112
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
113
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
114 def _compute_fdr_global_permissive(sorted_scores, accum_hits, accum_decoys, settings):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
115 raw_fdrs = build_raw_fdr_dict(sorted_scores, accum_hits, accum_decoys, settings)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
116 fdrs = {}
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
117 index = len(sorted_scores) - 1
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
118 min_fdr = 1
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
119 while index >= 0:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
120 score = sorted_scores[index]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
121 raw_fdr = raw_fdrs[score]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
122 if raw_fdr < min_fdr:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
123 min_fdr = raw_fdr
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
124 fdrs[score] = min_fdr
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
125 index -= 1
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
126 return fdrs
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
127
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
128
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
129 def build_raw_fdr_dict(sorted_scores, accum_hits, accum_decoys, settings):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
130 scaling = _get_scaling(settings)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
131 fdrs = {}
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
132 for score in sorted_scores:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
133 fdrs[score] = (scaling * accum_decoys[score]) / accum_hits[score]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
134 return fdrs
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
135
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
136
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
137 def __read_lines(input_file):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
138 with open(input_file, 'r') as input:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
139 for i, line in enumerate(input):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
140 line = line.rstrip('\r\n')
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
141 yield line
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
142
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
143
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
144 def __read_entries(input_file, settings):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
145 total_hits = 0
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
146 for line in __read_lines(input_file):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
147 if not line or line.startswith('#'):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
148 continue
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
149 entry = Entry(line, settings, total_hits)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
150 total_hits = total_hits + 1
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
151 yield entry
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
152
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
153
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
154 class Entry(object):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
155
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
156 def __init__(self, line, settings, index):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
157 self.settings = settings
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
158 line_parts = line.split(settings["separator"])
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
159 self.identifier = line_parts[settings["identifiers_index"]]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
160 if settings["score_column"]:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
161 self.score = float(line_parts[settings["score_column"]])
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
162 else:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
163 self.score = index
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
164
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
165 @property
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
166 def is_decoy(self):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
167 return self.identifier.startswith(self.settings["decoy_prefix"])
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
168
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
169
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
170 def _accum_decoys(input_file, settings):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
171 hits_at_score = {}
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
172 decoys_at_score = {}
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
173 for entry in __read_entries(input_file, settings):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
174 score = entry.score
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
175 score_total = hits_at_score.get(score, 0) + 1
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
176 score_decoys = decoys_at_score.get(score, 0) + (1 if entry.is_decoy else 0)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
177 hits_at_score[score] = score_total
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
178 decoys_at_score[score] = score_decoys
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
179 sorted_scores = sorted(hits_at_score, reverse=not settings["invert_score"])
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
180 accum_hits = {}
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
181 accum_decoys = {}
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
182 accum_hit_count = 0
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
183 accum_decoy_count = 0
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
184 for score in sorted_scores:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
185 accum_decoy_count += decoys_at_score[score]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
186 accum_hit_count += hits_at_score[score]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
187 accum_hits[score] = accum_hit_count
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
188 accum_decoys[score] = accum_decoy_count
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
189 return (sorted_scores, accum_hits, accum_decoys)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
190
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
191
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
192 def _build_arrays(input_file, settings, sorted_scores, accum_hits, accum_decoys):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
193 all_hits = []
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
194 decoy_hits = []
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
195 for entry in __read_entries(input_file, settings):
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
196 score = entry.score
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
197 all_hits.append(accum_hits[score])
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
198 decoy_hits.append(accum_decoys[score])
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
199
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
200 return (all_hits, decoy_hits)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
201
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
202
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
203 def run_script():
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
204 parser = optparse.OptionParser()
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
205 parser.add_option("--input")
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
206 parser.add_option("--output")
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
207 parser.add_option("--decoy_prefix")
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
208 parser.add_option("--identifiers_column")
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
209 parser.add_option("--separator", default="TAB")
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
210 parser.add_option("--fdr_type", default="global_conservative")
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
211 parser.add_option("--scaling")
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
212 parser.add_option("--score_column", default=None)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
213 # By default higher score is better.
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
214 parser.add_option("--invert_score", default=False, action="store_true")
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
215
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
216 (options, args) = parser.parse_args()
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
217 decoy_prefix = options.decoy_prefix
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
218 identifiers_column = options.identifiers_column
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
219 score_column = options.score_column
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
220 separator = SEPARATORS[options.separator]
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
221 settings = {"decoy_prefix": decoy_prefix,
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
222 "identifiers_index": int(identifiers_column) - 1,
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
223 "fdr_type": options.fdr_type,
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
224 "separator": separator,
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
225 "scaling": options.scaling,
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
226 "invert_score": options.invert_score
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
227 }
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
228 if score_column:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
229 settings["score_column"] = int(score_column) - 1
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
230 else:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
231 settings["score_column"] = None
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
232 # Assume data is descending, use index as score and invert.
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
233 settings["invert_score"] = True
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
234 with open(options.output, 'w') as output:
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
235 append_fdr(options.input, output, settings)
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
236
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
237
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
238 if __name__ == '__main__':
ef7cc296f063 Initial commit.
galaxyp
parents:
diff changeset
239 __main__()