Mercurial > repos > computational-metabolomics > sirius_csifingerid
annotate sirius_csifingerid.py @ 9:8dac4cef0a22 draft default tip
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
author | computational-metabolomics |
---|---|
date | Wed, 16 Feb 2022 16:11:55 +0000 |
parents | e29e64ff50bb |
children |
rev | line source |
---|---|
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
1 import argparse |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
2 import csv |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
3 import glob |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
4 import multiprocessing |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
5 import os |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
6 import re |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
7 import sys |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
8 import tempfile |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
9 import uuid |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
10 from collections import defaultdict |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
11 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
12 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
13 parser = argparse.ArgumentParser() |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
14 parser.add_argument('--input_pth') |
3
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
15 parser.add_argument('--canopus_result_pth') |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
16 parser.add_argument('--annotations_result_pth') |
9
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
17 parser.add_argument('--all_structures_result_pth') |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
18 parser.add_argument('--database') |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
19 parser.add_argument('--profile') |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
20 parser.add_argument('--candidates') |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
21 parser.add_argument('--ppm_max') |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
22 parser.add_argument('--polarity') |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
23 parser.add_argument('--results_name') |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
24 parser.add_argument('--out_dir') |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
25 parser.add_argument('--tool_directory') |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
26 parser.add_argument('--temp_dir') |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
27 parser.add_argument('--meta_select_col', default='all') |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
28 parser.add_argument('--cores_top_level', default=1) |
9
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
29 parser.add_argument('--cores_sirius', default=4) |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
30 parser.add_argument('--chunks', default=1) |
3
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
31 parser.add_argument('--min_MSMS_peaks', default=1) |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
32 parser.add_argument('--schema', default='msp') |
2
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
33 parser.add_argument('-a', '--adducts', action='append', nargs=1, |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
34 required=False, default=[], help='Adducts used') |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
35 |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
36 args = parser.parse_args() |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
37 print(args) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
38 if os.stat(args.input_pth).st_size == 0: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
39 print('Input file empty') |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
40 exit() |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
41 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
42 if args.temp_dir: |
6
96b077221201
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit a1dfcf9fe850298b80f3738611835a3ef53e820a"
computational-metabolomics
parents:
4
diff
changeset
|
43 wd = os.path.join(args.temp_dir, 'temp_'+str(uuid.uuid4())) |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
44 os.mkdir(wd) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
45 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
46 if not os.path.exists(wd): |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
47 os.mkdir(wd) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
48 else: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
49 td = tempfile.mkdtemp() |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
50 wd = os.path.join(td, str(uuid.uuid4())) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
51 os.mkdir(wd) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
52 |
2
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
53 print(args.adducts) |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
54 if args.adducts: |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
55 adducts_from_cli = [ |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
56 a[0].replace('__ob__', '[').replace('__cb__', ']') for a in |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
57 args.adducts |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
58 ] |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
59 else: |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
60 adducts_from_cli = [] |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
61 |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
62 ###################################################################### |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
63 # Setup regular expressions for MSP parsing dictionary |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
64 ###################################################################### |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
65 regex_msp = {} |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
66 regex_msp['name'] = [r'^Name(?:=|:)(.*)$'] |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
67 regex_msp['polarity'] = [r'^ion.*mode(?:=|:)(.*)$', |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
68 r'^ionization.*mode(?:=|:)(.*)$', |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
69 r'^polarity(?:=|:)(.*)$'] |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
70 regex_msp['precursor_mz'] = [r'^precursor.*m/z(?:=|:)\s*(\d*[.,]?\d*)$', |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
71 r'^precursor.*mz(?:=|:)\s*(\d*[.,]?\d*)$'] |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
72 regex_msp['precursor_type'] = [r'^precursor.*type(?:=|:)(.*)$', |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
73 r'^adduct(?:=|:)(.*)$', |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
74 r'^ADDUCTIONNAME(?:=|:)(.*)$'] |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
75 regex_msp['num_peaks'] = [r'^Num.*Peaks(?:=|:)\s*(\d*)$'] |
2
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
76 regex_msp['retention_time'] = [r'^RETENTION.*TIME(?:=|:)\s*(.*)$', |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
77 r'^rt(?:=|:)\s*(.*)$', |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
78 r'^time(?:=|:)\s*(.*)$'] |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
79 # From example winter_pos.mspy from kristian |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
80 regex_msp['AlignmentID'] = [r'^AlignmentID(?:=|:)\s*(.*)$'] |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
81 |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
82 regex_msp['msp'] = [r'^Name(?:=|:)(.*)$'] # Flag for standard MSP format |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
83 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
84 regex_massbank = {} |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
85 regex_massbank['name'] = [r'^RECORD_TITLE:(.*)$'] |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
86 regex_massbank['polarity'] = \ |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
87 [r'^AC\$MASS_SPECTROMETRY:\s+ION_MODE\s+(.*)$'] |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
88 regex_massbank['precursor_mz'] = \ |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
89 [r'^MS\$FOCUSED_ION:\s+PRECURSOR_M/Z\s+(\d*[.,]?\d*)$'] |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
90 regex_massbank['precursor_type'] = \ |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
91 [r'^MS\$FOCUSED_ION:\s+PRECURSOR_TYPE\s+(.*)$'] |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
92 regex_massbank['num_peaks'] = [r'^PK\$NUM_PEAK:\s+(\d*)'] |
2
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
93 regex_massbank['retention_time'] = [ |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
94 r'^AC\$CHROMATOGRAPHY:\s+RETENTION_TIME\s*(\d*\.?\d+).*'] |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
95 regex_massbank['cols'] = [r'^PK\$PEAK:\s+(.*)'] |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
96 regex_massbank['massbank'] = [r'^RECORD_TITLE:(.*)$'] # Flag for massbank |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
97 |
2
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
98 |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
99 if args.schema == 'msp': |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
100 meta_regex = regex_msp |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
101 elif args.schema == 'massbank': |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
102 meta_regex = regex_massbank |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
103 elif args.schema == 'auto': |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
104 # If auto we just check for all the available paramter names |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
105 # and then determine if Massbank or MSP based on |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
106 # the name parameter |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
107 meta_regex = {} |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
108 meta_regex.update(regex_massbank) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
109 meta_regex['name'].extend(regex_msp['name']) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
110 meta_regex['polarity'].extend(regex_msp['polarity']) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
111 meta_regex['precursor_mz'].extend(regex_msp['precursor_mz']) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
112 meta_regex['precursor_type'].extend(regex_msp['precursor_type']) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
113 meta_regex['num_peaks'].extend(regex_msp['num_peaks']) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
114 meta_regex['msp'] = regex_msp['msp'] |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
115 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
116 print(meta_regex) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
117 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
118 # this dictionary will store the meta data results form the MSp file |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
119 meta_info = {} |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
120 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
121 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
122 # function to extract the meta data using the regular expressions |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
123 def parse_meta(meta_regex, meta_info=None): |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
124 if meta_info is None: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
125 meta_info = {} |
3
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
126 for k, regexes in meta_regex.items(): |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
127 for reg in regexes: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
128 m = re.search(reg, line, re.IGNORECASE) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
129 if m: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
130 meta_info[k] = '-'.join(m.groups()).strip() |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
131 return meta_info |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
132 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
133 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
134 ###################################################################### |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
135 # Setup parameter dictionary |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
136 ###################################################################### |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
137 def init_paramd(args): |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
138 paramd = defaultdict() |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
139 paramd["cli"] = {} |
9
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
140 paramd["cli"]["--cores"] = args.cores_sirius |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
141 paramd["cli"]["--database"] = args.database |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
142 paramd["cli"]["--profile"] = args.profile |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
143 paramd["cli"]["--candidates"] = args.candidates |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
144 paramd["cli"]["--ppm-max"] = args.ppm_max |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
145 if args.polarity == 'positive': |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
146 paramd["default_ion"] = "[M+H]+" |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
147 elif args.polarity == 'negative': |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
148 paramd["default_ion"] = "[M-H]-" |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
149 else: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
150 paramd["default_ion"] = '' |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
151 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
152 return paramd |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
153 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
154 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
155 ###################################################################### |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
156 # Function to run sirius when all meta and spectra is obtained |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
157 ###################################################################### |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
158 def run_sirius(meta_info, peaklist, args, wd, spectrac): |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
159 # Get sample details (if possible to extract) e.g. if created as part of |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
160 # the msPurity pipeline) choose between getting additional details to |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
161 # add as columns as either all meta data from msp, just details from the |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
162 # record name (i.e. when using msPurity and we have the columns |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
163 # coded into the name) or just the spectra index (spectrac) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
164 paramd = init_paramd(args) |
2
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
165 meta_info = {k: v for k, v in meta_info.items() if k |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
166 not in ['msp', 'massbank', 'cols']} |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
167 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
168 if args.meta_select_col == 'name': |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
169 # have additional column of just the name |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
170 paramd['additional_details'] = {'name': meta_info['name']} |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
171 elif args.meta_select_col == 'name_split': |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
172 # have additional columns split by "|" and |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
173 # then on ":" e.g. MZ:100.2 | RT:20 | xcms_grp_id:1 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
174 paramd['additional_details'] = { |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
175 sm.split(":")[0].strip(): sm.split(":")[1].strip() for sm in |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
176 meta_info['name'].split("|")} |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
177 elif args.meta_select_col == 'all': |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
178 # have additional columns based on all |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
179 # the meta information extracted from the MSP |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
180 paramd['additional_details'] = meta_info |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
181 else: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
182 # Just have and index of the spectra in the MSP file |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
183 paramd['additional_details'] = {'spectra_idx': spectrac} |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
184 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
185 paramd["SampleName"] = "{}_sirius_result".format(spectrac) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
186 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
187 paramd["cli"]["--output"] = \ |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
188 os.path.join(wd, "{}_sirius_result".format(spectrac)) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
189 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
190 # =============== Output peaks to txt file ============================== |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
191 paramd["cli"]["--ms2"] = os.path.join(wd, |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
192 "{}_tmpspec.txt".format(spectrac)) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
193 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
194 # write spec file |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
195 with open(paramd["cli"]["--ms2"], 'w') as outfile: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
196 for p in peaklist: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
197 outfile.write(p[0] + "\t" + p[1] + "\n") |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
198 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
199 # =============== Update param based on MSP metadata ====================== |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
200 # Replace param details with details from MSP if required |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
201 if 'precursor_type' in meta_info and meta_info['precursor_type']: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
202 paramd["cli"]["--ion"] = meta_info['precursor_type'] |
2
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
203 adduct = meta_info['precursor_type'] |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
204 else: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
205 if paramd["default_ion"]: |
3
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
206 paramd["cli"]["--adduct"] = paramd["default_ion"] |
2
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
207 adduct = paramd["default_ion"] |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
208 else: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
209 paramd["cli"]["--auto-charge"] = '' |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
210 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
211 if 'precursor_mz' in meta_info and meta_info['precursor_mz']: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
212 paramd["cli"]["--precursor"] = meta_info['precursor_mz'] |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
213 |
2
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
214 if not ('precursor_type' in paramd['additional_details'] or 'adduct' |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
215 in paramd['additional_details']): |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
216 # If possible always good to have the adduct in output as a column |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
217 paramd['additional_details']['adduct'] = adduct |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
218 |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
219 # ============== Create CLI cmd for metfrag =============================== |
9
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
220 cmd = "sirius --cores {} --no-citations --ms2 {} --adduct {} " \ |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
221 "--precursor {} -o {} " \ |
3
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
222 "formula -c {} --ppm-max {} --profile {} " \ |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
223 "structure --database {} canopus".format( |
9
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
224 paramd["cli"]["--cores"], |
3
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
225 paramd["cli"]["--ms2"], |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
226 adduct, |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
227 paramd["cli"]["--precursor"], |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
228 paramd["cli"]["--output"], |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
229 paramd["cli"]["--candidates"], |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
230 paramd["cli"]["--ppm-max"], |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
231 paramd["cli"]["--profile"], |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
232 paramd["cli"]["--database"] |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
233 ) |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
234 print(cmd) |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
235 paramds[paramd["SampleName"]] = paramd |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
236 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
237 # =============== Run srius ============================================== |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
238 # Filter before process with a minimum number of MS/MS peaks |
3
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
239 if plinesread >= float(args.min_MSMS_peaks): |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
240 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
241 if int(args.cores_top_level) == 1: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
242 os.system(cmd) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
243 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
244 return paramd, cmd |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
245 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
246 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
247 def work(cmds): |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
248 return [os.system(cmd) for cmd in cmds] |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
249 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
250 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
251 ###################################################################### |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
252 # Parse MSP file and run SIRIUS CLI |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
253 ###################################################################### |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
254 # keep list of commands if performing in CLI in parallel |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
255 cmds = [] |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
256 # keep a dictionary of all params |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
257 paramds = {} |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
258 # keep count of spectra (for uid) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
259 spectrac = 0 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
260 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
261 with open(args.input_pth, "r") as infile: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
262 # number of lines for the peaks |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
263 pnumlines = 0 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
264 # number of lines read for the peaks |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
265 plinesread = 0 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
266 for line in infile: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
267 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
268 line = line.strip() |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
269 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
270 if pnumlines == 0: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
271 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
272 # ============== Extract metadata from MSP ======================== |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
273 meta_info = parse_meta(meta_regex, meta_info) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
274 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
275 if ('massbank' in meta_info and 'cols' in meta_info) or \ |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
276 ('msp' in meta_info and 'num_peaks' in meta_info): |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
277 pnumlines = int(meta_info['num_peaks']) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
278 peaklist = [] |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
279 plinesread = 0 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
280 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
281 elif plinesread < pnumlines: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
282 # =============== Extract peaks from MSP ========================== |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
283 # .split() will split on any empty space (i.e. tab and space) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
284 line = tuple(line.split()) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
285 # Keep only m/z and intensity, not relative intensity |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
286 save_line = tuple(line[0].split() + line[1].split()) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
287 plinesread += 1 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
288 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
289 peaklist.append(save_line) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
290 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
291 elif plinesread and plinesread == pnumlines: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
292 # ======= Get sample name and additional details for output ======= |
2
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
293 if adducts_from_cli: |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
294 for adduct in adducts_from_cli: |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
295 print(adduct) |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
296 spectrac += 1 |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
297 meta_info['precursor_type'] = adduct |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
298 paramd, cmd = run_sirius(meta_info, peaklist, args, wd, |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
299 spectrac) |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
300 |
2
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
301 paramds[paramd["SampleName"]] = paramd |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
302 cmds.append(cmd) |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
303 else: |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
304 spectrac += 1 |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
305 paramd, cmd = run_sirius(meta_info, peaklist, args, wd, |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
306 spectrac) |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
307 |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
308 paramds[paramd["SampleName"]] = paramd |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
309 cmds.append(cmd) |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
310 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
311 meta_info = {} |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
312 pnumlines = 0 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
313 plinesread = 0 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
314 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
315 # end of file. Check if there is a MSP spectra to |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
316 # run metfrag on still |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
317 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
318 if plinesread and plinesread == pnumlines: |
2
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
319 if adducts_from_cli: |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
320 for adduct in adducts_from_cli: |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
321 print(adduct) |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
322 spectrac += 1 |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
323 meta_info['precursor_type'] = adduct |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
324 paramd, cmd = run_sirius(meta_info, peaklist, args, wd, |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
325 spectrac) |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
326 |
2
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
327 paramds[paramd["SampleName"]] = paramd |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
328 cmds.append(cmd) |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
329 else: |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
330 spectrac += 1 |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
331 paramd, cmd = run_sirius(meta_info, peaklist, args, wd, |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
332 spectrac) |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
333 |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
334 paramds[paramd["SampleName"]] = paramd |
856b3761277d
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 3e3dee9a853b6133cf089b3c063f53c52b39463d"
computational-metabolomics
parents:
0
diff
changeset
|
335 cmds.append(cmd) |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
336 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
337 # Perform multiprocessing on command line call level |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
338 if int(args.cores_top_level) > 1: |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
339 cmds_chunks = [cmds[x:x + int(args.chunks)] |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
340 for x in list(range(0, len(cmds), int(args.chunks)))] |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
341 pool = multiprocessing.Pool(processes=int(args.cores_top_level)) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
342 pool.map(work, cmds_chunks) |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
343 pool.close() |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
344 pool.join() |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
345 |
3
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
346 |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
347 ###################################################################### |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
348 # Concatenate and filter the output |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
349 ###################################################################### |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
350 # outputs might have different headers. Need to get a list of all the headers |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
351 # before we start merging the files outfiles = [os.path.join(wd, f) for f in |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
352 # glob.glob(os.path.join(wd, "*_metfrag_result.csv"))] |
9
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
353 def concat_output(wd, filename, result_pth, level=2): |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
354 |
9
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
355 if level == 2: |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
356 outfiles = glob.glob(os.path.join(wd, '*', filename)) |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
357 else: |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
358 outfiles = glob.glob(os.path.join(wd, '*', '*', filename)) |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
359 |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
360 outfiles.sort( |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
361 key=lambda s: int( |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
362 re.match(r'.*/([0-9]+).*/{}$'.format(filename), |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
363 s).group(1))) |
3
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
364 print(outfiles) |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
365 if len(outfiles) == 0: |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
366 print('No results') |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
367 sys.exit() |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
368 |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
369 headers = [] |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
370 |
3
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
371 for fn in outfiles: |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
372 with open(fn, 'r') as infile: |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
373 reader = csv.reader(infile, delimiter='\t') |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
374 if sys.version_info >= (3, 0): |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
375 headers.extend(next(reader)) |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
376 else: |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
377 headers.extend(reader.next()) |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
378 break |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
379 |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
380 headers = list(paramd['additional_details'].keys()) + headers |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
381 |
3
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
382 with open(result_pth, 'a') as merged_outfile: |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
383 dwriter = csv.DictWriter(merged_outfile, |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
384 fieldnames=headers, delimiter='\t') |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
385 dwriter.writeheader() |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
386 |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
387 for fn in sorted(outfiles): |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
388 print(fn) |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
389 |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
390 with open(fn) as infile: |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
391 reader = csv.DictReader(infile, delimiter='\t') |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
392 |
9
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
393 ad = paramds[fn.split(os.sep)[-level]]['additional_details'] |
3
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
394 |
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
395 for line in reader: |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
396 |
3
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
397 line.update(ad) |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
398 |
3
4cbfd3d0a4c4
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit e4bc02f97a21da7556d1b76e5338ede3a9031fac"
computational-metabolomics
parents:
2
diff
changeset
|
399 dwriter.writerow(line) |
0
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
400 |
9e6bf7278257
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit 1d1b37a070f895c94069819237199c768da27258"
computational-metabolomics
parents:
diff
changeset
|
401 |
9
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
402 concat_output(wd, |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
403 'compound_identifications.tsv', |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
404 args.annotations_result_pth) |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
405 |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
406 concat_output(wd, |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
407 'canopus_summary.tsv', |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
408 args.canopus_result_pth) |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
409 |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
410 concat_output(wd, |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
411 'structure_candidates.tsv', |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
412 args.all_structures_result_pth, |
8dac4cef0a22
"planemo upload for repository https://github.com/computational-metabolomics/sirius_csifingerid_galaxy commit c2fc3de462ef4bd1a225c41624b094c3b5874736"
computational-metabolomics
parents:
7
diff
changeset
|
413 level=3) |