-
Notifications
You must be signed in to change notification settings - Fork 0
/
mzmine2ionlist.py
45 lines (35 loc) · 1.24 KB
/
mzmine2ionlist.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
import pandas as pd
import argparse
def gen_nominal_decimal(mz):
nominal = int(mz)
decimal = mz-nominal
return nominal, decimal
def parse_arguments():
"""
Parse command-line arguments using argparse.
"""
parser = argparse.ArgumentParser(description="Convert MZmine output quant table to ion list for NegMDF.")
# 输入文件参数
parser.add_argument(
"-i", "--input",
type=str,
required=True,
help="Path to the input quant table (CSV format) generated by MZmine."
)
# 输出文件参数
parser.add_argument(
"-o", "--output",
type=str,
required=True,
help="Path to save the output ion list (CSV format)."
)
return parser.parse_args()
if __name__ == '__main__':
args = parse_arguments()
mzmine_df = pd.read_csv(args.input)
mzmine_df_target_col = ["row ID","row retention time", "row m/z"]
ion_list_df = pd.DataFrame()
ion_list_df[["id", "rt", "mz"]] = mzmine_df[mzmine_df_target_col]
ion_list_df[["integer", "decimal"]] = ion_list_df["mz"].apply(gen_nominal_decimal).apply(pd.Series)
ion_list_df["integer"] = ion_list_df["integer"].astype(int)
ion_list_df.to_csv(args.output, index=False)