-
Notifications
You must be signed in to change notification settings - Fork 0
/
mass_aligner_ppm_estimator.py
65 lines (47 loc) · 1.67 KB
/
mass_aligner_ppm_estimator.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import argparse
import os
import numpy as np
from matplotlib import pyplot as plt
from src.senpy.ms2.parser import read_file as read_ms2
from src.senpy.sqt.parser import read_file as read_sqt
def parse_args():
# Parse Arguments
parser = argparse.ArgumentParser(description='TODO')
parser.add_argument('sqt_file', type=input_file_path, help='absolute path to sqt file')
args = parser.parse_args()
return args
def input_file_path(path):
if os.path.exists(path):
return path
else:
raise argparse.ArgumentTypeError(f"{path} is not a valid path")
def dta_select(dta_select_filter_file):
ppms = []
h_lines, locus_lines, end_lines = parse_dta_filter_file(dta_select_filter_file)
for locus_line in locus_lines:
for unique_line in locus_line.peptide_lines:
ppms.append(unique_line.ppm)
plt.hist(ppms)
plt.show()
print(np.mean(ppms))
def sqt_select(sqt_file):
xcorrs = []
h_lines, s_lines = read_sqt_file(sqt_file)
for s_line in s_lines:
for m_line in s_line.m_lines:
if not m_line.is_reverse():
xcorrs.append(m_line.xcorr)
percentile_xcorr = np.percentile(xcorrs, 95)
ppms = []
for s_line in s_lines:
for m_line in s_line.m_lines:
if not m_line.is_reverse() and m_line.xcorr >= percentile_xcorr:
ppms.append((m_line.calculated_mass - s_line.experimental_mass)/m_line.calculated_mass*1_000_000)
plt.hist(ppms, bins = 50)
plt.show()
print(np.mean(ppms))
if __name__ == '__main__':
args = parse_args()
for arg in vars(args):
print(arg, getattr(args, arg))
sqt_select(sqt_file = args.sqt_file)