CandyCrunch 0.2.2__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. {CandyCrunch-0.2.2 → CandyCrunch-0.4.0}/CandyCrunch/analysis.py +208 -327
  2. {CandyCrunch-0.2.2 → CandyCrunch-0.4.0}/CandyCrunch/candycrunch.pt +0 -0
  3. CandyCrunch-0.4.0/CandyCrunch/cli.py +38 -0
  4. CandyCrunch-0.4.0/CandyCrunch/glycans.pkl +0 -0
  5. CandyCrunch-0.4.0/CandyCrunch/glytoucan_mapping.pkl +0 -0
  6. CandyCrunch-0.4.0/CandyCrunch/prediction.py +1682 -0
  7. CandyCrunch-0.4.0/CandyCrunch/tester.py +2 -0
  8. CandyCrunch-0.4.0/CandyCrunch.egg-info/PKG-INFO +279 -0
  9. {CandyCrunch-0.2.2 → CandyCrunch-0.4.0}/CandyCrunch.egg-info/SOURCES.txt +4 -0
  10. CandyCrunch-0.4.0/CandyCrunch.egg-info/entry_points.txt +2 -0
  11. {CandyCrunch-0.2.2 → CandyCrunch-0.4.0}/CandyCrunch.egg-info/requires.txt +3 -3
  12. CandyCrunch-0.4.0/PKG-INFO +279 -0
  13. CandyCrunch-0.4.0/README.md +263 -0
  14. {CandyCrunch-0.2.2 → CandyCrunch-0.4.0}/setup.py +9 -4
  15. CandyCrunch-0.2.2/CandyCrunch/glycans.pkl +0 -0
  16. CandyCrunch-0.2.2/CandyCrunch/prediction.py +0 -1001
  17. CandyCrunch-0.2.2/CandyCrunch.egg-info/PKG-INFO +0 -133
  18. CandyCrunch-0.2.2/PKG-INFO +0 -133
  19. CandyCrunch-0.2.2/README.md +0 -117
  20. {CandyCrunch-0.2.2 → CandyCrunch-0.4.0}/CandyCrunch/__init__.py +0 -0
  21. {CandyCrunch-0.2.2 → CandyCrunch-0.4.0}/CandyCrunch/model.py +0 -0
  22. {CandyCrunch-0.2.2 → CandyCrunch-0.4.0}/CandyCrunch.egg-info/dependency_links.txt +0 -0
  23. {CandyCrunch-0.2.2 → CandyCrunch-0.4.0}/CandyCrunch.egg-info/top_level.txt +0 -0
  24. {CandyCrunch-0.2.2 → CandyCrunch-0.4.0}/LICENSE +0 -0
  25. {CandyCrunch-0.2.2 → CandyCrunch-0.4.0}/LICENSE.txt +0 -0
  26. {CandyCrunch-0.2.2 → CandyCrunch-0.4.0}/setup.cfg +0 -0
@@ -10,115 +10,90 @@ import networkx as nx
10
10
  import networkx.algorithms.isomorphism as iso
11
11
  import numpy as np
12
12
  import pandas as pd
13
- from glycowork.glycan_data.loader import lib, unwrap
14
- from glycowork.motif.processing import (bracket_removal, cohen_d,
15
- min_process_glycans)
13
+ from glycowork.glycan_data.loader import unwrap
14
+ from glycowork.motif.processing import (bracket_removal,
15
+ min_process_glycans, rescue_glycans)
16
+ from glycowork.motif.tokenization import map_to_basic
17
+ from glycowork.glycan_data.stats import cohen_d
18
+
16
19
  from scipy.stats import ttest_ind
17
20
  from statsmodels.stats.multitest import multipletests
18
21
 
19
- mono_attributes = {'Gal': {'mass': {'03X': 72.0211, '02X': 42.0105, '15X': 27.9949, '13A': 60.0211, '24A': 60.0211,
20
- '04A': 60.0211, '35A': 74.0368, '25A': 104.0473, '02A': 120.0423, 'Gal': 162.0528},
21
- 'atoms': {'03X': [1, 2, 3], '02X': [1, 2], '15X': [1], '13A': [2, 3], '24A': [3, 4],
22
- '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6], '02A': [3, 4, 5, 6], 'Gal': [1, 2, 3, 4, 5, 6]}},
23
- 'Glc': {'mass': {'03X': 72.0211, '02X': 42.0105, '15X': 27.9949, '13A': 60.0211, '24A': 60.0211,
24
- '04A': 60.0211, '35A': 74.0368, '25A': 104.0473, '02A': 120.0423, 'Glc': 162.0528},
25
- 'atoms': {'03X': [1, 2, 3], '02X': [1, 2], '15X': [1], '13A': [2, 3], '24A': [3, 4],
26
- '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6], '02A': [3, 4, 5, 6], 'Glc': [1, 2, 3, 4, 5, 6]}},
27
- 'Man': {'mass': {'03X': 72.0211, '02X': 42.0105, '15X': 27.9949, '13A': 60.0211, '24A': 60.0211,
28
- '04A': 60.0211, '35A': 74.0368, '25A': 104.0473, '02A': 120.0423, 'Man': 162.0528},
29
- 'atoms': {'03X': [1, 2, 3], '02X': [1, 2], '15X': [1], '13A': [2, 3], '24A': [3, 4],
30
- '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6], '02A': [3, 4, 5, 6], 'Man': [1, 2, 3, 4, 5, 6]}},
31
- 'Hex': {'mass': {'03X': 72.0211, '02X': 42.0105, '15X': 27.9949, '13A': 60.0211, '24A': 60.0211,
32
- '04A': 60.0211, '35A': 74.0368, '25A': 104.0473, '02A': 120.0423, 'Hex': 162.0528},
33
- 'atoms': {'03X': [1, 2, 3], '02X': [1, 2], '15X': [1], '13A': [2, 3], '24A': [3, 4],
34
- '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6], '02A': [3, 4, 5, 6], 'Hex': [1, 2, 3, 4, 5, 6]}},
35
- 'GalNAc': {'mass': {'04A': 60.0211, '24A': 60.0211, '35A': 74.0368, '03A': 90.0317, '25A': 104.0473,
36
- '02A': 120.0423, 'GalNAc': 203.0794},
37
- 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6],
38
- '02A': [3, 4, 5, 6], 'GalNAc': [1, 2, 3, 4, 5, 6]}},
39
- 'GlcNAc': {'mass': {'04A': 60.0211, '24A': 60.0211, '35A': 74.0368, '03A': 90.0317, '25A': 104.0473,
40
- '02A': 120.0423, 'GlcNAc': 203.0794},
41
- 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6],
42
- '02A': [3, 4, 5, 6], 'GlcNAc': [1, 2, 3, 4, 5, 6]}},
43
- 'HexNAc': {'mass': {'04A': 60.0211, '24A': 60.0211, '35A': 74.0368, '03A': 90.0317, '25A': 104.0473,
44
- '02A': 120.0423, 'HexNAc': 203.0794},
45
- 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6],
46
- '02A': [3, 4, 5, 6], 'HexNAc': [1, 2, 3, 4, 5, 6]}},
47
- 'Neu5Ac': {'mass': {'02X': 70.0055, '04X': 170.0453, 'Neu5Ac': 291.0954},
48
- 'atoms': {'02X': [1, 2, 3], '04X': [1, 2, 3, 4, 5], 'Neu5Ac': [1, 2, 3, 4, 5, 6, 7, 8, 9]}},
49
- 'Neu5Gc': {'mass': {'02X': 70.0055, '04X': 186.0402, 'Neu5Gc': 307.0903},
50
- 'atoms': {'02X': [1, 2, 3], '04X': [1, 2, 3, 4, 5], 'Neu5Gc': [1, 2, 3, 4, 5, 6, 7, 8, 9]}},
51
- 'Kdn': {'mass': {'02X': 70.0055, '04X': 129.0188, 'Kdn': 250.0689},
52
- 'atoms': {'02X': [1, 2, 3], '04X': [1, 2, 3, 4, 5], 'Kdn': [1, 2, 3, 4, 5, 6, 7, 8, 9]}},
53
- 'GlcA': {'mass': {'GlcA': 176.03209},
54
- 'atoms': {'GlcA': [1, 2, 3, 4, 5, 6]}},
55
- 'HexA': {'mass': {'HexA': 176.03209},
56
- 'atoms': {'HexA': [1, 2, 3, 4, 5, 6]}},
57
- 'Fuc': {'mass': {'Fuc': 146.0579},
58
- 'atoms': {'Fuc': [1, 2, 3, 4, 5, 6]}},
59
- 'dHex': {'mass': {'dHex': 146.0579},
60
- 'atoms': {'dHex': [1, 2, 3, 4, 5, 6]}},
61
- 'GlcNAc6S': {'mass': {'04A': 139.9779, '24A': 60.0211, '35A': 153.9936, '03A': 169.9885, '25A': 184.0041,
62
- '02A': 199.9991, 'GlcNAc6S': 283.0362},
63
- 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6],
64
- '02A': [3, 4, 5, 6], 'GlcNAc6S': [1, 2, 3, 4, 5, 6]}},
65
- 'GlcNAcOS': {'mass': {'04A': 139.9779, '24A': 139.9779, '35A': 153.9936, '03A': 169.9885, '25A': 184.0041,
66
- '02A': 199.9991, 'GlcNAcOS': 283.0362},
67
- 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6],
68
- '25A': [3, 4, 5, 6], '02A': [3, 4, 5, 6], 'GlcNAcOS': [1, 2, 3, 4, 5, 6]}},
69
- 'GalNAc6S': {'mass': {'04A': 139.9779, '24A': 60.0211, '35A': 153.9936, '03A': 169.9885, '25A': 184.0041,
70
- '02A': 199.9991, 'GalNAc6S': 283.0362},
71
- 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6],
72
- '02A': [3, 4, 5, 6], 'GalNAc6S': [1, 2, 3, 4, 5, 6]}},
73
- 'GalNAcOS': {'mass': {'04A': 139.9779, '24A': 139.9779, '35A': 153.9936, '03A': 169.9885, '25A': 184.0041,
74
- '02A': 199.9991, 'GalNAcOS': 283.0362},
75
- 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6],
76
- '02A': [3, 4, 5, 6], 'GalNAcOS': [1, 2, 3, 4, 5, 6]}},
77
- 'HexNAc6S': {'mass': {'04A': 139.9779, '24A': 60.0211, '35A': 153.9936, '03A': 169.9885, '25A': 184.0041,
78
- '02A': 199.9991, 'HexNAc6S': 283.0362},
79
- 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6],
80
- '02A': [3, 4, 5, 6], 'HexNAc6S': [1, 2, 3, 4, 5, 6]}},
81
- 'HexNAcOS': {'mass': {'04A': 139.9779, '24A': 139.9779, '35A': 153.9936, '03A': 169.9885, '25A': 184.0041,
82
- '02A': 199.9991, 'HexNAcOS': 283.0362},
83
- 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6],
84
- '02A': [3, 4, 5, 6], 'HexNAcOS': [1, 2, 3, 4, 5, 6]}},
85
- 'Gal6S': {'mass': {'13A': 60.0211, '24A': 60.0211, '04A': 139.9779, '35A': 153.9936, '25A': 184.0041,
86
- '02A': 199.9991, 'Gal6S': 242.0096},
87
- 'atoms': {'13A': [2, 3], '24A': [3, 4], '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6],
88
- '02A': [3, 4, 5, 6], 'Gal6S': [1, 2, 3, 4, 5, 6]}},
89
- 'Gal3S': {'mass': {'13A': 139.9779, '24A': 139.9779, '04A': 60.0211, '35A': 74.0368, '25A': 184.0041,
90
- '02A': 199.9991, 'Gal3S': 242.0096},
91
- 'atoms': {'13A': [2, 3], '24A': [3, 4], '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6],
92
- '02A': [3, 4, 5, 6], 'Gal3S': [1, 2, 3, 4, 5, 6]}},
93
- 'GalOS': {'mass': {'13A': 60.0211, '24A': 139.9779, '04A': 139.9779, '35A': 153.9936, '25A': 184.0041,
94
- '02A': 199.9991, 'GalOS': 242.0096},
95
- 'atoms': {'13A': [2, 3], '24A': [3, 4], '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6],
96
- '02A': [3, 4, 5, 6], 'GalOS': [1, 2, 3, 4, 5, 6]}},
97
- 'Glc6S': {'mass': {'13A': 60.0211, '24A': 60.0211, '04A': 139.9779, '35A': 153.9568, '25A': 184.0041,
98
- '02A': 199.9991, 'Glc6S': 242.0096},
99
- 'atoms': {'13A': [2, 3], '24A': [3, 4], '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6],
100
- '02A': [3, 4, 5, 6], 'Glc6S': [1, 2, 3, 4, 5, 6]}},
101
- 'Glc3S': {'mass': {'13A': 139.9779, '24A': 139.9779, '04A': 60.0211, '35A': 74.0368, '25A': 184.0041,
102
- '02A': 199.9991, 'Glc3S': 242.0096},
103
- 'atoms': {'13A': [2, 3], '24A': [3, 4], '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6],
104
- '02A': [3, 4, 5, 6], 'Glc3S': [1, 2, 3, 4, 5, 6]}},
105
- 'GlcOS': {'mass': {'13A': 60.0211, '24A': 139.9779, '04A': 139.9779, '35A': 153.9936, '25A': 184.0041,
106
- '02A': 199.9991, 'GlcOS': 242.0096},
107
- 'atoms': {'13A': [2, 3], '24A': [3, 4], '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6],
108
- '02A': [3, 4, 5, 6], 'GlcOS': [1, 2, 3, 4, 5, 6]}},
109
- 'HexOS': {'mass': {'13A': 60.0211, '24A': 139.9779, '04A': 139.9779, '35A': 153.9936, '25A': 184.0041,
110
- '02A': 199.9991, 'HexOS': 242.0096},
111
- 'atoms': {'13A': [2, 3], '24A': [3, 4], '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6],
112
- '02A': [3, 4, 5, 6], 'HexOS': [1, 2, 3, 4, 5, 6]}},
22
+ mono_attributes = {'Hex': {'mass': {'03X': 72.0211, '02X': 42.0106, '15X': 27.9949, '13A': 60.0211, '24A': 60.0211, '15A': 134.057859,
23
+ '04A': 60.0211, '35A': 74.0368, '25A': 104.0473, '02A': 120.0423, '03A': 74.0368, '24X': 102.0317, '04X': 102.0317,
24
+ '35X': 88.016, 'Hex': 162.0528},
25
+ 'atoms': {'03X': [1, 2, 3], '02X': [1, 2], '15X': [1], '13A': [2, 3], '24A': [3, 4], '15A': [2, 3, 4, 5, 6],
26
+ '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6], '02A': [3, 4, 5, 6], '03A': [4, 5, 6], '24X': [1, 2, 5, 6], '04X': [1, 2, 3, 4],
27
+ '35X': [1, 2, 3], 'Hex': [1, 2, 3, 4, 5, 6]}},
28
+ 'HexNAc': {'mass': {'04A': 60.0211, '24A': 60.0211, '35A': 74.0368, '03A': 90.0317, '25A': 104.0473, '25X': 99.0321,
29
+ '02A': 120.0423, '24X': 143.0583, '14A': 131.058244, '15A': 175.084458, '15X': 27.994941, '04X': 143.0583, '35X': 129.0426,
30
+ '14X': 72.021156, '13X': 102.031741, '13A': 101.047659, 'HexNAc': 203.0794},
31
+ 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6], '25X': [1, 2],
32
+ '02A': [3, 4, 5, 6], '24X': [1, 2, 5, 6], '14A': [2, 3, 4], '15A': [2, 3, 4, 5, 6], '15X': [1], '04X': [1, 2, 3, 4], '35X': [1, 2, 3],
33
+ '14X': [1, 5, 6], '13X': [1, 4, 5, 6], '13A': [2, 3], 'HexNAc': [1, 2, 3, 4, 5, 6]}},
34
+ 'Neu5Ac': {'mass': {'02X': 70.0055, '04X': 170.0453, '24X': 191.0556, '02A': 221.0899,
35
+ '04A': 121.0501, '24A': 100.0398, 'Neu5Ac': 291.0954},
36
+ 'atoms': {'02X': [1, 2, 3], '04X': [1, 2, 3, 4, 5], '24X': [1, 2, 3, 6, 7, 8, 9], '02A': [4, 5, 6, 7, 8, 9],
37
+ '04A': [6, 7, 8, 9], '24A': [4, 5], 'Neu5Ac': [1, 2, 3, 4, 5, 6, 7, 8, 9]}},
38
+ 'Neu5Gc': {'mass': {'02X': 70.0055, '04X': 186.0402, '24X': 191.0556, '02A': 237.0848,
39
+ '04A': 121.0501, '24A': 116.0347, 'Neu5Gc': 307.0903},
40
+ 'atoms': {'02X': [1, 2, 3], '04X': [1, 2, 3, 4, 5], '24X': [1, 2, 3, 6, 7, 8, 9], '02A': [4, 5, 6, 7, 8, 9],
41
+ '04A': [6, 7, 8, 9], '24A': [4, 5], 'Neu5Gc': [1, 2, 3, 4, 5, 6, 7, 8, 9]}},
42
+ 'Kdn': {'mass': {'02X': 70.0055, '04X': 129.0188, '24X': 191.0556, '02A': 180.0634,
43
+ '04A': 121.0501, '24A': 59.0133, 'Kdn': 250.0689},
44
+ 'atoms': {'02X': [1, 2, 3], '04X': [1, 2, 3, 4, 5], '24X': [1, 2, 3, 6, 7, 8, 9], '02A': [4, 5, 6, 7, 8, 9],
45
+ '04A': [6, 7, 8, 9], '24A': [4, 5], 'Kdn': [1, 2, 3, 4, 5, 6, 7, 8, 9]}},
46
+ 'HexA': {'mass': {'02X': 42.0106, '02A': 134.02159, '24X': 116.01099, '24A': 60.0211, 'HexA': 176.03209},
47
+ 'atoms': {'02X': [1, 2], '02A': [3, 4, 5, 6], '24X': [1, 2, 5, 6], '24A': [3, 4], 'HexA': [1, 2, 3, 4, 5, 6]}},
48
+ 'dHex': {'mass': {'02X': 42.0106, '02A': 104.0474, '25X': 42.0106, '25A': 104.0474, 'dHex': 146.0579},
49
+ 'atoms': {'02X': [1, 2], '02A': [3, 4, 5, 6], '25X': [1, 2], '25A': [3, 4, 5, 6], 'dHex': [1, 2, 3, 4, 5, 6]}},
50
+ 'Pen': {'mass': {'01A': 102.0326, '02A': 72.022, '03A': 42.011, '15X': 27.994941, '15A': 104.047359,
51
+ '12X': 102.0326, '03X': 72.022, '02X': 42.011, 'Pen': 132.0423},
52
+ 'atoms': {'01A': [2, 3, 4, 5], '02A': [3, 4, 5], '03A': [4, 5], '15X': [1], '15A': [2, 3, 4, 5],
53
+ '12X': [1, 3, 4, 5], '03X': [1, 2, 3], '02X': [1, 2], 'Pen': [1, 2, 3, 4, 5]}},
54
+ 'HexNAc6S': {'mass': {'04A': 139.9779, '24A': 60.0211, '35A': 153.9936, '03A': 169.9885, '25A': 184.0041, '25X': 99.0321,
55
+ '02A': 199.9991, '24X': 223.0151, '14A': 131.058244, '15A': 255.041259, '15X': 27.994941, '04X': 143.0583, '35X': 129.0426,
56
+ '14X': 151.977956, '13X': 181.988541, '13A': 101.047659, 'HexNAc6S': 283.0362},
57
+ 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6], '25X': [1, 2],
58
+ '02A': [3, 4, 5, 6], '24X': [1,2,5,6], '14A': [2, 3, 4], '15A': [2, 3, 4, 5, 6], '15X': [1], '04X': [1, 2, 3, 4], '35X': [1, 2, 3],
59
+ '14X': [1, 5, 6], '13X': [1, 4, 5, 6], '13A': [2, 3], 'HexNAc6S': [1, 2, 3, 4, 5, 6]}},
60
+ 'HexNAcOS': {'mass': {'04A': 139.9779, '24A': 139.9779, '35A': 153.9936, '03A': 169.9885, '25A': 184.0041, '25X': 99.0321,
61
+ '02A': 199.9991, '24X': 223.0151, '14A': 131.058244, '15A': 255.041259, '15X': 27.994941, '04X': 143.0583, '35X': 129.0426,
62
+ '14X': 151.977956, '13X': 181.988541, '13A': 101.047659, 'HexNAcOS': 283.0362},
63
+ 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6], '25X': [1, 2],
64
+ '02A': [3, 4, 5, 6], '24X': [1,2,5,6], '14A': [2, 3, 4], '15A': [2, 3, 4, 5, 6], '15X': [1], '04X': [1, 2, 3, 4], '35X': [1, 2, 3],
65
+ '14X': [1, 5, 6],'13X': [1, 4, 5, 6], '13A': [2, 3], 'HexNAcOS': [1, 2, 3, 4, 5, 6]}},
66
+ 'Hex6S': {'mass': {'02X': 42.0106, '03X': 72.0211, '15X': 27.9949, '13A': 60.0211, '24A': 60.0211, '04A': 139.9779, '35A': 153.9936, '25A': 184.0041,
67
+ '02A': 199.9991, '03A': 153.9936, '15A': 214.014659, '24X': 181.9885, '04X': 102.0317, '35X': 88.016, 'Hex6S': 242.0096},
68
+ 'atoms': {'02X': [1, 2], '03X': [1, 2, 3], '15X': [1], '13A': [2, 3], '24A': [3, 4], '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6],
69
+ '02A': [3, 4, 5, 6], '03A': [4, 5, 6], '15A': [2, 3, 4, 5, 6], '24X': [1, 2, 5, 6], '04X': [1, 2, 3, 4], '35X': [1, 2, 3], 'Hex6S': [1, 2, 3, 4, 5, 6]}},
70
+ 'Hex3S': {'mass': {'02X': 42.0106, '03X': 151.9779, '15X': 27.9949, '13A': 139.9779, '24A': 139.9779, '04A': 60.0211, '35A': 74.0368, '25A': 184.0041,
71
+ '02A': 199.9991, '03A': 74.0368, '15A': 214.014659, '24X': 102.0317, '04X': 181.9885, '35X': 167.9728, 'Hex3S': 242.0096},
72
+ 'atoms': {'02X': [1, 2], '03X': [1, 2, 3], '15X': [1], '13A': [2, 3], '24A': [3, 4], '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6],
73
+ '02A': [3, 4, 5, 6], '03A': [4, 5, 6], '15A': [2, 3, 4, 5, 6], '24X': [1, 2, 5, 6], '04X': [1, 2, 3, 4], '35X': [1, 2, 3], 'Hex3S': [1, 2, 3, 4, 5, 6]}},
74
+ 'HexOS': {'mass': {'02X': 42.0106, '03X': 151.9779, '15X': 27.9949, '13A': 139.9779, '24A': 139.9779, '04A': 139.9779, '35A': 153.9936, '25A': 184.0041,
75
+ '02A': 199.9991, '03A': 153.9936, '15A': 214.014659, '24X': 181.9885, '04X': 181.9885, '35X': 167.9728, 'HexOS': 242.0096},
76
+ 'atoms': {'02X': [1, 2], '03X': [1, 2, 3], '15X': [1], '13A': [2, 3], '24A': [3, 4], '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6],
77
+ '02A': [3, 4, 5, 6], '03A': [4, 5, 6], '15A': [2, 3, 4, 5, 6], '04X': [1, 2, 3, 4], '35X': [1, 2, 3], 'HexOS': [1, 2, 3, 4, 5, 6]}},
78
+ 'Man6P': {'mass': {'03X': 72.0211, '02X': 42.0106, '15X': 27.9949, '13A': 60.0211, '24A': 60.0211, '03A': 154.0031, '15A': 214.024159,
79
+ '04A': 139.9874, '35A': 154.0031, '25A': 184.0136, '02A': 200.0086, '24X': 181.998, '04X': 102.0317, '35X': 88.016, 'Man6P': 242.0191},
80
+ 'atoms': {'03X': [1, 2, 3], '02X': [1, 2], '15X': [1], '13A': [2, 3], '24A': [3, 4], '03A': [4, 5, 6], '15A': [2, 3, 4, 5, 6],
81
+ '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6], '02A': [3, 4, 5, 6], '24X': [1, 2, 5, 6], '04X': [1, 2, 3, 4], '35X': [1, 2, 3], 'Man6P': [1, 2, 3, 4, 5, 6]}},
82
+ 'Hex6P': {'mass': {'03X': 72.0211, '02X': 42.0106, '15X': 27.9949, '13A': 60.0211, '24A': 60.0211, '03A': 154.0031, '15A': 214.024159,
83
+ '04A': 139.9874, '35A': 154.0031, '25A': 184.0136, '02A': 200.0086, '24X': 181.998, '04X': 102.0317, '35X': 88.016, 'Hex6P': 242.0191},
84
+ 'atoms': {'03X': [1, 2, 3], '02X': [1, 2], '15X': [1], '13A': [2, 3], '24A': [3, 4], '03A': [4, 5, 6], '15A': [2, 3, 4, 5, 6],
85
+ '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6], '02A': [3, 4, 5, 6], '24X': [1, 2, 5, 6], '04X': [1, 2, 3, 4], '35X': [1, 2, 3], 'Hex6P': [1, 2, 3, 4, 5, 6]}},
113
86
  'Global': {'mass': {'H2O': -18.0105546, 'CH2O': -30.0106, 'C2H2O': -42.0106, 'CO2': -43.9898, 'C2H4O2': -60.0211,
114
- 'SO4': -79.9568, 'C3H8O4': -108.0423, '+Acetate': +42.0106, '+Na': +22.989218}}
87
+ 'SO4': -79.9568, 'PO4': -79.9663, 'C3H8O4': -108.0423, '+Acetonitrile': +41.0519, '+Acetate': 59.013851,
88
+ '+Na': +22.989218, '+K': 38.963707}}
115
89
  }
116
90
 
117
91
  bond_type_helper = {1: ['bond', 'no_bond'], 2: ['red_bond', 'red_no_bond']}
118
- cut_type_dict = {'bond': 'Y', 'no_bond': 'Z', 'red_bond': 'C', 'red_no_bond': 'B', '13A': '13A', '24A': '24A',
119
- '04A': '04A', '35A': '35A', '03A': '03A', '25A': '25A', '02A': '02A', '02X': '02X', '04X': '04X'}
120
- A_cross_rings = {'13A', '24A', '04A', '35A', '03A', '25A', '02A'}
121
- X_cross_rings = {'02X', '04X'}
92
+ cut_type_dict = {'bond': 'Y', 'no_bond': 'Z', 'red_bond': 'C', 'red_no_bond': 'B',
93
+ '13A': '13A', '14A': '14A', '15A': '15A', '24A': '24A', '04A': '04A', '35A': '35A', '03A': '03A', '25A': '25A', '02A': '02A',
94
+ '02X': '02X', '03X': '03X', '04X': '04X', '12X': '12X', '13X': '13X', '14X': '14X', '15X': '15X', '24X': '24X', '35X': '35X'}
95
+ A_cross_rings = {c for c in cut_type_dict if c[-1] == 'A'}
96
+ X_cross_rings = {c for c in cut_type_dict if c[-1] == 'X'}
122
97
  ranks = ['Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon', 'Zeta', 'Eta']
123
98
 
124
99
 
@@ -158,35 +133,27 @@ def glycan_to_graph_monos(glycan):
158
133
  bond_proc = min_process_glycans([glycan])[0]
159
134
  mono_proc = bond_proc[::2]
160
135
 
161
- all_mask_dic = {k: bond_proc[k] for k in range(len(bond_proc))}
162
- mono_mask_dic = {k: mono_proc[k] for k in range(len(mono_proc))}
136
+ all_mask_dic = {k: v for k, v in enumerate(bond_proc)}
137
+ mono_mask_dic = {k: v for k, v in enumerate(mono_proc)}
163
138
  for k, j in mono_mask_dic.items():
164
139
  glycan = glycan.replace(j, str(k), 1)
165
140
  glycan = ''.join(re.split(r'[()]', glycan)[::2])
166
141
  adj_matrix = np.zeros((len(mono_proc), len(mono_proc)), dtype = int)
167
142
 
168
143
  for k in range(len(mono_mask_dic)):
169
- for j in range(len(mono_mask_dic)):
170
- if k < j:
171
- if k >= 100:
172
- adjustment = 2
173
- elif k >= 10:
174
- adjustment = 1
175
- else:
176
- adjustment = 0
177
- k_idx, j_idx = glycan.find(str(k), k),glycan.find(str(j), j)
178
- glycan_part = glycan[k_idx+1:j_idx]
179
-
144
+ for j in range(k + 1, len(mono_mask_dic)):
145
+ adjustment = 2 if k >= 100 else 1 if k >= 10 else 0
146
+ k_idx, j_idx = glycan.find(str(k), k),glycan.find(str(j), j)
147
+ glycan_part = glycan[k_idx+1:j_idx]
148
+ if evaluate_adjacency_monos(glycan_part, adjustment):
149
+ adj_matrix[k, j] = 1
150
+ continue
151
+ if len(bracket_removal(glycan_part)) <= 1+adjustment:
152
+ glycan_part = bracket_removal(glycan_part)
180
153
  if evaluate_adjacency_monos(glycan_part, adjustment):
181
154
  adj_matrix[k, j] = 1
182
155
  continue
183
156
 
184
- if len(bracket_removal(glycan_part)) <= 1+adjustment:
185
- glycan_part = bracket_removal(glycan_part)
186
- if evaluate_adjacency_monos(glycan_part, adjustment):
187
- adj_matrix[k, j] = 1
188
- continue
189
-
190
157
  return mono_mask_dic, adj_matrix, all_mask_dic
191
158
 
192
159
 
@@ -200,41 +167,29 @@ def create_edge_labels(gr, all_dict):
200
167
  | :-
201
168
  | Returns a dict mapping each gr edge to its bond label
202
169
  """
203
- edge_dict = {}
204
- for e in gr.edges:
205
- edge_dict[e] = {'bond_label': all_dict[(e[0]*2)+1]}
206
-
207
- return edge_dict
170
+ return {(e[0], e[1]): {'bond_label': all_dict[(e[0]*2)+1]} for e in gr.edges}
208
171
 
209
172
 
210
- def mono_graph_to_nx(mono_graph, directed = True, libr = None):
173
+ def mono_graph_to_nx(mono_graph, directed = True):
211
174
  """Modified version of glycan_to_nxGraph, converts a mono adjacency matrix into a networkx graph, adds bonds as edge labels, and terminal,reducing end labels\n
212
175
  | Arguments:
213
176
  | :-
214
177
  | mono_graph (string): output of glycan_to_graph_monos
215
- | directed (bool): if True, creates a directed graph with bonds pointing from leaf to reducing end ; default:True
216
- | libr (list): library of monosaccharides; if you have one use it, otherwise a comprehensive lib will be used\n
178
+ | directed (bool): if True, creates a directed graph with bonds pointing from leaf to reducing end ; default:True\n
217
179
  | Returns:
218
180
  | :-
219
181
  | Returns networkx graph object of a glycan made up of only monosaccharides
220
182
  """
221
- if libr is None:
222
- libr = lib
223
- if directed:
224
- template = nx.DiGraph
225
- else:
226
- template = nx.Graph
227
- node_dict_mono = mono_graph[0]
228
- all_dict = mono_graph[2]
183
+ template = nx.DiGraph if directed else nx.Graph
184
+ node_dict_mono, adj_matrix, all_dict = mono_graph
229
185
 
230
186
  if len(node_dict_mono) > 1:
231
- gr = nx.from_numpy_array(mono_graph[1], create_using = template)
187
+ gr = nx.from_numpy_array(adj_matrix, create_using = template)
232
188
  for n1, n2, d in gr.edges(data = True):
233
189
  del d['weight']
234
190
  else:
235
191
  gr = nx.Graph()
236
192
  gr.add_node(0)
237
- nx.set_node_attributes(gr, {k: lib[v] for k,v in node_dict_mono.items()}, 'labels')
238
193
  nx.set_node_attributes(gr, node_dict_mono, 'string_labels')
239
194
  nx.set_node_attributes(gr, {k: 'terminal' if gr.degree[k] == 1 else 'internal' for k in gr.nodes()}, 'termini')
240
195
  nx.set_node_attributes(gr, {max(gr.nodes): 2}, 'reducing_end')
@@ -362,37 +317,6 @@ def get_terminals(subg, present_breakages, root_node):
362
317
  return terminals
363
318
 
364
319
 
365
- def calculate_mass(nx_mono):
366
- """Calculates the mass of a networkx glycan\n
367
- | Arguments:
368
- | :-
369
- | nx_mono (networkx_object): the original monosaccharide only graph\n
370
- | Returns:
371
- | :-
372
- | Returns a float of the monoisotopic mass of the glycan or fragment in negative mode
373
- """
374
- comp = nx.get_node_attributes(nx_mono, 'string_labels')
375
- mono_mods = nx.get_node_attributes(nx_mono, 'mod_labels')
376
- atom_dict = nx.get_node_attributes(nx_mono, 'atomic_mod_dict')
377
- all_atom_mods = Counter([m for d in [v.values() for v in atom_dict.values()] for m in d if m != 0])
378
- reducing_end = nx.get_node_attributes(nx_mono, 'reducing_end')
379
-
380
- mass = sum([mono_attributes[v]['mass'][v] for k, v in comp.items() if k not in mono_mods])-1.0078
381
- mass += sum([mono_attributes[comp[k]]['mass'][v] for k, v in mono_mods.items() if v in mono_attributes[comp[k]]['mass']])
382
- mass += sum([mono_attributes[comp[k]]['mass'][v] for k, v in mono_mods.items() if v not in mono_attributes[comp[k]]['mass']])
383
- mass += -18.0105546*all_atom_mods['no_bond']
384
- mass += +18.0105546*all_atom_mods['red_bond']
385
-
386
- if reducing_end:
387
- if mono_mods:
388
- reducing_end_node = next(iter(reducing_end))
389
- if mono_mods[reducing_end_node] == comp[reducing_end_node]:
390
- mass += 18.0105546+(2*1.0078)
391
- else:
392
- mass += 18.0105546
393
- return mass
394
-
395
-
396
320
  def atom_mods_init(subg, present_breakages, terminals, terminal_labels):
397
321
  """Creates the initial nested dict of each terminal node with floating bonds labelled 1 and the reducing end floating bond labelled 2\n
398
322
  | Arguments:
@@ -407,6 +331,7 @@ def atom_mods_init(subg, present_breakages, terminals, terminal_labels):
407
331
  """
408
332
  atomic_mod_dict = {}
409
333
  for terminal, terminal_label in zip(terminals, terminal_labels):
334
+ terminal_label = map_to_basic(terminal_label, obfuscate_ptm = False)
410
335
  atomic_mod_dict[terminal] = {y: 0 for y in mono_attributes[terminal_label]['atoms'][terminal_label]}
411
336
 
412
337
  for bond, bond_label in present_breakages.items():
@@ -415,10 +340,7 @@ def atom_mods_init(subg, present_breakages, terminals, terminal_labels):
415
340
  atomic_mod_dict[bond[0]][red_breakage] = 2
416
341
  else:
417
342
  # Current improvised way of providing '?' support
418
- try:
419
- breakage = int(bond_label[-1])
420
- except:
421
- breakage = random.choice([2, 3, 4, 5, 6])
343
+ breakage = int(bond_label[-1]) if bond_label[-1].isdigit() else random.choice([2, 3, 4, 5, 6])
422
344
  atomic_mod_dict[bond[1]][breakage] = 1
423
345
  return atomic_mod_dict
424
346
 
@@ -439,13 +361,14 @@ def get_mono_mods_list(root_node, subg, terminals, terminal_labels, nx_edge_dict
439
361
  """
440
362
  terminal_mods = []
441
363
  for node, label in zip(terminals, terminal_labels):
364
+ basic_label = map_to_basic(label, obfuscate_ptm = False)
442
365
  if node == root_node:
443
366
  valid_A_frags = get_valid_A_frags(subg, node, label, nx_edge_dict)
444
367
  terminal_mods.append(valid_A_frags)
445
368
  elif subg.degree()[node] > 1:
446
369
  terminal_mods.append([label])
447
370
  else:
448
- terminal_mods.append([x for x in mono_attributes[label]['mass'] if x in X_cross_rings or x == label])
371
+ terminal_mods.append([x for x in mono_attributes[basic_label]['mass'] if x in X_cross_rings or x == label])
449
372
  return terminal_mods
450
373
 
451
374
 
@@ -462,13 +385,13 @@ def get_valid_A_frags(subg, node, label, nx_edge_dict):
462
385
  | Returns a list of names of possible modifications
463
386
  """
464
387
  valid_A_mods_list = []
465
- A_mods_list = [x for x in mono_attributes[label]['mass'] if x in A_cross_rings or x == label]
466
- node_in_edges = [x for x in subg.in_edges(node)]
467
- for mod in A_mods_list:
468
- if not set([int(nx_edge_dict[bond]['bond_label'][-1]) for bond in node_in_edges if nx_edge_dict[bond]['bond_label'][-1] != '?']) <= set(mono_attributes[label]['atoms'][mod]):
469
- pass
470
- else:
471
- valid_A_mods_list.append(mod)
388
+ idx_label = map_to_basic(label, obfuscate_ptm = False)
389
+ A_mods_list = [x for x in mono_attributes[idx_label]['mass'] if x in A_cross_rings or x == label]
390
+ bond_numbers = set(int(nx_edge_dict[bond]['bond_label'][-1])
391
+ for bond in subg.in_edges(node)
392
+ if nx_edge_dict[bond]['bond_label'][-1].isdigit())
393
+ valid_A_mods_list = [mod for mod in A_mods_list
394
+ if bond_numbers <= set(mono_attributes[idx_label]['atoms'][mod])]
472
395
  return valid_A_mods_list
473
396
 
474
397
 
@@ -483,8 +406,8 @@ def create_dict_perms(dicty):
483
406
  """
484
407
  dict_perms = []
485
408
  modded_atoms = [k for k, v in dicty.items() if v in bond_type_helper]
486
- for mod_prod in product(*[bond_type_helper[dicty[y]] for y in modded_atoms]):
487
- dict_perms.append({**dicty, **dict(zip(modded_atoms, mod_prod))})
409
+ perms = product(*(bond_type_helper[dicty[y]] for y in modded_atoms))
410
+ dict_perms = [{**dicty, **dict(zip(modded_atoms, perm))} for perm in perms]
488
411
  return dict_perms
489
412
 
490
413
 
@@ -503,7 +426,8 @@ def generate_mod_permutations(terminals, terminal_labels, mono_mods_list, atomic
503
426
  """
504
427
  all_terminal_perms, all_mono_mods = [], []
505
428
  for node, label, mono_mods in zip(terminals, terminal_labels, mono_mods_list):
506
- possible_node_atoms = [{k: v for k, v in atomic_mod_dict_subg[node].items() if k in mono_attributes[label]['atoms'][mod]} for mod in mono_mods]
429
+ label = map_to_basic(label, obfuscate_ptm = False)
430
+ possible_node_atoms = [{k: v for k, v in atomic_mod_dict_subg[node].items() if k in mono_attributes[label]['atoms'][map_to_basic(mod, obfuscate_ptm = False)]} for mod in mono_mods]
507
431
  all_atom_dict_perms, all_mono_mod_perms = [], []
508
432
  for i, atom_dict in enumerate(possible_node_atoms):
509
433
  dict_perms = create_dict_perms(atom_dict)
@@ -528,22 +452,14 @@ def precalculate_mod_masses(all_mono_mods, all_terminal_perms, terminal_labels,
528
452
  | (2) a list of all possible mass combinations for each bond fragmentation combination
529
453
  | (3) a list of masses corresponding to each of the global mods
530
454
  """
531
- all_mono_mod_masses = []
532
- for node, label in zip(all_mono_mods, terminal_labels):
533
- node_mod_masses = []
534
- for mod in node:
535
- mass = mono_attributes[label]['mass'][mod]
536
- node_mod_masses.append(mass)
537
- all_mono_mod_masses.append(node_mod_masses)
455
+ all_mono_mod_masses = [[mono_attributes[map_to_basic(label, obfuscate_ptm = False)]['mass'][map_to_basic(mod, obfuscate_ptm = False)] for mod in mods] for mods, label in zip(all_mono_mods, terminal_labels)]
538
456
 
539
457
  all_atom_dict_masses = []
540
458
  for node in all_terminal_perms:
541
459
  node_dict_masses = []
542
460
  for mod in node:
543
461
  present_atom_mods = [x for x in mod.values() if x in ['no_bond', 'red_bond']]
544
- mass = -18.0105546*len([x for x in present_atom_mods if x == 'no_bond'])
545
- mass += +18.0105546*len([x for x in present_atom_mods if x == 'red_bond'])
546
- node_dict_masses.append(mass)
462
+ node_dict_masses.append(sum(-18.0105546 if v == 'no_bond' else 18.0105546 for v in present_atom_mods))
547
463
  all_atom_dict_masses.append(node_dict_masses)
548
464
 
549
465
  global_mods_mass = [mono_attributes['Global']['mass'][x] for x in global_mods[1:]]
@@ -552,7 +468,7 @@ def precalculate_mod_masses(all_mono_mods, all_terminal_perms, terminal_labels,
552
468
 
553
469
 
554
470
  def preliminary_calculate_mass(mono_mods_mass, atom_mods_mass, global_mods_mass, terminals,
555
- inner_mass, true_root_node, label_mass, mode):
471
+ inner_mass, true_root_node, label_mass, charge):
556
472
  """Determines the mass of every permutation of monosaccharide, atom, and global modification\n
557
473
  | Arguments:
558
474
  | :-
@@ -563,30 +479,21 @@ def preliminary_calculate_mass(mono_mods_mass, atom_mods_mass, global_mods_mass,
563
479
  | inner_mass (float): total mass of non-terminal nodes in subgraph
564
480
  | true_root_node (int): the node label corresponding to the root of the parent glycan
565
481
  | label_mass (float): mass of the glycan label or reducing end modification
566
- | mode (string): the mode in which the mass spectrometer was run, 'negative' or 'positive'\n
482
+ | charge (int): assumed charge of glycan\n
567
483
  | Returns:
568
484
  | :-
569
485
  | Returns a list every single mass of each modification combination for each cross ring combination
570
486
  """
571
- if mode == 'negative':
572
- mode_mass = -1.0078
573
- elif mode == 'positive':
574
- mode_mass = +1.0078
487
+ mode_mass = -1.0078 if charge < 0 else 1.0078
575
488
  masses_list = []
576
- root_presence = False
577
- if true_root_node in terminals:
578
- root_presence = True
579
- root_node_idx = terminals.index(true_root_node)
489
+ root_presence = true_root_node in terminals
490
+ root_node_idx = terminals.index(true_root_node) if root_presence else -1
580
491
  for mod_combo, atom_combo in zip(mono_mods_mass, atom_mods_mass):
581
- mass = inner_mass+mode_mass
582
- mass += sum(mod_combo)+sum(atom_combo)
583
- if root_presence:
584
- if mod_combo[root_node_idx] not in A_cross_rings:
585
- mass += 18.0105546+label_mass
492
+ mass = inner_mass + mode_mass + sum(mod_combo) + sum(atom_combo)
493
+ if root_presence and mod_combo[root_node_idx] not in A_cross_rings:
494
+ mass += 18.0105546 + label_mass
586
495
  masses_list.append(mass)
587
- for mod_mass in global_mods_mass:
588
- modded_mass = mass + mod_mass
589
- masses_list.append(modded_mass)
496
+ masses_list.extend([mass + mod_mass for mod_mass in global_mods_mass])
590
497
  return masses_list
591
498
 
592
499
 
@@ -602,34 +509,33 @@ def add_to_subgraph_fragments(subgraph_fragments, nx_mono_list, mass_list):
602
509
  | Returns an updated subgraph_fragments dict
603
510
  """
604
511
  for nx_mono, mass in zip(nx_mono_list, mass_list):
605
- if mass not in subgraph_fragments:
606
- subgraph_fragments[mass] = [nx_mono]
607
- else:
608
- subgraph_fragments[mass].append(nx_mono)
609
-
512
+ subgraph_fragments.setdefault(mass, []).append(nx_mono)
610
513
  return subgraph_fragments
611
514
 
612
515
 
613
- def get_global_mods(subg, node_dict, mode):
516
+ def get_global_mods(subg, node_dict, charge):
614
517
  """Returns the valid list of global modifications for a given subgraph\n
615
518
  | Arguments:
616
519
  | :-
617
520
  | subg (networkx_object): a subgraph
618
521
  | node_dict (dict): a dictionary relating the integer label of each node with the monosaccharide it represents\n
619
- | mode (string): the mode in which the mass spectrometer was run, 'negative' or 'positive'\n
522
+ | charge (int): the assumed charge of the glycan\n
620
523
  | Returns:
621
524
  | :-
622
525
  | Returns a a list of modification names
623
526
  """
624
527
  global_mods = sorted([x for x in mono_attributes['Global']['mass']])
625
- if not any(k in [node_dict[x] for x in subg.nodes()] for k in ['Neu5Ac', 'Neu5Gc', 'GlcA', 'HexA', 'Kdn']):
528
+ node_labels = ''.join(node_dict[x] for x in subg.nodes())
529
+ if not any(k in node_labels for k in ['Neu5Ac', 'Neu5Gc', 'GlcA', 'HexA', 'Kdn']):
626
530
  global_mods.remove('CO2')
627
- if 'S' not in ''.join([node_dict[x] for x in subg.nodes()]):
531
+ if 'S' not in node_labels:
628
532
  global_mods.remove('SO4')
629
- if mode == 'negative':
630
- global_mods.remove('+Na')
631
- if mode == 'positive':
632
- global_mods.remove('+Acetate')
533
+ if 'P' not in node_labels:
534
+ global_mods.remove('PO4')
535
+ positive_mods = {'+Na', '+K'}
536
+ negative_mods = {'+Acetate', '+Acetonitrile'}
537
+ mods_to_remove = positive_mods if charge < 0 else negative_mods
538
+ global_mods = [mod for mod in global_mods if mod not in mods_to_remove]
633
539
  return global_mods
634
540
 
635
541
 
@@ -643,9 +549,7 @@ def mod_count(node_mod, global_mod):
643
549
  | :-
644
550
  | Returns a sum of modifications
645
551
  """
646
- c = 0
647
- if global_mod is not None:
648
- c += 1
552
+ c = 1 if global_mod is not None else 0
649
553
  c += sum([1 for k in node_mod[0] if k in A_cross_rings or k in X_cross_rings])
650
554
  c += sum([1 for k in unwrap([list(n.values()) for n in node_mod[1]]) if isinstance(k, str)])
651
555
  return c
@@ -656,7 +560,7 @@ def extend_masses(fragment_masses, charge):
656
560
  | Arguments:
657
561
  | :-
658
562
  | fragment_masses (list): a list of observed masses to be searched for possible fragments
659
- | charge (int): the charge to use when calcualting multiply charged masses\n
563
+ | charge (int): the charge to use when calculating multiply charged masses\n
660
564
  | Returns:
661
565
  | :-
662
566
  | Returns a list containing both the input masses and the other masses at which to search to assign multiply charged fragments to the inital masses
@@ -665,7 +569,7 @@ def extend_masses(fragment_masses, charge):
665
569
  return fragment_masses
666
570
  modifier = np.sign(charge)
667
571
  for z in range(2, abs(charge)+1):
668
- charged_masses = fragment_masses + [(k*z)-(z*modifier-modifier) for k in fragment_masses]
572
+ charged_masses = fragment_masses + [(k*z) - (z - 1.0078)*modifier for k in fragment_masses]
669
573
  return charged_masses
670
574
 
671
575
 
@@ -682,16 +586,15 @@ def annotate_subgraph(subg,node_mod,global_mod,terminals):
682
586
  | Returns a copy of the input subgraph with networkx node attributes describing the modifications
683
587
  """
684
588
  mod_subg = subg.copy()
685
- mono_mods_dict = dict(zip(terminals, node_mod[0]))
686
- nx.set_node_attributes(mod_subg, mono_mods_dict, 'mod_labels')
687
- atoms_mods_dict = dict(zip(terminals, node_mod[1]))
688
- nx.set_node_attributes(mod_subg, atoms_mods_dict, 'atomic_mod_dict')
589
+ nx.set_node_attributes(mod_subg, dict(zip(terminals, node_mod[0])), 'mod_labels')
590
+ nx.set_node_attributes(mod_subg, dict(zip(terminals, node_mod[1])), 'atomic_mod_dict')
689
591
  if global_mod:
690
592
  nx.set_node_attributes(mod_subg, [global_mod], 'global_mod')
691
593
  return mod_subg
692
594
 
693
595
 
694
- def generate_atomic_frags(nx_mono, max_cleavages = 3, fragment_masses = None, threshold=None, label_mass=2.0156, charge = -1, mode = 'negative'):
596
+ def generate_atomic_frags(nx_mono, max_cleavages = 3, fragment_masses = [],
597
+ threshold = 0.5, label_mass = 2.0156, charge = -1):
695
598
  """Calculates the graph and mass of all possible fragments of the input\n
696
599
  | Arguments:
697
600
  | :-
@@ -700,8 +603,7 @@ def generate_atomic_frags(nx_mono, max_cleavages = 3, fragment_masses = None, th
700
603
  | fragment_masses (list): all masses which are to be annotated with a fragment name
701
604
  | threshold (float): the range around the observed mass in which constrain potential fragments
702
605
  | label_mass (float): mass of the glycan label or reducing end modification; default:2.0156
703
- | charge (int): the maximum possible charge on the fragments to be matched; default:-1
704
- | mode (string): the mode in which the mass spectrometer was run, 'negative' or 'positive'\n
606
+ | charge (int): the maximum possible charge on the fragments to be matched; default:-1\n
705
607
  | Returns:
706
608
  | :-
707
609
  | Returns a dict of lists of networkx subgraphs
@@ -712,32 +614,33 @@ def generate_atomic_frags(nx_mono, max_cleavages = 3, fragment_masses = None, th
712
614
  true_root_node = [v for v, d in nx_mono.out_degree() if d == 0][0]
713
615
  nx_edge_dict = {(node[0], node[1]): node[2] for node in nx_mono.edges(data = True)}
714
616
  node_dict = nx.get_node_attributes(nx_mono, 'string_labels')
617
+ node_dict_basic = {k: map_to_basic(v, obfuscate_ptm = False) for k, v in node_dict.items()}
715
618
  subgraph_fragments = {}
716
- subgraphs = enumerate_subgraphs(nx_mono)
717
- subgraphs.append(nx_mono)
619
+ subgraphs = enumerate_subgraphs(nx_mono) + [nx_mono]
620
+ max_global_mass = max(mono_attributes['Global']['mass'].values())
718
621
  for subg in subgraphs:
719
622
  present_breakages = get_broken_bonds(subg, nx_mono, nx_edge_dict)
720
623
  root_node = [v for v, d in subg.out_degree() if d == 0][0]
721
624
  terminals = get_terminals(subg, present_breakages, root_node)
722
- inner_mass = sum([mono_attributes[node_dict[m]]['mass'][node_dict[m]] for m in subg.nodes() if m not in terminals])
723
- max_mass = inner_mass + sum([mono_attributes[node_dict[m]]['mass'][node_dict[m]] for m in terminals]) + 18.0105546*len(terminals)
724
- max_mass += mono_attributes['Global']['mass']['+Acetate']
725
- if max_mass < min_mass:
625
+ inner_mass = sum([mono_attributes[node_dict_basic[m]]['mass'][node_dict_basic[m]] for m in subg.nodes() if m not in terminals])
626
+ max_mass = inner_mass + sum([mono_attributes[node_dict_basic[m]]['mass'][node_dict_basic[m]] for m in terminals]) + 18.0105546*len(terminals)
627
+ max_mass += max_global_mass
628
+ if max_mass < min_mass - threshold:
726
629
  continue
727
- terminal_labels = [node_dict[x] for x in terminals]
728
- global_mods = [None] + get_global_mods(subg, node_dict,mode)
630
+ terminal_labels = [node_dict_basic[x] for x in terminals]
631
+ global_mods = [None] + get_global_mods(subg, node_dict,charge)
729
632
  atomic_mod_dict_subg = atom_mods_init(subg, present_breakages, terminals, terminal_labels)
730
633
  mono_mods_list = get_mono_mods_list(root_node, subg, terminals, terminal_labels, nx_edge_dict)
731
634
  mono_mod_perms, atom_dict_perms = generate_mod_permutations(terminals, terminal_labels, mono_mods_list, atomic_mod_dict_subg)
732
635
  permutation_list = product(zip(product(*mono_mod_perms), product(*atom_dict_perms)), global_mods)
733
636
  mono_masses, atom_masses, global_masses = precalculate_mod_masses(mono_mod_perms, atom_dict_perms, terminal_labels, global_mods)
734
- initial_masses = preliminary_calculate_mass(mono_masses, atom_masses, global_masses, terminals, inner_mass, true_root_node, label_mass, mode)
637
+ initial_masses = preliminary_calculate_mass(mono_masses, atom_masses, global_masses, terminals, inner_mass, true_root_node, label_mass, charge)
735
638
  fragment_arr = np.array(charge_masses)
736
639
  for mass, (node_mod, global_mod) in zip(initial_masses, permutation_list):
737
640
  if not (abs(fragment_arr - mass) < threshold).any():
738
641
  continue
739
642
  if (m := mod_count(node_mod, global_mod)) <= max_cleavages:
740
- if m > 1 and global_mod in ['+Acetate','+Na']:
643
+ if m > 1 and global_mod in ['+Acetate', '+Acetonitrile', '+Na', '+K']:
741
644
  continue
742
645
  annotated_subg = annotate_subgraph(subg,node_mod,global_mod,terminals)
743
646
  annotated_subg_mass = round(mass, 5)
@@ -760,7 +663,8 @@ def rank_chains(nx_mono):
760
663
  leaf_chains = []
761
664
  for og_leaf in og_leaves:
762
665
  leaf_chains.append(nx.shortest_path(nx_mono, source = og_leaf))
763
- main_chains = sorted([branch_path[og_root] for branch_path in leaf_chains], key = lambda x: sum([mono_attributes[node_dict[n]]['mass'][node_dict[n]] for n in x]), reverse = True)
666
+ main_chains = sorted([branch_path[og_root] for branch_path in leaf_chains],
667
+ key = lambda x: sum([mono_attributes[map_to_basic(node_dict[n], obfuscate_ptm = False)]['mass'][map_to_basic(node_dict[n], obfuscate_ptm = False)] for n in x]), reverse = True)
764
668
  return zip(ranks, main_chains)
765
669
 
766
670
 
@@ -780,21 +684,23 @@ def domon_costello_to_node_labels(fragment, chain_rank):
780
684
  global_mod = None
781
685
  post_mono = None
782
686
  for cut in fragment:
783
- if cut[0] == 'M':
687
+ if cut.startswith('M'):
784
688
  global_mod = cut.split('_')[-1]
785
689
  continue
786
- split_cut = cut.split('_')
787
- chain = chain_rank[split_cut[2]]
788
- if split_cut[0][-1] in {'Y', 'Z'}:
789
- mono = chain[::-1][int(split_cut[1])]
790
- elif split_cut[0][-1] == 'X':
791
- mono = chain[::-1][int(split_cut[1])-1]
792
- elif split_cut[0][-1] in {'B', 'C'}:
793
- mono = chain[int(split_cut[1])]
794
- post_mono = chain[int(split_cut[1])-1]
795
- elif split_cut[0][-1] == 'A':
796
- mono = chain[int(split_cut[1])-1]
797
- skelly_dict[mono] = split_cut[0]
690
+ cut_type, cut_num, chain_label = cut.split('_')
691
+ cut_type_last_char = cut_type[-1]
692
+ cut_num = int(cut_num)
693
+ chain = chain_rank[chain_label]
694
+ if cut_type_last_char in 'YZ':
695
+ mono = chain[::-1][cut_num]
696
+ elif cut_type_last_char == 'X':
697
+ mono = chain[::-1][cut_num-1]
698
+ elif cut_type_last_char in 'BC':
699
+ mono = chain[cut_num]
700
+ post_mono = chain[cut_num-1]
701
+ elif cut_type_last_char == 'A':
702
+ mono = chain[cut_num-1]
703
+ skelly_dict[mono] = cut_type
798
704
  return skelly_dict, post_mono, global_mod
799
705
 
800
706
 
@@ -804,7 +710,7 @@ def node_labels_to_domon_costello(cuts, chain_rank, global_mods = {}):
804
710
  | :-
805
711
  | cuts (list): a list of tuples each containing the cleavage type, and related integer node labels
806
712
  | chain_rank (list): a list of tuples each containing rank and a list of integer node labels representing the glycan chain
807
- | global_mods (dict): the output of get_node_attributes(subg, 'global_mod') a dict containng integer node labels each pointing to a global mass change\n
713
+ | global_mods (dict): the output of get_node_attributes(subg, 'global_mod') a dict containing integer node labels each pointing to a global mass change\n
808
714
  | Returns:
809
715
  | :-
810
716
  | Returns a list containing all of the cleavages making up the fragment in Domon-Costello form
@@ -821,13 +727,11 @@ def node_labels_to_domon_costello(cuts, chain_rank, global_mods = {}):
821
727
  elif cut_type[-1] in {'X'}:
822
728
  cut_rank, cut_chain = [(rank, chain) for rank, chain in chain_rank if cut[1] in chain][0]
823
729
  cut_number = cut_chain[::-1].index(cut[1])+1
824
- dc_cuts.append('_'.join((cut_type, str(cut_number), cut_rank)))
730
+ dc_cuts.append(f"{cut_type}_{cut_number}_{cut_rank}")
825
731
  if global_mods:
826
- global_mods = list(global_mods.values())
827
- dc_cuts.append('_'.join(('M', global_mods[0][0])))
828
- if not dc_cuts:
829
- dc_cuts = ['M']
830
- return dc_cuts
732
+ global_mods = list(global_mods.values())[0][0]
733
+ dc_cuts.append(f"M_{global_mods}")
734
+ return dc_cuts or ['M']
831
735
 
832
736
 
833
737
  def find_main_chain(subgraph, leaves, root_node):
@@ -842,12 +746,10 @@ def find_main_chain(subgraph, leaves, root_node):
842
746
  | Returns a list of integer node labels representing the inputs main chain
843
747
  """
844
748
  bond_dict = nx.get_edge_attributes(subgraph, 'bond_label')
845
- main_chains = []
846
- for leaf in leaves:
847
- for path in nx.all_simple_paths(subgraph, source = leaf, target = root_node):
848
- main_chains.append(path)
849
- main_chain_len = max([len(x) for x in main_chains])
850
- main_chains = [k for k in main_chains if len(k) == main_chain_len]
749
+ all_paths = [path for leaf in leaves for path in nx.all_simple_paths(subgraph, source = leaf, target = root_node)]
750
+ main_chain = max(all_paths, key = len)
751
+ main_chain_len = len(main_chain)
752
+ main_chains = [k for k in all_paths if len(k) == main_chain_len]
851
753
  for i in range(main_chain_len)[::-1]:
852
754
  step = [c[i] for c in main_chains]
853
755
  if len(set(step)) == 1:
@@ -868,9 +770,8 @@ def subgraph_to_label_skeleton(sub_g):
868
770
  | Returns a list of integer node labels and branching brackets in the same order as the IUPAC condensed string
869
771
  """
870
772
  if len(sub_g.nodes) == 1:
871
- return [str(x) for x in sub_g.nodes]
872
- root_node = [k for k, v in sub_g.out_degree if v == 0]
873
- root_node = root_node[0]
773
+ return [str(next(iter(sub_g.nodes)))]
774
+ root_node = next(k for k, v in sub_g.out_degree if v == 0)
874
775
  leaves = [v for v, d in sub_g.in_degree() if d == 0]
875
776
  main_chain = []
876
777
  n_skelly = []
@@ -914,17 +815,15 @@ def label_skeleton_to_string(n_skelly, sub_g):
914
815
 
915
816
 
916
817
  def mono_frag_to_string(sub_g):
917
- """Converts a monsaccharide graph to a string\n
818
+ """Converts a monosaccharide graph to a string\n
918
819
  | Arguments:
919
820
  | :-
920
821
  | subg (networkx_object): a graph or subgraph of monosaccharides\n
921
822
  | Returns:
922
823
  | :-
923
- | Returns an IUPAC condesnsed representation of the input graph, in the case of fragment graphs it returns the closest canonical string representation
824
+ | Returns an IUPAC condensed representation of the input graph, in the case of fragment graphs it returns the closest canonical string representation
924
825
  """
925
- n_skelly = subgraph_to_label_skeleton(sub_g)
926
- glycan_string = label_skeleton_to_string(n_skelly, sub_g)
927
- return glycan_string
826
+ return label_skeleton_to_string(subgraph_to_label_skeleton(sub_g), sub_g)
928
827
 
929
828
 
930
829
  def domon_costello_to_fragIUPAC(glycan_string, fragment):
@@ -1017,6 +916,7 @@ def subgraphs_to_domon_costello(nx_mono, subgs):
1017
916
  """
1018
917
  ion_names = []
1019
918
  node_dict = nx.get_node_attributes(nx_mono, 'string_labels')
919
+ node_dict = {k: map_to_basic(v, obfuscate_ptm = False) for k, v in node_dict.items()}
1020
920
  chain_rank = list(rank_chains(nx_mono))
1021
921
 
1022
922
  for subg in subgs:
@@ -1032,31 +932,25 @@ def subgraphs_to_domon_costello(nx_mono, subgs):
1032
932
  cuts.append((atom_mod, cut_node[0], node))
1033
933
  if atom_mod in {'red_bond', 'red_no_bond'}:
1034
934
  cuts.append((atom_mod, node))
1035
- cross_rings = [(k, v) for k, v in mono_mod_dict.items() if (k, v) not in node_dict.items()]
1036
- for node, mod in cross_rings:
1037
- cuts.append((mod, node))
935
+ cross_rings = [(v, k) for k, v in mono_mod_dict.items() if (k, v) not in node_dict.items()]
936
+ cuts.extend(cross_rings)
1038
937
  dc_cuts = node_labels_to_domon_costello(cuts, chain_rank, global_mods = global_mods)
1039
938
  ion_names.append((dc_cuts))
1040
939
  return ion_names
1041
940
 
1042
941
 
1043
- def mass_match(dc_names, diffs, max_cleavages):
942
+ def priority_filter(dc_names, diffs):
1044
943
  """Filters Domon-Costello fragment names by number of cleavages and difference from observed mass\n
1045
944
  | Arguments:
1046
945
  | :-
1047
946
  | dc_names (list): a nested list of Domon-Costello fragment grouped by mass
1048
- | diffs (list): a nested list of mass differences between the masses of Domon-Costello fragments and the observed masses
1049
- | max_cleavages (int): the maximum number of permitted cleavages in a fragment\n
947
+ | diffs (list): a nested list of mass differences between the masses of Domon-Costello fragments and the observed masses\n
1050
948
  | Returns:
1051
949
  | :-
1052
- | Returns a list of Domon-Costello fragment names with the smallest mass difference from the observed mass out of those with fewest cleavages
950
+ | Returns a list of Domon-Costello fragment names sorted by number of cleavages and the observed mass difference
1053
951
  """
1054
- min_diff = 0.01
1055
- for num_cleavages in range(1, max_cleavages+1):
1056
- if any([len(k) == num_cleavages for k in dc_names]):
1057
- frags, frag_diffs = zip(*[(dc_names[k], diffs[k]) for k in range(len(dc_names)) if len(dc_names[k]) == num_cleavages])
1058
- return [frags[k] for k in np.where((np.array(frag_diffs) < min(frag_diffs)+min_diff) & (np.array(frag_diffs) > min(frag_diffs)-min_diff))[0].tolist()]
1059
- return []
952
+ sorted_frags = sorted(list(zip(dc_names, diffs)), key = lambda x:(len(x[0]), x[1]))
953
+ return [f[0] for f in sorted_frags]
1060
954
 
1061
955
 
1062
956
  def match_fragment_properties(subg_frags, mass, mass_threshold, charge):
@@ -1078,11 +972,11 @@ def match_fragment_properties(subg_frags, mass, mass_threshold, charge):
1078
972
  fragment_properties = []
1079
973
  modifier = np.sign(charge)
1080
974
  for z in range(1, abs(charge)+1):
1081
- charged_mass = (mass*z)-(z*modifier-modifier)
1082
- for k in subg_frags:
1083
- if abs(charged_mass-k) < mass_threshold:
1084
- for graph in subg_frags[k]:
1085
- fragment_properties.append((mass, k, abs(charged_mass-k), modifier*z, graph))
975
+ charged_mass = (mass*z) - (z - 1.0078)*modifier
976
+ for frag_mass, graphs in subg_frags.items():
977
+ if abs(charged_mass - frag_mass) < mass_threshold:
978
+ for graph in graphs:
979
+ fragment_properties.append((mass, frag_mass, abs(charged_mass - frag_mass), modifier*z, graph))
1086
980
  if fragment_properties:
1087
981
  return list(zip(*fragment_properties))
1088
982
  else:
@@ -1099,16 +993,10 @@ def observed_fragments_checker(possible_fragments, observed_fragments):
1099
993
  | :-
1100
994
  | Returns a list containing integers corresponding to the largest overlap each possible fragment had with all previously observed fragments
1101
995
  """
1102
- max_overlaps_seen = []
1103
- for cleavage_combo in possible_fragments:
1104
- seen_cleavage_overlaps = []
1105
- for obs in observed_fragments:
1106
- if not obs:
1107
- seen_cleavage_overlaps.append(0)
1108
- continue
1109
- seen_cleavage_overlaps.append(len(set(cleavage_combo) & set(obs[0])))
1110
- max_overlaps_seen.append(max(seen_cleavage_overlaps, default = 0))
1111
- return max_overlaps_seen
996
+ if observed_fragments and observed_fragments[0] and observed_fragments[0][0] and isinstance(observed_fragments[0][0], list):
997
+ observed_fragments = unwrap(observed_fragments)
998
+ sums = [sum(len(set(pf) & set(of)) for of in observed_fragments if of) for pf in possible_fragments]
999
+ return [sums[i] - 1 if 'M' in ''.join(f) else sums[i] for i, f in enumerate(possible_fragments)]
1112
1000
 
1113
1001
 
1114
1002
  def simplify_fragments(dc_names):
@@ -1128,17 +1016,16 @@ def simplify_fragments(dc_names):
1128
1016
  observed_frags.append([])
1129
1017
  elif len(possible_frags[0]) == 1:
1130
1018
  observed_frags.append([possible_frags[0]])
1131
- continue
1132
1019
  else:
1133
1020
  frag_options = [x for x in possible_frags if len(x) == len(possible_frags[0])]
1134
1021
  max_overlaps_seen = (observed_fragments_checker(frag_options, observed_frags))
1135
1022
  max_overlap_idx = np.argsort(max_overlaps_seen, kind = 'stable')[-1]
1136
1023
  observed_frags.append([frag_options[max_overlap_idx]])
1137
- continue
1138
1024
  return observed_frags
1139
1025
 
1140
1026
 
1141
- def CandyCrumbs(glycan_string, fragment_masses, mass_threshold, libr = None,
1027
+ @rescue_glycans
1028
+ def CandyCrumbs(glycan_string, fragment_masses, mass_threshold,
1142
1029
  max_cleavages = 3, simplify = True, charge = -1, label_mass = 2.0156,
1143
1030
  iupac = False, intensities = None):
1144
1031
  """Basic wrapper for the annotation of observed masses with correct nomenclature given a glycan\n
@@ -1147,7 +1034,6 @@ def CandyCrumbs(glycan_string, fragment_masses, mass_threshold, libr = None,
1147
1034
  | glycan_string (string): glycan in IUPAC-condensed format
1148
1035
  | fragment_masses (list): all masses which are to be annotated with a fragment name
1149
1036
  | mass_threshold (float): the maximum tolerated mass difference around each observed mass at which to include fragments
1150
- | libr (list): library of monosaccharides; if you have one use it, otherwise a comprehensive lib will be used
1151
1037
  | max_cleavages (int): maximum number of allowed concurrent fragmentations per mass; default:3
1152
1038
  | simplify (bool): whether to try condensing fragment options to the most likely option; default:True
1153
1039
  | charge (int): the charge state of the precursor ion (singly-charged, doubly-charged); default:-1
@@ -1157,28 +1043,23 @@ def CandyCrumbs(glycan_string, fragment_masses, mass_threshold, libr = None,
1157
1043
  | :-
1158
1044
  | Returns a list of tuples containing the observed mass and all of the possible fragment names within the threshold
1159
1045
  """
1160
- if libr is None:
1161
- libr = lib
1162
1046
  hit_dict = {}
1163
- mode = 'negative' if charge < 0 else 'positive'
1164
1047
  fragment_masses = sorted(fragment_masses)
1165
1048
  mono_graph = glycan_to_graph_monos(glycan_string)
1166
- nx_mono = mono_graph_to_nx(mono_graph, directed = True, libr = libr)
1167
- subg_frags = generate_atomic_frags(nx_mono, max_cleavages = max_cleavages, fragment_masses = fragment_masses, threshold = mass_threshold, label_mass = label_mass, charge = charge, mode = mode)
1049
+ nx_mono = mono_graph_to_nx(mono_graph, directed = True)
1050
+ subg_frags = generate_atomic_frags(nx_mono, max_cleavages = max_cleavages, fragment_masses = fragment_masses, threshold = mass_threshold, label_mass = label_mass, charge = charge)
1168
1051
  downstream_values = []
1169
1052
  for observed_mass in fragment_masses:
1170
1053
  fragment_properties = match_fragment_properties(subg_frags, observed_mass, mass_threshold, charge)
1171
1054
  dc_names = subgraphs_to_domon_costello(nx_mono, fragment_properties[-1])
1172
1055
  downstream_values.append((*fragment_properties,dc_names))
1173
- filtered_dc_names = [x[5] for x in downstream_values]
1056
+ filtered_dc_names = [priority_filter(x[5], x[2]) if x[0] else [] for x in downstream_values]
1174
1057
  if simplify:
1175
- filtered_dc_names = [mass_match(x[5], x[2],max_cleavages) for x in downstream_values]
1176
1058
  filtered_dc_names = simplify_fragments(filtered_dc_names)
1177
- filtered_dc_names = [x[:5] for x in filtered_dc_names]
1178
- for i,filtered_dc_names in enumerate(filtered_dc_names):
1179
- filtered_properties = list(zip(*downstream_values[i]))
1180
- if filtered_properties:
1181
- final_hits = [x for x in filtered_properties if x[5] in filtered_dc_names]
1059
+ for i,frag_dc_names in enumerate(filtered_dc_names):
1060
+ if frag_dc_names:
1061
+ filtered_properties = list(zip(*downstream_values[i]))
1062
+ final_hits = [[y for y in filtered_properties if y[5]==x][0] for x in frag_dc_names][:5]
1182
1063
  final_hits = [list(x) for x in list(zip(*final_hits))]
1183
1064
  hit_dict[fragment_masses[i]] = {'Theoretical fragment masses':final_hits[1],'Domon-Costello nomenclatures':final_hits[5], 'Fragment charges':final_hits[3]}
1184
1065
  if iupac: