1414from pytmt .get_spec import Mzml
1515from pytmt import tmt_reporters
1616from pytmt import quantify_spec
17+ from pytmt import correct_matrix
1718
1819def quant (args ):
1920 """
@@ -162,7 +163,7 @@ def quant(args):
162163 idx , pathname = pattern [0 ]
163164 dirname , filename = os .path .split (pathname )
164165 mzml_files [int (idx )] = re .sub ('\.pep\.xml' , '' , filename )
165- #TODO: will probably have to account for .pin or other input to Percolator
166+ # TODO: will probably have to account for .pin or other input to Percolator
166167
167168 # If the log file does not exist, assign index naively based on sort
168169 else :
@@ -279,10 +280,18 @@ def quant(args):
279280 for reporter in reporters :
280281 output_df_columns .append ('m' + str (reporter ))
281282
282- output_df_columns .append ('spectrum_int' )
283283
284+
285+ output_df_columns .append ('spectrum_int' )
284286 output_df = pd .DataFrame (output_list , columns = output_df_columns )
285287
288+ # Correct for contamination
289+ if args .contam is not None :
290+ output_df = correct_matrix .correct_matrix (output_df = output_df ,
291+ contam = args .contam ,
292+ nnls = args .nnls ,
293+ )
294+
286295 # Final output, merging the input and output tables
287296 final_df = pd .merge (id_df , output_df , how = 'left' )
288297
@@ -306,13 +315,22 @@ def main():
306315 import argparse
307316
308317 parser = argparse .ArgumentParser (description = 'pytmt returns ms2 tmt quantification values'
309- 'from Percolator (Crux or Standalone) output' )
318+ 'from Percolator output and perform contamination'
319+ 'correction' )
310320
311- parser .add_argument ('mzml' , help = 'path to folder containing mzml files' )
321+ parser .add_argument ('mzml' ,
322+ help = 'path to folder containing mzml files' ,
323+ )
312324
313- parser .add_argument ('id' , help = 'path to percolator target psms output file' )
325+ parser .add_argument ('id' ,
326+ help = 'path to percolator target psms output file' ,
327+ )
314328
315- parser .add_argument ('-u' , '--unique' , action = 'store_true' , help = 'quantify unique peptides only' )
329+ parser .add_argument ('-u' ,
330+ '--unique' ,
331+ action = 'store_true' ,
332+ help = 'quantify unique peptides only' ,
333+ )
316334
317335 parser .add_argument ('-q' , '--qvalue' ,
318336 help = 'quantify peptides with q value below this threshold [default: 1.0]' ,
@@ -332,10 +350,21 @@ def main():
332350 parser .add_argument ('-o' , '--out' , help = 'name of the output directory [default: tmt_out]' ,
333351 default = 'tmt_out' )
334352
335-
336353 parser .add_argument ('-v' , '--version' , action = 'version' ,
337354 version = '%(prog)s {version}' .format (version = __version__ ))
338355
356+ parser .add_argument ('-c' , '--contam' ,
357+ help = 'Path to contaminant matrix csv file.'
358+ ' Leave blank to get tmt output without correction' ,
359+ metavar = 'CONTAM' ,
360+ type = argparse .FileType ('r' ),
361+ )
362+
363+ parser .add_argument ('-n' , '--nnls' ,
364+ action = 'store_true' ,
365+ help = 'uses non-negative least square for contamination correction' ,
366+ )
367+
339368 parser .set_defaults (func = quant )
340369
341370
0 commit comments