robert05 commited on
Commit
3689349
·
verified ·
1 Parent(s): a77d6e1

Upload folder using huggingface_hub

Browse files
Files changed (43) hide show
  1. .DS_Store +0 -0
  2. .gitattributes +22 -0
  3. download_list.txt +11 -0
  4. downloads/.DS_Store +0 -0
  5. downloads/2014_05_29_human_consensus_final_true_lib.tar.gz +3 -0
  6. downloads/cptac2_human_hcd_itraq_phospho_selected.msp.tar.gz +3 -0
  7. downloads/cptac2_human_hcd_itraq_selected_part1.msp.tar.gz +3 -0
  8. downloads/cptac2_human_hcd_itraq_selected_part2.msp.tar.gz +3 -0
  9. downloads/cptac3_tmt_selected_passed_best.msp.tar.gz +3 -0
  10. downloads/human_hair_selected_with_GVPs_passed_msp.tar.gz +3 -0
  11. downloads/human_hcd_labelfree_phospho_selected_passed.msp.tar.gz +3 -0
  12. downloads/human_hcd_semitryp.msp.tar.gz +3 -0
  13. downloads/human_hcd_tryp_best.msp.tar.gz +3 -0
  14. downloads/human_hcd_tryp_good.msp.tar.gz +3 -0
  15. downloads/human_synthetic_hcd_selected.msp.tar.gz +3 -0
  16. extracted/.DS_Store +0 -0
  17. extracted/cptac2_human_hcd_itraq_phospho_selected.msp +3 -0
  18. extracted/cptac2_human_hcd_itraq_selected_part1.msp +3 -0
  19. extracted/cptac2_human_hcd_itraq_selected_part2.msp +3 -0
  20. extracted/cptac3_tmt_selected_passed_best.msp +3 -0
  21. extracted/human_consensus_final_true_lib.msp +3 -0
  22. extracted/human_hair_selected_with_GVPs_passed.msp +3 -0
  23. extracted/human_hcd_labelfree_phospho_selected_passed.msp +3 -0
  24. extracted/human_hcd_semitryp.msp +3 -0
  25. extracted/human_hcd_tryp_best.msp +3 -0
  26. extracted/human_hcd_tryp_good.msp +3 -0
  27. extracted/human_synthetic_hcd_selected.msp +3 -0
  28. mgf/.DS_Store +0 -0
  29. mgf/cptac2_human_hcd_itraq_phospho_selected.mgf +3 -0
  30. mgf/cptac2_human_hcd_itraq_selected_part1.mgf +3 -0
  31. mgf/cptac2_human_hcd_itraq_selected_part2.mgf +3 -0
  32. mgf/cptac3_tmt_selected_passed_best.mgf +3 -0
  33. mgf/human_consensus_final_true_lib.mgf +3 -0
  34. mgf/human_hair_selected_with_GVPs_passed.mgf +3 -0
  35. mgf/human_hcd_labelfree_phospho_selected_passed.mgf +3 -0
  36. mgf/human_hcd_semitryp.mgf +3 -0
  37. mgf/human_hcd_tryp_best.mgf +3 -0
  38. mgf/human_hcd_tryp_good.mgf +3 -0
  39. mgf/human_synthetic_hcd_selected.mgf +3 -0
  40. mgf/msp_to_mgf_.xlsx +0 -0
  41. mgf/msp_to_mgf_summary.xlsx +0 -0
  42. msp_to_mgf.py +178 -0
  43. msp_to_mgf_副本.py +130 -0
.DS_Store ADDED
Binary file (14.3 kB). View file
 
.gitattributes CHANGED
@@ -58,3 +58,25 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
58
  *.mp4 filter=lfs diff=lfs merge=lfs -text
59
  *.webm filter=lfs diff=lfs merge=lfs -text
60
  human_hair_selected_with_GVPs_passed.mgf filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  *.mp4 filter=lfs diff=lfs merge=lfs -text
59
  *.webm filter=lfs diff=lfs merge=lfs -text
60
  human_hair_selected_with_GVPs_passed.mgf filter=lfs diff=lfs merge=lfs -text
61
+ extracted/cptac2_human_hcd_itraq_phospho_selected.msp filter=lfs diff=lfs merge=lfs -text
62
+ extracted/cptac2_human_hcd_itraq_selected_part1.msp filter=lfs diff=lfs merge=lfs -text
63
+ extracted/cptac2_human_hcd_itraq_selected_part2.msp filter=lfs diff=lfs merge=lfs -text
64
+ extracted/cptac3_tmt_selected_passed_best.msp filter=lfs diff=lfs merge=lfs -text
65
+ extracted/human_consensus_final_true_lib.msp filter=lfs diff=lfs merge=lfs -text
66
+ extracted/human_hair_selected_with_GVPs_passed.msp filter=lfs diff=lfs merge=lfs -text
67
+ extracted/human_hcd_labelfree_phospho_selected_passed.msp filter=lfs diff=lfs merge=lfs -text
68
+ extracted/human_hcd_semitryp.msp filter=lfs diff=lfs merge=lfs -text
69
+ extracted/human_hcd_tryp_best.msp filter=lfs diff=lfs merge=lfs -text
70
+ extracted/human_hcd_tryp_good.msp filter=lfs diff=lfs merge=lfs -text
71
+ extracted/human_synthetic_hcd_selected.msp filter=lfs diff=lfs merge=lfs -text
72
+ mgf/cptac2_human_hcd_itraq_phospho_selected.mgf filter=lfs diff=lfs merge=lfs -text
73
+ mgf/cptac2_human_hcd_itraq_selected_part1.mgf filter=lfs diff=lfs merge=lfs -text
74
+ mgf/cptac2_human_hcd_itraq_selected_part2.mgf filter=lfs diff=lfs merge=lfs -text
75
+ mgf/cptac3_tmt_selected_passed_best.mgf filter=lfs diff=lfs merge=lfs -text
76
+ mgf/human_consensus_final_true_lib.mgf filter=lfs diff=lfs merge=lfs -text
77
+ mgf/human_hair_selected_with_GVPs_passed.mgf filter=lfs diff=lfs merge=lfs -text
78
+ mgf/human_hcd_labelfree_phospho_selected_passed.mgf filter=lfs diff=lfs merge=lfs -text
79
+ mgf/human_hcd_semitryp.mgf filter=lfs diff=lfs merge=lfs -text
80
+ mgf/human_hcd_tryp_best.mgf filter=lfs diff=lfs merge=lfs -text
81
+ mgf/human_hcd_tryp_good.mgf filter=lfs diff=lfs merge=lfs -text
82
+ mgf/human_synthetic_hcd_selected.mgf filter=lfs diff=lfs merge=lfs -text
download_list.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
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
downloads/.DS_Store ADDED
Binary file (6.15 kB). View file
 
downloads/2014_05_29_human_consensus_final_true_lib.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b2c16ffdfb154e4b09db554bb2e6aabab48ecb196b0fab39b61977c5076b366f
3
+ size 573909561
downloads/cptac2_human_hcd_itraq_phospho_selected.msp.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:233f92a089d0eb83e48150d9b3c32c4145939fd886d364ffb2067922b45d8f8f
3
+ size 1162476607
downloads/cptac2_human_hcd_itraq_selected_part1.msp.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6bf4dec73d2b3f1eac4f1902b00b6edadefac0244de99adf660a2b4fc145b1f3
3
+ size 1961961686
downloads/cptac2_human_hcd_itraq_selected_part2.msp.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:14e0196680db5e2f2513094c4da86ac067928f5b8747aea20dc39d086e098438
3
+ size 2090393526
downloads/cptac3_tmt_selected_passed_best.msp.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:063ac05e057ef5b5745049d7ccba97d69b9d4de6806e96890e98f277b9d02bd3
3
+ size 2717409713
downloads/human_hair_selected_with_GVPs_passed_msp.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5de06f70d0462b6b92510e30ba10028a8ebf0c7f613f21f77035cb5b7144b007
3
+ size 19504122
downloads/human_hcd_labelfree_phospho_selected_passed.msp.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b1faa9bf7c77006c167a7a89d4d7435bea91adebe1528ffc0ab31ebd1bb61de5
3
+ size 244368083
downloads/human_hcd_semitryp.msp.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:43670383bfbb3669fb900aefce08838cecd7766783df440cfc4fd0d28cb89a0b
3
+ size 627308208
downloads/human_hcd_tryp_best.msp.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1866af6296e9b696aed71d0dbf22b82dc15d02510459c236b2a37798a0c00ebf
3
+ size 677259962
downloads/human_hcd_tryp_good.msp.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5b7ca7ccf69df16900df51f3b620f5cdb1bc155459d32dc82806c84ee6d6f3e5
3
+ size 414274314
downloads/human_synthetic_hcd_selected.msp.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:049385c4b539a268389f10a5565ea6627b88bde8476075b93b6498084e64da0c
3
+ size 2282954701
extracted/.DS_Store ADDED
Binary file (6.15 kB). View file
 
extracted/cptac2_human_hcd_itraq_phospho_selected.msp ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f0a215409e67a71472d1a66723b13df4eee72fe4fc08b371a5002eb0caed0a95
3
+ size 3436589381
extracted/cptac2_human_hcd_itraq_selected_part1.msp ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d53905c7e1f6feb87a3a813b370db9cebb29d18304fa2e9f4ed9888892b5c537
3
+ size 5696742728
extracted/cptac2_human_hcd_itraq_selected_part2.msp ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a0bc8b3da8a3c7d07365d6d0e8a97d58ba9dc397519e57155192e0b87aa8c56f
3
+ size 6065475043
extracted/cptac3_tmt_selected_passed_best.msp ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:41935573cc352036950929c6c431917f90ace804e7709bccc94af2965f271ec7
3
+ size 7284745279
extracted/human_consensus_final_true_lib.msp ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6dc464bc6e087e9874da719c43a4eedbac26c9fd603c635bbc600948871dc76d
3
+ size 1799654156
extracted/human_hair_selected_with_GVPs_passed.msp ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a280e55e1548de927948f7cb9ef38021c44a9e7b17a95d7175df30f9caa983bb
3
+ size 51857342
extracted/human_hcd_labelfree_phospho_selected_passed.msp ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:85413f74e7e196a0b1ba0a9ea30f2b04be2cf8631e04b0f8c31bce76eb1b8598
3
+ size 666477843
extracted/human_hcd_semitryp.msp ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:08468e189efca7eb51e0dd29d8998851643809caeb0d0e211731752b4c437c10
3
+ size 1828861186
extracted/human_hcd_tryp_best.msp ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:91c7024827cb8b5ea4ca26048eea050c1c5c8cc45068dc384029d4a5a35ce391
3
+ size 1977167029
extracted/human_hcd_tryp_good.msp ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bd5546534a4a6d4a76aa9ca14bc1d4c23c65989cde8ddbc4320df20b46f6ffb0
3
+ size 1206025106
extracted/human_synthetic_hcd_selected.msp ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3024d7bd30b2890d4f5666f464fc6d1f27c9c934cb89f16da0d20d51ccfd39e6
3
+ size 6314162285
mgf/.DS_Store ADDED
Binary file (6.15 kB). View file
 
mgf/cptac2_human_hcd_itraq_phospho_selected.mgf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a32ad6732b312f4f9e70d518f24a5cfe0fea77a192e0d13f56be79c8fb802bef
3
+ size 1286960599
mgf/cptac2_human_hcd_itraq_selected_part1.mgf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2112e672640a5c4c8f10dc6f995718ecf39e15e433d6edb9075529af547b0b6b
3
+ size 2267561747
mgf/cptac2_human_hcd_itraq_selected_part2.mgf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c1f34c699b214812f78cfe646f7d63379de89139265f446141992b726ce82f63
3
+ size 2410447071
mgf/cptac3_tmt_selected_passed_best.mgf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1333acf3677f1c8b291a81306f502fd630dc3a3f405ee702bf2048ec9b66c0e0
3
+ size 4464804155
mgf/human_consensus_final_true_lib.mgf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:833aeab251c4762ec414a87d2641de24681be5253fe0e294568e4dec91e423dd
3
+ size 535157732
mgf/human_hair_selected_with_GVPs_passed.mgf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ee4af223792becc06021ca66745f7128870a5f25670a4650ac491ae32dd3fb07
3
+ size 30846552
mgf/human_hcd_labelfree_phospho_selected_passed.mgf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fcab79ce88cd32dcafce856d7b2d020c6455fe7b521d05ed4fc2259450aa7c40
3
+ size 369461867
mgf/human_hcd_semitryp.mgf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:31ad7f74490c143e4ac1c0de55d46c36515097f2128c77325738d33c91e8e521
3
+ size 857276354
mgf/human_hcd_tryp_best.mgf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cf865bea5f3ace2c01b6e8fa9863ec172ea6de5552ad04fa1ee00936e50d5d60
3
+ size 869051862
mgf/human_hcd_tryp_good.mgf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:176735488a881c13aa75855630b57b0a5550098ce32cf166cdc04fe43fc5a300
3
+ size 555735766
mgf/human_synthetic_hcd_selected.mgf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:23336945fee0ea76f46a6e9f14703a19c82818bd0791af41ddffe0334b77d5eb
3
+ size 3582540718
mgf/msp_to_mgf_.xlsx ADDED
Binary file (5.28 kB). View file
 
mgf/msp_to_mgf_summary.xlsx ADDED
Binary file (9 kB). View file
 
msp_to_mgf.py ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/Human/extracted")
13
+ OUTPUT_DIR = Path("/Users/guanmumu/Desktop/Data/Human/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)
30
+ return int(m.group(1)) if m else None
31
+
32
+ def parse_mz_exact_from_comment(line: str):
33
+ # Comment: ... Mz_exact=536.5844 ...
34
+ m = re.search(r"\bMz_exact=([0-9]*\.?[0-9]+)", line)
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
51
+ charge = None
52
+ mw = None # 你要求用作 PEPMASS
53
+ precursor_mz = None # 仅用于辅助记录(Mz_exact)
54
+
55
+ for line in fin:
56
+ line = line.rstrip("\n")
57
+
58
+ if line.startswith("Name:"):
59
+ name_val = line.split("Name:", 1)[1].strip()
60
+ seq = parse_sequence_from_name(name_val)
61
+ charge = parse_charge_from_name(name_val)
62
+ unique_peptides.add(seq)
63
+
64
+ elif line.startswith("MW:"):
65
+ try:
66
+ mw = float(line.split("MW:", 1)[1].strip())
67
+ except Exception:
68
+ mw = None
69
+
70
+ elif line.startswith("Comment:"):
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:
83
+ fout.write(f"TITLE={seq}\n")
84
+ else:
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()
msp_to_mgf_副本.py ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ import os
3
+ import re
4
+
5
+ # =========================================================
6
+ # 1) 读取路径与保存路径(请你按自己的电脑路径修改)
7
+ # =========================================================
8
+ # 示例(macOS):
9
+ MSP_PATH = "/Users/guanmumu/Desktop/Data/Human/extracted/human_hair_selected_with_GVPs_passed.msp"
10
+ MGF_PATH = "/Users/guanmumu/Desktop/Data/human_hair_selected_with_GVPs_passed.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)
26
+ return int(m.group(1)) if m else None
27
+
28
+ def parse_mz_exact_from_comment(line: str):
29
+ # Comment: ... Mz_exact=536.5844 ...
30
+ m = re.search(r"\bMz_exact=([0-9]*\.?[0-9]+)", line)
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
45
+ charge = None
46
+ mw = None # 你要求用作 PEPMASS
47
+ precursor_mz = None # 仅用于辅助记录(Mz_exact)
48
+
49
+ for line in fin:
50
+ line = line.rstrip("\n")
51
+
52
+ if line.startswith("Name:"):
53
+ name_val = line.split("Name:", 1)[1].strip()
54
+ seq = parse_sequence_from_name(name_val)
55
+ charge = parse_charge_from_name(name_val)
56
+ unique_peptides.add(seq)
57
+
58
+ elif line.startswith("MW:"):
59
+ try:
60
+ mw = float(line.split("MW:", 1)[1].strip())
61
+ except Exception:
62
+ mw = None
63
+
64
+ elif line.startswith("Comment:"):
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:
80
+ fout.write(f"TITLE={seq}\n")
81
+ else:
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()