-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_scan_number_to_precursor_id.py
40 lines (29 loc) · 1.11 KB
/
map_scan_number_to_precursor_id.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import argparse
import os
from ms2.fast_parser import read_file
def parse_args():
# Parse Arguments
_parser = argparse.ArgumentParser(description='Arguments for Ms2 Extractor')
_parser.add_argument('--ms2', required=True, type=str,
help='path to ms2 file')
_parser.add_argument('--out', required=False, type=str,
help='output file')
return _parser.parse_args()
def main(ms2_path, out_path):
ms2_file_name = os.path.basename(ms2_path).split(".ms2")[0]
print("ms2_file_name: " + ms2_file_name)
lines = []
_, ms2_spectras = read_file(ms2_path)
for ms2_spectra in ms2_spectras:
ms2_scan_number = int(ms2_spectra.s_line.get_low_scan())
precursor_id = int(ms2_spectra.get_precursor_id())
line = '\t'.join([str(ms2_scan_number), str(precursor_id)]) + '\n'
lines.append(line)
with open(out_path, "w") as file:
file.write(''.join(lines))
if __name__ == '__main__':
args = parse_args()
if args.out is None:
args.out = args.ms2 + ".sn2p"
print(args)
main(args.ms2, args.out)