4
4
from beams import __version__
5
5
import argparse
6
6
import sys
7
+ import os
7
8
import networkx as nx
8
9
from beams import in_out
9
10
from beams import grouping
10
11
from beams import annotation
12
+ from beams import plots
11
13
12
14
13
15
def map_delimiter (delimiter ):
@@ -28,8 +30,6 @@ def main():
28
30
subparsers = parser .add_subparsers (dest = 'step' )
29
31
30
32
31
- parser_fi = subparsers .add_parser ('format-inputs' , help = 'Convert and format input files.' )
32
-
33
33
parser_gf = subparsers .add_parser ('group-features' , help = 'Group features.' )
34
34
35
35
parser_app = subparsers .add_parser ('annotate-peak-patterns' , help = 'Annotate peak patterns, molecular formulae and metabolites.' )
@@ -42,22 +42,6 @@ def main():
42
42
43
43
parser_gui = subparsers .add_parser ('start-gui' , help = 'Start GUI.' )
44
44
45
- #################################
46
- # FORMAT INPUTS
47
- #################################
48
-
49
- parser_fi .add_argument ('-l' , '--peaklist' ,
50
- type = str , required = True , help = "Tab-delimited peaklist." )
51
-
52
- parser_fi .add_argument ('-m' , '--intensity-matrix' ,
53
- type = str , required = True , help = "Tab-delimited intensity matrix." )
54
-
55
- parser_fi .add_argument ('-o' , '--output' , type = str , required = True ,
56
- help = "Filename / Path to save the merged peaklist and intensity matrix." )
57
-
58
- parser_fi .add_argument ('-s' , '--sep' , default = "tab" , choices = ["tab" , "comma" ], required = True ,
59
- help = "Values on each line of the file are separated by this character." )
60
-
61
45
62
46
#################################
63
47
# GROUP FEATURES
@@ -67,7 +51,7 @@ def main():
67
51
type = str , required = True , help = "Tab-delimited peaklist." )
68
52
69
53
parser_gf .add_argument ('-i' , '--intensity-matrix' ,
70
- type = str , required = False , help = "Tab-delimited intensity matrix." )
54
+ type = str , required = True , help = "Tab-delimited intensity matrix." )
71
55
72
56
#parser_gf.add_argument('-x', '--xset-matrix',
73
57
# type=str, required=False, help="Tab-delimited intensity matrix")
@@ -113,18 +97,18 @@ def main():
113
97
help = "Annotate adducts." )
114
98
115
99
parser_app .add_argument ('-b' , '--adducts-library' , action = 'append' , required = False ,
116
- help = "List of adducts." )
100
+ default = [], help = "List of adducts." )
117
101
118
102
parser_app .add_argument ('-e' , '--isotopes' , action = 'store_true' , required = False ,
119
103
help = "Annotate isotopes." )
120
104
121
- parser_app .add_argument ('-f' , '--isotopes-library' , action = 'append' , required = False ,
105
+ parser_app .add_argument ('-f' , '--isotopes-library' , required = False ,
122
106
help = "List of isotopes." )
123
107
124
108
parser_app .add_argument ('-r' , '--multiple-charged-ions' , action = 'store_true' , required = False ,
125
109
help = "Annotate multiple-charged ions." )
126
110
127
- parser_app .add_argument ('-s' , '--multiple-charged-ions-library' , action = 'append' , required = False ,
111
+ parser_app .add_argument ('-s' , '--multiple-charged-ions-library' , required = False ,
128
112
help = "List of multiple charged ions." )
129
113
130
114
parser_app .add_argument ('-o' , '--oligomers' , action = 'store_true' , required = False ,
@@ -136,7 +120,10 @@ def main():
136
120
parser_app .add_argument ('-p' , '--ppm' , default = 3.0 , type = float , required = True ,
137
121
help = "Mass tolerance in parts per million." )
138
122
123
+ parser_app .add_argument ('-u' , '--max-monomer-units' , default = 2 , type = int , required = False ,
124
+ help = "Maximum number of monomer units." )
139
125
126
+
140
127
#################################
141
128
# ANNOTATE MOLECULAR FORMULAE
142
129
#################################
@@ -179,7 +166,7 @@ def main():
179
166
parser_am .add_argument ('-d' , '--db' , type = str , required = True ,
180
167
help = "Sqlite database to write results." )
181
168
182
- parser_am .add_argument ('-c' , '--db-compounds' , type = str , required = True , help = "Metabolite database (reference)." )
169
+ parser_am .add_argument ('-c' , '--db-compounds' , type = str , required = False , help = "Metabolite database (reference)." )
183
170
184
171
parser_am .add_argument ('-n' , '--db-name' , type = str , default = "" , required = False ,
185
172
help = "Name compound / metabolite database (within --db-compounds)." )
@@ -221,23 +208,18 @@ def main():
221
208
parser_sr .add_argument ('-c' , '--single-column' , action = "store_true" ,
222
209
help = "Concatenate the annotations for each spectral feature and keep seperate columns for molecular formula, adduct, name, etc." )
223
210
224
- parser_sr .add_argument ('-n' , '--ndigits-mz' , default = None , type = int , required = True ,
211
+ parser_sr .add_argument ('-n' , '--ndigits-mz' , default = None , type = int , required = False ,
225
212
help = "Digits after the decimal point for m/z values." )
226
213
227
- parser_sr .add_argument ('-t' , '--convert-rt' , default = None , choices = ["sec" , "min" , None ], required = True ,
228
- help = "Covert the retention time to seconds or minutes. An additional column will be added." )
214
+ parser_sr .add_argument ('-t' , '--convert-rt' , default = None , choices = ["sec" , "min" , None ],
215
+ required = False , help = "Covert the retention time to seconds or minutes. An additional column will be added." )
229
216
230
217
args = parser .parse_args ()
231
218
232
219
print (args )
233
220
234
221
separators = {"tab" : "\t " , "comma" : "," }
235
222
236
- if args .step == "format-inputs" :
237
-
238
- df = in_out .combine_peaklist_matrix (args .peaklist , args .intensity_matrix )
239
- df .to_csv (args .output , sep = separators [args .sep ], index = False )
240
-
241
223
if args .step == "group-features" :
242
224
df = in_out .combine_peaklist_matrix (args .peaklist , args .intensity_matrix )
243
225
graph = grouping .group_features (df , db_out = args .db , max_rt_diff = args .max_rt_diff ,
@@ -249,61 +231,93 @@ def main():
249
231
250
232
if args .gml_file :
251
233
inp = nx .read_gml (args .gml_file )
252
- else :
234
+ elif args . intensity_matrix :
253
235
inp = in_out .combine_peaklist_matrix (args .peaklist , args .intensity_matrix )
236
+ else :
237
+ inp = in_out .read_peaklist (args .peaklist )
254
238
255
239
if args .adducts :
256
- for i , a in enumerate (args .adducts_library ):
257
- try :
258
- lib = in_out .read_adducts (a , args .ion_mode )
259
- except :
260
- lib = in_out .read_mass_differences (a , args .ion_mode )
261
- if i > 0 :
262
- add = True
263
- else :
264
- add = False
265
- annotation .annotate_adducts (inp , db_out = args .db , ppm = args .ppm , lib = lib , add = add )
266
-
240
+ if len (args .adducts_library ) > 0 and args .adducts_library is not None :
241
+ for i , a in enumerate (args .adducts_library ):
242
+ try :
243
+ lib = in_out .read_adducts (a , args .ion_mode )
244
+ except :
245
+ lib = in_out .read_mass_differences (a , args .ion_mode )
246
+ if i > 0 :
247
+ add = True
248
+ else :
249
+ add = False
250
+ annotation .annotate_adducts (inp , db_out = args .db , ppm = args .ppm , lib = lib , add = add )
251
+ else :
252
+ path = 'data/adducts.txt'
253
+ p = os .path .join (os .path .dirname (os .path .abspath (__file__ )), path )
254
+ lib = in_out .read_adducts (p , args .ion_mode )
255
+ annotation .annotate_adducts (inp , db_out = args .db , ppm = args .ppm , lib = lib , add = False )
267
256
268
257
if args .isotopes :
269
- for i in args .isotopes_library :
270
- lib = in_out .read_isotopes (i , args .ion_mode )
258
+ if args .isotopes_library is not None :
259
+ lib = in_out .read_isotopes (args .isotopes_library , args .ion_mode )
260
+ annotation .annotate_isotopes (inp , db_out = args .db , ppm = args .ppm , lib = lib )
261
+ else :
262
+ path = 'data/isotopes.txt'
263
+ p = os .path .join (os .path .dirname (os .path .abspath (__file__ )), path )
264
+ lib = in_out .read_isotopes (p , args .ion_mode )
271
265
annotation .annotate_isotopes (inp , db_out = args .db , ppm = args .ppm , lib = lib )
272
266
273
267
if args .multiple_charged_ions :
274
- for i , m in enumerate (args .multiple_charged_ions_library ):
275
- try :
276
- lib = in_out .read_multiple_charged_ions (m , args .ion_mode )
277
- except :
278
- lib = in_out .read_mass_differences (m , args .ion_mode )
279
-
280
- if i > 0 :
281
- add = True
282
- else :
283
- add = False
284
-
285
- annotation .annotate_multiple_charged_ions (inp , db_out = args .db , ppm = args .ppm , lib = lib , add = add )
286
-
268
+ if len (args .multiple_charged_ions_library ) > 0 and args .multiple_charged_ions_library is not None :
269
+ for i , m in enumerate (args .multiple_charged_ions_library ):
270
+ try :
271
+ lib = in_out .read_multiple_charged_ions (m , args .ion_mode )
272
+ except :
273
+ lib = in_out .read_mass_differences (m , args .ion_mode )
274
+
275
+ if i > 0 :
276
+ add = True
277
+ else :
278
+ add = False
279
+
280
+ annotation .annotate_multiple_charged_ions (inp , db_out = args .db , ppm = args .ppm , lib = lib , add = add )
281
+ else :
282
+ path = 'data/multiple_charged_ions.txt'
283
+ p = os .path .join (os .path .dirname (os .path .abspath (__file__ )), path )
284
+ lib = in_out .read_multiple_charged_ions (p , args .ion_mode )
285
+
287
286
if args .oligomers :
288
287
annotation .annotate_oligomers (inp , db_out = args .db , ppm = args .ppm , lib = lib )
289
288
290
289
if args .step == "annotate-mf" :
291
- df = in_out .combine_peaklist_matrix (args .peaklist , args .intensity_matrix )
290
+
291
+ if args .intensity_matrix :
292
+ df = in_out .combine_peaklist_matrix (args .peaklist , args .intensity_matrix )
293
+ else :
294
+ df = in_out .read_peaklist (args .peaklist )
295
+
292
296
lib = in_out .read_adducts (args .adducts_library , args .ion_mode )
293
297
annotation .annotate_molecular_formulae (df , ppm = args .ppm , lib_adducts = lib , db_out = args .db , db_in = args .db_mf , max_mz = args .max_mz )
294
298
295
299
if args .step == "annotate-compounds" :
296
- df = in_out .combine_peaklist_matrix (args .peaklist , args .intensity_matrix )
300
+
301
+ if args .intensity_matrix :
302
+ df = in_out .combine_peaklist_matrix (args .peaklist , args .intensity_matrix )
303
+ else :
304
+ df = in_out .read_peaklist (args .peaklist )
305
+
297
306
lib = in_out .read_adducts (args .adducts_library , args .ion_mode )
298
- annotation .annotate_compounds (df , lib_adducts = lib , ppm = args .ppm , db_out = args .db , db_in = args .db_compounds , db_name = args . db_name )
307
+ annotation .annotate_compounds (df , lib_adducts = lib , ppm = args .ppm , db_out = args .db , db_name = args .db_name , db_in = "" )
299
308
300
309
if args .step == "summary-results" :
301
- df = in_out .combine_peaklist_matrix (args .peaklist , args .intensity_matrix )
310
+
311
+ if args .intensity_matrix :
312
+ df = in_out .combine_peaklist_matrix (args .peaklist , args .intensity_matrix )
313
+ else :
314
+ df = in_out .read_peaklist (args .peaklist )
315
+
302
316
df_out = annotation .summary (df , db = args .db , single_row = args .single_row , single_column = args .single_column , convert_rt = args .convert_rt , ndigits_mz = args .ndigits_mz )
303
317
df_out .to_csv (args .output , sep = separators [args .sep ], index = False , encoding = "utf-8" )
304
318
if args .pdf :
305
319
plots .report (db = args .db , pdf_out = args .pdf ,
306
- column_corr = "r_value" , column_pvalue = "pvalue " ,
320
+ column_corr = "r_value" , column_pvalue = "p_value " ,
307
321
column_ppm_error = "ppm_error" , column_adducts = "adduct" )
308
322
309
323
if args .step == "start-gui" :
0 commit comments