robert05 commited on
Commit
268ed8c
·
verified ·
1 Parent(s): da9b612

Upload folder using huggingface_hub

Browse files
.DS_Store CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
 
.gitattributes CHANGED
@@ -89,3 +89,11 @@ drosophila_consensus_final_true_lib.mgf filter=lfs diff=lfs merge=lfs -text
89
  drosophila_consensus_final_true_lib.msp filter=lfs diff=lfs merge=lfs -text
90
  e_coli_consensus_final_true_lib.mgf filter=lfs diff=lfs merge=lfs -text
91
  e_coli_consensus_final_true_lib.msp filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
89
  drosophila_consensus_final_true_lib.msp filter=lfs diff=lfs merge=lfs -text
90
  e_coli_consensus_final_true_lib.mgf filter=lfs diff=lfs merge=lfs -text
91
  e_coli_consensus_final_true_lib.msp filter=lfs diff=lfs merge=lfs -text
92
+ extracted/cptac2_mouse_hcd_itraq_phospho_selected.msp filter=lfs diff=lfs merge=lfs -text
93
+ extracted/cptac2_mouse_hcd_itraq_selected.msp filter=lfs diff=lfs merge=lfs -text
94
+ extracted/cptac2_mouse_hcd_selected.msp filter=lfs diff=lfs merge=lfs -text
95
+ extracted/mouse_consensus_final_true_lib.msp filter=lfs diff=lfs merge=lfs -text
96
+ mgf/cptac2_mouse_hcd_itraq_phospho_selected.mgf filter=lfs diff=lfs merge=lfs -text
97
+ mgf/cptac2_mouse_hcd_itraq_selected.mgf filter=lfs diff=lfs merge=lfs -text
98
+ mgf/cptac2_mouse_hcd_selected.mgf filter=lfs diff=lfs merge=lfs -text
99
+ mgf/mouse_consensus_final_true_lib.mgf filter=lfs diff=lfs merge=lfs -text
download_list.txt CHANGED
@@ -1,11 +1,4 @@
1
- https://chemdata.nist.gov/download/peptide_library/libraries/human/ION_TRAP/2014_05_29/2014_05_29_human_consensus_final_true_lib.tar.gz
2
- https://chemdata.nist.gov/download/peptide_library/libraries/human/HCD/2020_05_19/human_hcd_tryp_best.msp.tar.gz
3
- https://chemdata.nist.gov/download/peptide_library/libraries/human/HCD/2020_05_19/human_hcd_tryp_good.msp.tar.gz
4
- https://chemdata.nist.gov/download/peptide_library/libraries/human/HCD/2020_05_19/human_hcd_semitryp.msp.tar.gz
5
- https://chemdata.nist.gov/download/peptide_library/libraries/cptaclib/2015/cptac2_human_hcd_itraq_selected_part1.msp.tar.gz
6
- https://chemdata.nist.gov/download/peptide_library/libraries/cptaclib/2015/cptac2_human_hcd_itraq_selected_part2.msp.tar.gz
7
- https://chemdata.nist.gov/download/peptide_library/libraries/cptaclib/2015/cptac2_human_hcd_itraq_phospho_selected.msp.tar.gz
8
- https://chemdata.nist.gov/download/peptide_library/libraries/human/HCD/2017_05_30/human_synthetic_hcd_selected.msp.tar.gz
9
- https://chemdata.nist.gov/download/peptide_library/libraries/human/HCD/2019_02_14/human_hcd_labelfree_phospho_selected_passed.msp.tar.gz
10
- https://chemdata.nist.gov/download/peptide_library/libraries/human/HCD/hair/human_hair_selected_with_GVPs_passed_msp.tar.gz
11
- https://chemdata.nist.gov/download/peptide_library/libraries/human/HCD/2022_03_16/cptac3_tmt_selected_passed_best.msp.tar.gz
 
1
+ https://chemdata.nist.gov/download/peptide_library/libraries/mouse/ION_TRAP/2013_05_20/2013_05_20_mouse_consensus_final_true_lib.tar.gz
2
+ https://chemdata.nist.gov/download/peptide_library/libraries/cptaclib/2015/cptac2_mouse_hcd_selected.msp.tar.gz
3
+ https://chemdata.nist.gov/download/peptide_library/libraries/cptaclib/2015/cptac2_mouse_hcd_itraq_selected.msp.tar.gz
4
+ https://chemdata.nist.gov/download/peptide_library/libraries/cptaclib/2015/cptac2_mouse_hcd_itraq_phospho_selected.msp.tar.gz
 
 
 
 
 
 
 
downloads/.DS_Store CHANGED
Binary files a/downloads/.DS_Store and b/downloads/.DS_Store differ
 
downloads/2013_05_20_mouse_consensus_final_true_lib.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9f88234d90684bd7bdbca31d9f9742ef107685d3791d0ec2570e91f2c66b82ba
3
+ size 227578902
downloads/cptac2_mouse_hcd_itraq_phospho_selected.msp.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6cd24b2fc9d15a2269c872c8f9ce5822a76dfa361787efc9ecf7693b0ee98de3
3
+ size 74644121
downloads/cptac2_mouse_hcd_itraq_selected.msp.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9e9b1c8865fa859279b294407a6993a5c22c76631db9331373d86b1232441249
3
+ size 360659920
downloads/cptac2_mouse_hcd_selected.msp.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:347c0d14aa3b673ea51089924b22a528e20db2290e165703814085a554aff254
3
+ size 61660818
extracted/cptac2_mouse_hcd_itraq_phospho_selected.msp ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1569974c2c0af3d9f26695fa33f95d2161ab4af85ba5defb1bb498d62319e105
3
+ size 217718178
extracted/cptac2_mouse_hcd_itraq_selected.msp ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9b477dd318c085b146915b48f3fa7c6b543c6b53ce80735579580678c296e8e2
3
+ size 1044198105
extracted/cptac2_mouse_hcd_selected.msp ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:943a663f11127b98a0bd7cf4343b460f9a109630f59c04e18938eaa3a353080d
3
+ size 181845806
extracted/mouse_consensus_final_true_lib.msp ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:557685a16568d90e5f31473de35ca98561c2da2e6154443d4b09be185c691ac6
3
+ size 685987106
mgf/cptac2_mouse_hcd_itraq_phospho_selected.mgf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f52662493c6be02447cac538bf5321bacff84f806986502a47887fceab9c441f
3
+ size 83274964
mgf/cptac2_mouse_hcd_itraq_selected.mgf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6e4a94b27d2cd8464431ee771e35c0cd8323a61e3577d2d59a56df0f81ddb221
3
+ size 403687841
mgf/cptac2_mouse_hcd_selected.mgf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a77cb8ae41ed596864cda104364e0c893219f4afddff95a2761a7af0e4c73c0f
3
+ size 67648441
mgf/mouse_consensus_final_true_lib.mgf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ecafa0686d7aac09a3705432d5906ebd6e9909c7984c1c8ff5bc5e080fe43c37
3
+ size 238390604
mgf/msp_to_mgf_summary.xlsx CHANGED
Binary files a/mgf/msp_to_mgf_summary.xlsx and b/mgf/msp_to_mgf_summary.xlsx differ
 
msp_to_mgf.py CHANGED
@@ -1,25 +1,29 @@
1
  # -*- coding: utf-8 -*-
2
- import os
3
  import re
 
 
4
 
5
  # =========================================================
6
- # 1) 读取路径与保存路径(请你按自己的电脑路径修改)
 
 
 
7
  # =========================================================
8
- # 示例(macOS):
9
- MSP_PATH = "/Users/guanmumu/Desktop/Data/E. coli/e_coli_consensus_final_true_lib.msp"
10
- MGF_PATH = "/Users/guanmumu/Desktop/Data/E. coli/e_coli_consensus_final_true_lib.mgf"
11
 
12
- # 如果你想让脚本“放哪儿都能跑”,可以用脚本所在目录:
13
- # BASE_DIR = os.path.dirname(os.path.abspath(__file__))
14
- # MSP_PATH = os.path.join(BASE_DIR, "bsa_consensus_final_true_lib.msp")
15
- # MGF_PATH = os.path.join(BASE_DIR, "bsa_consensus_final_true_lib.pepmass_is_mw.mgf")
16
 
17
  # =========================================================
18
- # 2) MSP 字段解析函数
19
  # =========================================================
20
  def parse_sequence_from_name(name_val: str) -> str:
21
  # Name: SEQUENCE/charge_...
22
- return name_val.split("/")[0].strip()
23
 
24
  def parse_charge_from_name(name_val: str):
25
  m = re.search(r"/(\d+)", name_val)
@@ -31,14 +35,16 @@ def parse_mz_exact_from_comment(line: str):
31
  return float(m.group(1)) if m else None
32
 
33
  # =========================================================
34
- # 3) 主逻辑:流式读取 MSP,写 MGF
 
 
35
  # =========================================================
36
- def main():
37
  spectra_count = 0
38
  unique_peptides = set()
39
 
40
- with open(MSP_PATH, "r", encoding="utf-8", errors="replace") as fin, \
41
- open(MGF_PATH, "w", encoding="utf-8") as fout:
42
 
43
  name_val = None
44
  seq = None
@@ -65,15 +71,12 @@ def main():
65
  precursor_mz = parse_mz_exact_from_comment(line)
66
 
67
  elif line.startswith("Num peaks:"):
68
- # 进入峰列表块
69
  num_peaks = int(line.split("Num peaks:", 1)[1].strip())
70
-
71
  spectra_count += 1
72
 
73
- # ===================== 写一个 MGF block =====================
74
  fout.write("BEGIN IONS\n")
75
 
76
- # TITLE:建议写得可追溯
77
  if seq is not None and charge is not None:
78
  fout.write(f"TITLE={seq}/z{charge}\n")
79
  elif seq is not None:
@@ -82,49 +85,94 @@ def main():
82
  fout.write(f"TITLE=Spectrum_{spectra_count}\n")
83
 
84
  # 你要求:PEPMASS = MW(不做换算)
85
- # 注意:如果 mw 缺失,会跳过 PEPMASS 行
86
  if mw is not None:
87
  fout.write(f"PEPMASS={mw:.6f}\n")
88
 
89
- # 电荷
90
  if charge is not None:
91
  fout.write(f"CHARGE={charge}+\n")
92
 
93
- # 你要的 sequence 列:这里写在 MGF 自定义字段中
94
  if seq is not None:
95
  fout.write(f"SEQ={seq}\n")
96
 
97
- # 辅助字段:把 Comment 里 Mz_exact 也记录下来(不影响你要求)
98
  if precursor_mz is not None:
99
  fout.write(f"PRECURSOR_MZ={precursor_mz:.6f}\n")
100
 
101
- # 写峰:每行 "m/z intensity"
102
  for _ in range(num_peaks):
103
  peak_line = next(fin).strip()
104
  if not peak_line:
105
  continue
106
  parts = peak_line.split()
107
  if len(parts) >= 2:
108
- mz = parts[0]
109
- inten = parts[1]
110
- fout.write(f"{mz} {inten}\n")
111
 
112
  fout.write("END IONS\n\n")
113
 
114
- # reset 当前谱状态
115
  name_val = None
116
  seq = None
117
  charge = None
118
  mw = None
119
  precursor_mz = None
120
 
121
- # =========================================================
122
- # 4) 最终统计输出
123
- # =========================================================
124
- print(f"[DONE] MSP input : {MSP_PATH}")
125
- print(f"[DONE] MGF output: {MGF_PATH}")
126
- print(f"Spectra count : {spectra_count}")
127
- print(f"Unique peptides : {len(unique_peptides)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
  if __name__ == "__main__":
130
  main()
 
1
  # -*- coding: utf-8 -*-
 
2
  import re
3
+ from pathlib import Path
4
+ from openpyxl import Workbook
5
 
6
  # =========================================================
7
+ # 1) 路径配置:改这里即可
8
+ # INPUT_DIR : 你截图里的 extracted 目录(存放 .msp)
9
+ # OUTPUT_DIR: 输出 .mgf 的目录(会自动创建)
10
+ # EXCEL_PATH: 输出统计表
11
  # =========================================================
12
+ INPUT_DIR = Path("/Users/guanmumu/Desktop/Data/Mouse/extracted")
13
+ OUTPUT_DIR = Path("/Users/guanmumu/Desktop/Data/Mouse/mgf")
14
+ OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
15
 
16
+ EXCEL_PATH = OUTPUT_DIR / "msp_to_mgf_summary.xlsx"
17
+
18
+ # 进度打印(大文件可调)
19
+ PROGRESS_EVERY_SPECTRA = 50000
20
 
21
  # =========================================================
22
+ # 2) MSP 字段解析函数(保持和你单文件脚本一致)
23
  # =========================================================
24
  def parse_sequence_from_name(name_val: str) -> str:
25
  # Name: SEQUENCE/charge_...
26
+ return name_val.split("/", 1)[0].strip()
27
 
28
  def parse_charge_from_name(name_val: str):
29
  m = re.search(r"/(\d+)", name_val)
 
35
  return float(m.group(1)) if m else None
36
 
37
  # =========================================================
38
+ # 3) 转换单个 MSP -> MGF,并返回统计信息
39
+ # - Spectra count: Num peaks 次数
40
+ # - Unique peptides: 对 Name: 的 seq 去重(与你单文件脚本一致)
41
  # =========================================================
42
+ def convert_one_msp(msp_path: Path, mgf_path: Path):
43
  spectra_count = 0
44
  unique_peptides = set()
45
 
46
+ with msp_path.open("r", encoding="utf-8", errors="replace") as fin, \
47
+ mgf_path.open("w", encoding="utf-8") as fout:
48
 
49
  name_val = None
50
  seq = None
 
71
  precursor_mz = parse_mz_exact_from_comment(line)
72
 
73
  elif line.startswith("Num peaks:"):
 
74
  num_peaks = int(line.split("Num peaks:", 1)[1].strip())
 
75
  spectra_count += 1
76
 
77
+ # ===== 写一个 MGF block =====
78
  fout.write("BEGIN IONS\n")
79
 
 
80
  if seq is not None and charge is not None:
81
  fout.write(f"TITLE={seq}/z{charge}\n")
82
  elif seq is not None:
 
85
  fout.write(f"TITLE=Spectrum_{spectra_count}\n")
86
 
87
  # 你要求:PEPMASS = MW(不做换算)
 
88
  if mw is not None:
89
  fout.write(f"PEPMASS={mw:.6f}\n")
90
 
 
91
  if charge is not None:
92
  fout.write(f"CHARGE={charge}+\n")
93
 
94
+ # 自定义字段
95
  if seq is not None:
96
  fout.write(f"SEQ={seq}\n")
97
 
98
+ # 可选:记录 Mz_exact(不影响你要求)
99
  if precursor_mz is not None:
100
  fout.write(f"PRECURSOR_MZ={precursor_mz:.6f}\n")
101
 
102
+ # 峰:每行 "m/z intensity"
103
  for _ in range(num_peaks):
104
  peak_line = next(fin).strip()
105
  if not peak_line:
106
  continue
107
  parts = peak_line.split()
108
  if len(parts) >= 2:
109
+ fout.write(f"{parts[0]} {parts[1]}\n")
 
 
110
 
111
  fout.write("END IONS\n\n")
112
 
113
+ # reset 当前谱状态(与你单文件脚本一致)
114
  name_val = None
115
  seq = None
116
  charge = None
117
  mw = None
118
  precursor_mz = None
119
 
120
+ if spectra_count % PROGRESS_EVERY_SPECTRA == 0:
121
+ print(f" ... {msp_path.name}: spectra={spectra_count}")
122
+
123
+ return spectra_count, len(unique_peptides)
124
+
125
+ # =========================================================
126
+ # 4) 写 Excel(3列:文件名 / Spectra count / Unique peptides
127
+ # =========================================================
128
+ def write_excel(excel_path: Path, rows):
129
+ wb = Workbook()
130
+ ws = wb.active
131
+ ws.title = "summary"
132
+
133
+ for r in rows:
134
+ ws.append(list(r))
135
+
136
+ ws.column_dimensions["A"].width = 55
137
+ ws.column_dimensions["B"].width = 18
138
+ ws.column_dimensions["C"].width = 20
139
+
140
+ wb.save(excel_path)
141
+
142
+ # =========================================================
143
+ # 5) 批量处理
144
+ # =========================================================
145
+ def main():
146
+ if not INPUT_DIR.exists():
147
+ raise FileNotFoundError(f"INPUT_DIR not found: {INPUT_DIR}")
148
+
149
+ msp_files = sorted(INPUT_DIR.glob("*.msp"))
150
+ if not msp_files:
151
+ print(f"No .msp files found in: {INPUT_DIR}")
152
+ return
153
+
154
+ print(f"Input dir : {INPUT_DIR}")
155
+ print(f"Output dir: {OUTPUT_DIR}")
156
+ print(f"Found {len(msp_files)} MSP files.")
157
+
158
+ rows = [("file_name", "spectra_count", "unique_peptides")]
159
+
160
+ for idx, msp_path in enumerate(msp_files, 1):
161
+ mgf_path = OUTPUT_DIR / (msp_path.stem + ".mgf")
162
+
163
+ print(f"\n[{idx}/{len(msp_files)}] Converting: {msp_path.name}")
164
+ spectra_count, unique_pep = convert_one_msp(msp_path, mgf_path)
165
+
166
+ print(f" -> MGF: {mgf_path.name}")
167
+ print(f" Spectra count : {spectra_count}")
168
+ print(f" Unique peptides : {unique_pep}")
169
+
170
+ rows.append((msp_path.name, spectra_count, unique_pep))
171
+
172
+ write_excel(EXCEL_PATH, rows)
173
+
174
+ print("\n================= DONE =================")
175
+ print(f"Excel summary: {EXCEL_PATH}")
176
 
177
  if __name__ == "__main__":
178
  main()