CandyCrunch 0.3.0__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 (21) hide show
  1. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/CandyCrunch/analysis.py +194 -312
  2. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/CandyCrunch/prediction.py +66 -78
  3. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/CandyCrunch.egg-info/PKG-INFO +2 -2
  4. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/CandyCrunch.egg-info/requires.txt +2 -2
  5. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/PKG-INFO +2 -2
  6. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/README.md +1 -1
  7. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/setup.py +3 -3
  8. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/CandyCrunch/__init__.py +0 -0
  9. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/CandyCrunch/candycrunch.pt +0 -0
  10. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/CandyCrunch/cli.py +0 -0
  11. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/CandyCrunch/glycans.pkl +0 -0
  12. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/CandyCrunch/glytoucan_mapping.pkl +0 -0
  13. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/CandyCrunch/model.py +0 -0
  14. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/CandyCrunch/tester.py +0 -0
  15. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/CandyCrunch.egg-info/SOURCES.txt +0 -0
  16. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/CandyCrunch.egg-info/dependency_links.txt +0 -0
  17. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/CandyCrunch.egg-info/entry_points.txt +0 -0
  18. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/CandyCrunch.egg-info/top_level.txt +0 -0
  19. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/LICENSE +0 -0
  20. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/LICENSE.txt +0 -0
  21. {CandyCrunch-0.3.0 → CandyCrunch-0.4.0}/setup.cfg +0 -0
@@ -10,119 +10,88 @@ 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
13
+ from glycowork.glycan_data.loader import unwrap
14
14
  from glycowork.motif.processing import (bracket_removal,
15
- min_process_glycans)
16
- try:
17
- from glycowork.glycan_data.stats import cohen_d
18
- except ModuleNotFoundError:
19
- from glycowork.motif.processing import cohen_d
15
+ min_process_glycans, rescue_glycans)
16
+ from glycowork.motif.tokenization import map_to_basic
17
+ from glycowork.glycan_data.stats import cohen_d
20
18
 
21
19
  from scipy.stats import ttest_ind
22
20
  from statsmodels.stats.multitest import multipletests
23
21
 
24
- mono_attributes = {'Gal': {'mass': {'03X': 72.0211, '02X': 42.0105, '15X': 27.9949, '13A': 60.0211, '24A': 60.0211,
25
- '04A': 60.0211, '35A': 74.0368, '25A': 104.0473, '02A': 120.0423, 'Gal': 162.0528},
26
- 'atoms': {'03X': [1, 2, 3], '02X': [1, 2], '15X': [1], '13A': [2, 3], '24A': [3, 4],
27
- '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6], '02A': [3, 4, 5, 6], 'Gal': [1, 2, 3, 4, 5, 6]}},
28
- 'Glc': {'mass': {'03X': 72.0211, '02X': 42.0105, '15X': 27.9949, '13A': 60.0211, '24A': 60.0211,
29
- '04A': 60.0211, '35A': 74.0368, '25A': 104.0473, '02A': 120.0423, 'Glc': 162.0528},
30
- 'atoms': {'03X': [1, 2, 3], '02X': [1, 2], '15X': [1], '13A': [2, 3], '24A': [3, 4],
31
- '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6], '02A': [3, 4, 5, 6], 'Glc': [1, 2, 3, 4, 5, 6]}},
32
- 'Man': {'mass': {'03X': 72.0211, '02X': 42.0105, '15X': 27.9949, '13A': 60.0211, '24A': 60.0211,
33
- '04A': 60.0211, '35A': 74.0368, '25A': 104.0473, '02A': 120.0423, 'Man': 162.0528},
34
- 'atoms': {'03X': [1, 2, 3], '02X': [1, 2], '15X': [1], '13A': [2, 3], '24A': [3, 4],
35
- '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6], '02A': [3, 4, 5, 6], 'Man': [1, 2, 3, 4, 5, 6]}},
36
- 'Hex': {'mass': {'03X': 72.0211, '02X': 42.0105, '15X': 27.9949, '13A': 60.0211, '24A': 60.0211,
37
- '04A': 60.0211, '35A': 74.0368, '25A': 104.0473, '02A': 120.0423, 'Hex': 162.0528},
38
- 'atoms': {'03X': [1, 2, 3], '02X': [1, 2], '15X': [1], '13A': [2, 3], '24A': [3, 4],
39
- '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6], '02A': [3, 4, 5, 6], 'Hex': [1, 2, 3, 4, 5, 6]}},
40
- 'GalNAc': {'mass': {'04A': 60.0211, '24A': 60.0211, '35A': 74.0368, '03A': 90.0317, '25A': 104.0473,
41
- '02A': 120.0423, '24X': 143, 'GalNAc': 203.0794},
42
- 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6],
43
- '02A': [3, 4, 5, 6], '24X': [1,2,5,6], 'GalNAc': [1, 2, 3, 4, 5, 6]}},
44
- 'GlcNAc': {'mass': {'04A': 60.0211, '24A': 60.0211, '35A': 74.0368, '03A': 90.0317, '25A': 104.0473,
45
- '02A': 120.0423, '24X': 143, 'GlcNAc': 203.0794},
46
- 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6],
47
- '02A': [3, 4, 5, 6], '24X': [1,2,5,6], 'GlcNAc': [1, 2, 3, 4, 5, 6]}},
48
- 'HexNAc': {'mass': {'04A': 60.0211, '24A': 60.0211, '35A': 74.0368, '03A': 90.0317, '25A': 104.0473,
49
- '02A': 120.0423, '24X': 143, 'HexNAc': 203.0794},
50
- 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6],
51
- '02A': [3, 4, 5, 6], '24X': [1,2,5,6], 'HexNAc': [1, 2, 3, 4, 5, 6]}},
52
- 'Neu5Ac': {'mass': {'02X': 70.0055, '04X': 170.0453, 'Neu5Ac': 291.0954},
53
- 'atoms': {'02X': [1, 2, 3], '04X': [1, 2, 3, 4, 5], 'Neu5Ac': [1, 2, 3, 4, 5, 6, 7, 8, 9]}},
54
- 'Neu5Gc': {'mass': {'02X': 70.0055, '04X': 186.0402, 'Neu5Gc': 307.0903},
55
- 'atoms': {'02X': [1, 2, 3], '04X': [1, 2, 3, 4, 5], 'Neu5Gc': [1, 2, 3, 4, 5, 6, 7, 8, 9]}},
56
- 'Kdn': {'mass': {'02X': 70.0055, '04X': 129.0188, 'Kdn': 250.0689},
57
- 'atoms': {'02X': [1, 2, 3], '04X': [1, 2, 3, 4, 5], 'Kdn': [1, 2, 3, 4, 5, 6, 7, 8, 9]}},
58
- 'GlcA': {'mass': {'GlcA': 176.03209},
59
- 'atoms': {'GlcA': [1, 2, 3, 4, 5, 6]}},
60
- 'HexA': {'mass': {'HexA': 176.03209},
61
- 'atoms': {'HexA': [1, 2, 3, 4, 5, 6]}},
62
- 'Fuc': {'mass': {'Fuc': 146.0579},
63
- 'atoms': {'Fuc': [1, 2, 3, 4, 5, 6]}},
64
- 'dHex': {'mass': {'dHex': 146.0579},
65
- 'atoms': {'dHex': [1, 2, 3, 4, 5, 6]}},
66
- 'GlcNAc6S': {'mass': {'04A': 139.9779, '24A': 60.0211, '35A': 153.9936, '03A': 169.9885, '25A': 184.0041,
67
- '02A': 199.9991, 'GlcNAc6S': 283.0362},
68
- 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6],
69
- '02A': [3, 4, 5, 6], 'GlcNAc6S': [1, 2, 3, 4, 5, 6]}},
70
- 'GlcNAcOS': {'mass': {'04A': 139.9779, '24A': 139.9779, '35A': 153.9936, '03A': 169.9885, '25A': 184.0041,
71
- '02A': 199.9991, 'GlcNAcOS': 283.0362},
72
- 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6],
73
- '25A': [3, 4, 5, 6], '02A': [3, 4, 5, 6], 'GlcNAcOS': [1, 2, 3, 4, 5, 6]}},
74
- 'GalNAc6S': {'mass': {'04A': 139.9779, '24A': 60.0211, '35A': 153.9936, '03A': 169.9885, '25A': 184.0041,
75
- '02A': 199.9991, 'GalNAc6S': 283.0362},
76
- 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6],
77
- '02A': [3, 4, 5, 6], 'GalNAc6S': [1, 2, 3, 4, 5, 6]}},
78
- 'GalNAcOS': {'mass': {'04A': 139.9779, '24A': 139.9779, '35A': 153.9936, '03A': 169.9885, '25A': 184.0041,
79
- '02A': 199.9991, 'GalNAcOS': 283.0362},
80
- 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6],
81
- '02A': [3, 4, 5, 6], 'GalNAcOS': [1, 2, 3, 4, 5, 6]}},
82
- 'HexNAc6S': {'mass': {'04A': 139.9779, '24A': 60.0211, '35A': 153.9936, '03A': 169.9885, '25A': 184.0041,
83
- '02A': 199.9991, 'HexNAc6S': 283.0362},
84
- 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6],
85
- '02A': [3, 4, 5, 6], 'HexNAc6S': [1, 2, 3, 4, 5, 6]}},
86
- 'HexNAcOS': {'mass': {'04A': 139.9779, '24A': 139.9779, '35A': 153.9936, '03A': 169.9885, '25A': 184.0041,
87
- '02A': 199.9991, 'HexNAcOS': 283.0362},
88
- 'atoms': {'04A': [5, 6], '24A': [3, 4], '35A': [4, 5, 6], '03A': [4, 5, 6], '25A': [3, 4, 5, 6],
89
- '02A': [3, 4, 5, 6], 'HexNAcOS': [1, 2, 3, 4, 5, 6]}},
90
- 'Gal6S': {'mass': {'13A': 60.0211, '24A': 60.0211, '04A': 139.9779, '35A': 153.9936, '25A': 184.0041,
91
- '02A': 199.9991, 'Gal6S': 242.0096},
92
- 'atoms': {'13A': [2, 3], '24A': [3, 4], '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6],
93
- '02A': [3, 4, 5, 6], 'Gal6S': [1, 2, 3, 4, 5, 6]}},
94
- 'Gal3S': {'mass': {'13A': 139.9779, '24A': 139.9779, '04A': 60.0211, '35A': 74.0368, '25A': 184.0041,
95
- '02A': 199.9991, 'Gal3S': 242.0096},
96
- 'atoms': {'13A': [2, 3], '24A': [3, 4], '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6],
97
- '02A': [3, 4, 5, 6], 'Gal3S': [1, 2, 3, 4, 5, 6]}},
98
- 'GalOS': {'mass': {'13A': 60.0211, '24A': 139.9779, '04A': 139.9779, '35A': 153.9936, '25A': 184.0041,
99
- '02A': 199.9991, 'GalOS': 242.0096},
100
- 'atoms': {'13A': [2, 3], '24A': [3, 4], '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6],
101
- '02A': [3, 4, 5, 6], 'GalOS': [1, 2, 3, 4, 5, 6]}},
102
- 'Glc6S': {'mass': {'13A': 60.0211, '24A': 60.0211, '04A': 139.9779, '35A': 153.9568, '25A': 184.0041,
103
- '02A': 199.9991, 'Glc6S': 242.0096},
104
- 'atoms': {'13A': [2, 3], '24A': [3, 4], '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6],
105
- '02A': [3, 4, 5, 6], 'Glc6S': [1, 2, 3, 4, 5, 6]}},
106
- 'Glc3S': {'mass': {'13A': 139.9779, '24A': 139.9779, '04A': 60.0211, '35A': 74.0368, '25A': 184.0041,
107
- '02A': 199.9991, 'Glc3S': 242.0096},
108
- 'atoms': {'13A': [2, 3], '24A': [3, 4], '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6],
109
- '02A': [3, 4, 5, 6], 'Glc3S': [1, 2, 3, 4, 5, 6]}},
110
- 'GlcOS': {'mass': {'13A': 60.0211, '24A': 139.9779, '04A': 139.9779, '35A': 153.9936, '25A': 184.0041,
111
- '02A': 199.9991, 'GlcOS': 242.0096},
112
- 'atoms': {'13A': [2, 3], '24A': [3, 4], '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6],
113
- '02A': [3, 4, 5, 6], 'GlcOS': [1, 2, 3, 4, 5, 6]}},
114
- 'HexOS': {'mass': {'13A': 60.0211, '24A': 139.9779, '04A': 139.9779, '35A': 153.9936, '25A': 184.0041,
115
- '02A': 199.9991, 'HexOS': 242.0096},
116
- 'atoms': {'13A': [2, 3], '24A': [3, 4], '04A': [5, 6], '35A': [4, 5, 6], '25A': [3, 4, 5, 6],
117
- '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]}},
118
86
  'Global': {'mass': {'H2O': -18.0105546, 'CH2O': -30.0106, 'C2H2O': -42.0106, 'CO2': -43.9898, 'C2H4O2': -60.0211,
119
- '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}}
120
89
  }
121
90
 
122
91
  bond_type_helper = {1: ['bond', 'no_bond'], 2: ['red_bond', 'red_no_bond']}
123
92
  cut_type_dict = {'bond': 'Y', 'no_bond': 'Z', 'red_bond': 'C', 'red_no_bond': 'B',
124
- '13A': '13A', '24A': '24A', '04A': '04A', '35A': '35A', '03A': '03A', '25A': '25A', '02A': '02A',
125
- '02X': '02X', '04X': '04X', '03X': '03X', '15X': '15X', '24X': '24X'}
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'}
126
95
  A_cross_rings = {c for c in cut_type_dict if c[-1] == 'A'}
127
96
  X_cross_rings = {c for c in cut_type_dict if c[-1] == 'X'}
128
97
  ranks = ['Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon', 'Zeta', 'Eta']
@@ -164,35 +133,27 @@ def glycan_to_graph_monos(glycan):
164
133
  bond_proc = min_process_glycans([glycan])[0]
165
134
  mono_proc = bond_proc[::2]
166
135
 
167
- all_mask_dic = {k: bond_proc[k] for k in range(len(bond_proc))}
168
- 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)}
169
138
  for k, j in mono_mask_dic.items():
170
139
  glycan = glycan.replace(j, str(k), 1)
171
140
  glycan = ''.join(re.split(r'[()]', glycan)[::2])
172
141
  adj_matrix = np.zeros((len(mono_proc), len(mono_proc)), dtype = int)
173
142
 
174
143
  for k in range(len(mono_mask_dic)):
175
- for j in range(len(mono_mask_dic)):
176
- if k < j:
177
- if k >= 100:
178
- adjustment = 2
179
- elif k >= 10:
180
- adjustment = 1
181
- else:
182
- adjustment = 0
183
- k_idx, j_idx = glycan.find(str(k), k),glycan.find(str(j), j)
184
- glycan_part = glycan[k_idx+1:j_idx]
185
-
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)
186
153
  if evaluate_adjacency_monos(glycan_part, adjustment):
187
154
  adj_matrix[k, j] = 1
188
155
  continue
189
156
 
190
- if len(bracket_removal(glycan_part)) <= 1+adjustment:
191
- glycan_part = bracket_removal(glycan_part)
192
- if evaluate_adjacency_monos(glycan_part, adjustment):
193
- adj_matrix[k, j] = 1
194
- continue
195
-
196
157
  return mono_mask_dic, adj_matrix, all_mask_dic
197
158
 
198
159
 
@@ -206,41 +167,29 @@ def create_edge_labels(gr, all_dict):
206
167
  | :-
207
168
  | Returns a dict mapping each gr edge to its bond label
208
169
  """
209
- edge_dict = {}
210
- for e in gr.edges:
211
- edge_dict[e] = {'bond_label': all_dict[(e[0]*2)+1]}
212
-
213
- return edge_dict
170
+ return {(e[0], e[1]): {'bond_label': all_dict[(e[0]*2)+1]} for e in gr.edges}
214
171
 
215
172
 
216
- def mono_graph_to_nx(mono_graph, directed = True, libr = None):
173
+ def mono_graph_to_nx(mono_graph, directed = True):
217
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
218
175
  | Arguments:
219
176
  | :-
220
177
  | mono_graph (string): output of glycan_to_graph_monos
221
- | directed (bool): if True, creates a directed graph with bonds pointing from leaf to reducing end ; default:True
222
- | 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
223
179
  | Returns:
224
180
  | :-
225
181
  | Returns networkx graph object of a glycan made up of only monosaccharides
226
182
  """
227
- if libr is None:
228
- libr = lib
229
- if directed:
230
- template = nx.DiGraph
231
- else:
232
- template = nx.Graph
233
- node_dict_mono = mono_graph[0]
234
- all_dict = mono_graph[2]
183
+ template = nx.DiGraph if directed else nx.Graph
184
+ node_dict_mono, adj_matrix, all_dict = mono_graph
235
185
 
236
186
  if len(node_dict_mono) > 1:
237
- gr = nx.from_numpy_array(mono_graph[1], create_using = template)
187
+ gr = nx.from_numpy_array(adj_matrix, create_using = template)
238
188
  for n1, n2, d in gr.edges(data = True):
239
189
  del d['weight']
240
190
  else:
241
191
  gr = nx.Graph()
242
192
  gr.add_node(0)
243
- nx.set_node_attributes(gr, {k: lib[v] for k,v in node_dict_mono.items()}, 'labels')
244
193
  nx.set_node_attributes(gr, node_dict_mono, 'string_labels')
245
194
  nx.set_node_attributes(gr, {k: 'terminal' if gr.degree[k] == 1 else 'internal' for k in gr.nodes()}, 'termini')
246
195
  nx.set_node_attributes(gr, {max(gr.nodes): 2}, 'reducing_end')
@@ -368,37 +317,6 @@ def get_terminals(subg, present_breakages, root_node):
368
317
  return terminals
369
318
 
370
319
 
371
- def calculate_mass(nx_mono):
372
- """Calculates the mass of a networkx glycan\n
373
- | Arguments:
374
- | :-
375
- | nx_mono (networkx_object): the original monosaccharide only graph\n
376
- | Returns:
377
- | :-
378
- | Returns a float of the monoisotopic mass of the glycan or fragment in negative mode
379
- """
380
- comp = nx.get_node_attributes(nx_mono, 'string_labels')
381
- mono_mods = nx.get_node_attributes(nx_mono, 'mod_labels')
382
- atom_dict = nx.get_node_attributes(nx_mono, 'atomic_mod_dict')
383
- all_atom_mods = Counter([m for d in [v.values() for v in atom_dict.values()] for m in d if m != 0])
384
- reducing_end = nx.get_node_attributes(nx_mono, 'reducing_end')
385
-
386
- mass = sum([mono_attributes[v]['mass'][v] for k, v in comp.items() if k not in mono_mods])-1.0078
387
- mass += sum([mono_attributes[comp[k]]['mass'][v] for k, v in mono_mods.items() if v in mono_attributes[comp[k]]['mass']])
388
- mass += sum([mono_attributes[comp[k]]['mass'][v] for k, v in mono_mods.items() if v not in mono_attributes[comp[k]]['mass']])
389
- mass += -18.0105546*all_atom_mods['no_bond']
390
- mass += +18.0105546*all_atom_mods['red_bond']
391
-
392
- if reducing_end:
393
- if mono_mods:
394
- reducing_end_node = next(iter(reducing_end))
395
- if mono_mods[reducing_end_node] == comp[reducing_end_node]:
396
- mass += 18.0105546+(2*1.0078)
397
- else:
398
- mass += 18.0105546
399
- return mass
400
-
401
-
402
320
  def atom_mods_init(subg, present_breakages, terminals, terminal_labels):
403
321
  """Creates the initial nested dict of each terminal node with floating bonds labelled 1 and the reducing end floating bond labelled 2\n
404
322
  | Arguments:
@@ -413,6 +331,7 @@ def atom_mods_init(subg, present_breakages, terminals, terminal_labels):
413
331
  """
414
332
  atomic_mod_dict = {}
415
333
  for terminal, terminal_label in zip(terminals, terminal_labels):
334
+ terminal_label = map_to_basic(terminal_label, obfuscate_ptm = False)
416
335
  atomic_mod_dict[terminal] = {y: 0 for y in mono_attributes[terminal_label]['atoms'][terminal_label]}
417
336
 
418
337
  for bond, bond_label in present_breakages.items():
@@ -421,10 +340,7 @@ def atom_mods_init(subg, present_breakages, terminals, terminal_labels):
421
340
  atomic_mod_dict[bond[0]][red_breakage] = 2
422
341
  else:
423
342
  # Current improvised way of providing '?' support
424
- try:
425
- breakage = int(bond_label[-1])
426
- except:
427
- 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])
428
344
  atomic_mod_dict[bond[1]][breakage] = 1
429
345
  return atomic_mod_dict
430
346
 
@@ -445,13 +361,14 @@ def get_mono_mods_list(root_node, subg, terminals, terminal_labels, nx_edge_dict
445
361
  """
446
362
  terminal_mods = []
447
363
  for node, label in zip(terminals, terminal_labels):
364
+ basic_label = map_to_basic(label, obfuscate_ptm = False)
448
365
  if node == root_node:
449
366
  valid_A_frags = get_valid_A_frags(subg, node, label, nx_edge_dict)
450
367
  terminal_mods.append(valid_A_frags)
451
368
  elif subg.degree()[node] > 1:
452
369
  terminal_mods.append([label])
453
370
  else:
454
- 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])
455
372
  return terminal_mods
456
373
 
457
374
 
@@ -468,13 +385,13 @@ def get_valid_A_frags(subg, node, label, nx_edge_dict):
468
385
  | Returns a list of names of possible modifications
469
386
  """
470
387
  valid_A_mods_list = []
471
- A_mods_list = [x for x in mono_attributes[label]['mass'] if x in A_cross_rings or x == label]
472
- node_in_edges = [x for x in subg.in_edges(node)]
473
- for mod in A_mods_list:
474
- 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]):
475
- pass
476
- else:
477
- 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])]
478
395
  return valid_A_mods_list
479
396
 
480
397
 
@@ -489,8 +406,8 @@ def create_dict_perms(dicty):
489
406
  """
490
407
  dict_perms = []
491
408
  modded_atoms = [k for k, v in dicty.items() if v in bond_type_helper]
492
- for mod_prod in product(*[bond_type_helper[dicty[y]] for y in modded_atoms]):
493
- 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]
494
411
  return dict_perms
495
412
 
496
413
 
@@ -509,7 +426,8 @@ def generate_mod_permutations(terminals, terminal_labels, mono_mods_list, atomic
509
426
  """
510
427
  all_terminal_perms, all_mono_mods = [], []
511
428
  for node, label, mono_mods in zip(terminals, terminal_labels, mono_mods_list):
512
- 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]
513
431
  all_atom_dict_perms, all_mono_mod_perms = [], []
514
432
  for i, atom_dict in enumerate(possible_node_atoms):
515
433
  dict_perms = create_dict_perms(atom_dict)
@@ -534,22 +452,14 @@ def precalculate_mod_masses(all_mono_mods, all_terminal_perms, terminal_labels,
534
452
  | (2) a list of all possible mass combinations for each bond fragmentation combination
535
453
  | (3) a list of masses corresponding to each of the global mods
536
454
  """
537
- all_mono_mod_masses = []
538
- for node, label in zip(all_mono_mods, terminal_labels):
539
- node_mod_masses = []
540
- for mod in node:
541
- mass = mono_attributes[label]['mass'][mod]
542
- node_mod_masses.append(mass)
543
- 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)]
544
456
 
545
457
  all_atom_dict_masses = []
546
458
  for node in all_terminal_perms:
547
459
  node_dict_masses = []
548
460
  for mod in node:
549
461
  present_atom_mods = [x for x in mod.values() if x in ['no_bond', 'red_bond']]
550
- mass = -18.0105546*len([x for x in present_atom_mods if x == 'no_bond'])
551
- mass += +18.0105546*len([x for x in present_atom_mods if x == 'red_bond'])
552
- 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))
553
463
  all_atom_dict_masses.append(node_dict_masses)
554
464
 
555
465
  global_mods_mass = [mono_attributes['Global']['mass'][x] for x in global_mods[1:]]
@@ -558,7 +468,7 @@ def precalculate_mod_masses(all_mono_mods, all_terminal_perms, terminal_labels,
558
468
 
559
469
 
560
470
  def preliminary_calculate_mass(mono_mods_mass, atom_mods_mass, global_mods_mass, terminals,
561
- inner_mass, true_root_node, label_mass, mode):
471
+ inner_mass, true_root_node, label_mass, charge):
562
472
  """Determines the mass of every permutation of monosaccharide, atom, and global modification\n
563
473
  | Arguments:
564
474
  | :-
@@ -569,30 +479,21 @@ def preliminary_calculate_mass(mono_mods_mass, atom_mods_mass, global_mods_mass,
569
479
  | inner_mass (float): total mass of non-terminal nodes in subgraph
570
480
  | true_root_node (int): the node label corresponding to the root of the parent glycan
571
481
  | label_mass (float): mass of the glycan label or reducing end modification
572
- | mode (string): the mode in which the mass spectrometer was run, 'negative' or 'positive'\n
482
+ | charge (int): assumed charge of glycan\n
573
483
  | Returns:
574
484
  | :-
575
485
  | Returns a list every single mass of each modification combination for each cross ring combination
576
486
  """
577
- if mode == 'negative':
578
- mode_mass = -1.0078
579
- elif mode == 'positive':
580
- mode_mass = +1.0078
487
+ mode_mass = -1.0078 if charge < 0 else 1.0078
581
488
  masses_list = []
582
- root_presence = False
583
- if true_root_node in terminals:
584
- root_presence = True
585
- 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
586
491
  for mod_combo, atom_combo in zip(mono_mods_mass, atom_mods_mass):
587
- mass = inner_mass+mode_mass
588
- mass += sum(mod_combo)+sum(atom_combo)
589
- if root_presence:
590
- if mod_combo[root_node_idx] not in A_cross_rings:
591
- 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
592
495
  masses_list.append(mass)
593
- for mod_mass in global_mods_mass:
594
- modded_mass = mass + mod_mass
595
- masses_list.append(modded_mass)
496
+ masses_list.extend([mass + mod_mass for mod_mass in global_mods_mass])
596
497
  return masses_list
597
498
 
598
499
 
@@ -608,34 +509,33 @@ def add_to_subgraph_fragments(subgraph_fragments, nx_mono_list, mass_list):
608
509
  | Returns an updated subgraph_fragments dict
609
510
  """
610
511
  for nx_mono, mass in zip(nx_mono_list, mass_list):
611
- if mass not in subgraph_fragments:
612
- subgraph_fragments[mass] = [nx_mono]
613
- else:
614
- subgraph_fragments[mass].append(nx_mono)
615
-
512
+ subgraph_fragments.setdefault(mass, []).append(nx_mono)
616
513
  return subgraph_fragments
617
514
 
618
515
 
619
- def get_global_mods(subg, node_dict, mode):
516
+ def get_global_mods(subg, node_dict, charge):
620
517
  """Returns the valid list of global modifications for a given subgraph\n
621
518
  | Arguments:
622
519
  | :-
623
520
  | subg (networkx_object): a subgraph
624
521
  | node_dict (dict): a dictionary relating the integer label of each node with the monosaccharide it represents\n
625
- | 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
626
523
  | Returns:
627
524
  | :-
628
525
  | Returns a a list of modification names
629
526
  """
630
527
  global_mods = sorted([x for x in mono_attributes['Global']['mass']])
631
- 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']):
632
530
  global_mods.remove('CO2')
633
- if 'S' not in ''.join([node_dict[x] for x in subg.nodes()]):
531
+ if 'S' not in node_labels:
634
532
  global_mods.remove('SO4')
635
- if mode == 'negative':
636
- global_mods.remove('+Na')
637
- if mode == 'positive':
638
- 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]
639
539
  return global_mods
640
540
 
641
541
 
@@ -649,9 +549,7 @@ def mod_count(node_mod, global_mod):
649
549
  | :-
650
550
  | Returns a sum of modifications
651
551
  """
652
- c = 0
653
- if global_mod is not None:
654
- c += 1
552
+ c = 1 if global_mod is not None else 0
655
553
  c += sum([1 for k in node_mod[0] if k in A_cross_rings or k in X_cross_rings])
656
554
  c += sum([1 for k in unwrap([list(n.values()) for n in node_mod[1]]) if isinstance(k, str)])
657
555
  return c
@@ -662,7 +560,7 @@ def extend_masses(fragment_masses, charge):
662
560
  | Arguments:
663
561
  | :-
664
562
  | fragment_masses (list): a list of observed masses to be searched for possible fragments
665
- | 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
666
564
  | Returns:
667
565
  | :-
668
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
@@ -671,7 +569,7 @@ def extend_masses(fragment_masses, charge):
671
569
  return fragment_masses
672
570
  modifier = np.sign(charge)
673
571
  for z in range(2, abs(charge)+1):
674
- 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]
675
573
  return charged_masses
676
574
 
677
575
 
@@ -688,16 +586,15 @@ def annotate_subgraph(subg,node_mod,global_mod,terminals):
688
586
  | Returns a copy of the input subgraph with networkx node attributes describing the modifications
689
587
  """
690
588
  mod_subg = subg.copy()
691
- mono_mods_dict = dict(zip(terminals, node_mod[0]))
692
- nx.set_node_attributes(mod_subg, mono_mods_dict, 'mod_labels')
693
- atoms_mods_dict = dict(zip(terminals, node_mod[1]))
694
- 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')
695
591
  if global_mod:
696
592
  nx.set_node_attributes(mod_subg, [global_mod], 'global_mod')
697
593
  return mod_subg
698
594
 
699
595
 
700
- 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):
701
598
  """Calculates the graph and mass of all possible fragments of the input\n
702
599
  | Arguments:
703
600
  | :-
@@ -706,8 +603,7 @@ def generate_atomic_frags(nx_mono, max_cleavages = 3, fragment_masses = None, th
706
603
  | fragment_masses (list): all masses which are to be annotated with a fragment name
707
604
  | threshold (float): the range around the observed mass in which constrain potential fragments
708
605
  | label_mass (float): mass of the glycan label or reducing end modification; default:2.0156
709
- | charge (int): the maximum possible charge on the fragments to be matched; default:-1
710
- | 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
711
607
  | Returns:
712
608
  | :-
713
609
  | Returns a dict of lists of networkx subgraphs
@@ -718,32 +614,33 @@ def generate_atomic_frags(nx_mono, max_cleavages = 3, fragment_masses = None, th
718
614
  true_root_node = [v for v, d in nx_mono.out_degree() if d == 0][0]
719
615
  nx_edge_dict = {(node[0], node[1]): node[2] for node in nx_mono.edges(data = True)}
720
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()}
721
618
  subgraph_fragments = {}
722
- subgraphs = enumerate_subgraphs(nx_mono)
723
- subgraphs.append(nx_mono)
619
+ subgraphs = enumerate_subgraphs(nx_mono) + [nx_mono]
620
+ max_global_mass = max(mono_attributes['Global']['mass'].values())
724
621
  for subg in subgraphs:
725
622
  present_breakages = get_broken_bonds(subg, nx_mono, nx_edge_dict)
726
623
  root_node = [v for v, d in subg.out_degree() if d == 0][0]
727
624
  terminals = get_terminals(subg, present_breakages, root_node)
728
- inner_mass = sum([mono_attributes[node_dict[m]]['mass'][node_dict[m]] for m in subg.nodes() if m not in terminals])
729
- max_mass = inner_mass + sum([mono_attributes[node_dict[m]]['mass'][node_dict[m]] for m in terminals]) + 18.0105546*len(terminals)
730
- max_mass += mono_attributes['Global']['mass']['+Acetate']
731
- 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:
732
629
  continue
733
- terminal_labels = [node_dict[x] for x in terminals]
734
- 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)
735
632
  atomic_mod_dict_subg = atom_mods_init(subg, present_breakages, terminals, terminal_labels)
736
633
  mono_mods_list = get_mono_mods_list(root_node, subg, terminals, terminal_labels, nx_edge_dict)
737
634
  mono_mod_perms, atom_dict_perms = generate_mod_permutations(terminals, terminal_labels, mono_mods_list, atomic_mod_dict_subg)
738
635
  permutation_list = product(zip(product(*mono_mod_perms), product(*atom_dict_perms)), global_mods)
739
636
  mono_masses, atom_masses, global_masses = precalculate_mod_masses(mono_mod_perms, atom_dict_perms, terminal_labels, global_mods)
740
- 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)
741
638
  fragment_arr = np.array(charge_masses)
742
639
  for mass, (node_mod, global_mod) in zip(initial_masses, permutation_list):
743
640
  if not (abs(fragment_arr - mass) < threshold).any():
744
641
  continue
745
642
  if (m := mod_count(node_mod, global_mod)) <= max_cleavages:
746
- if m > 1 and global_mod in ['+Acetate','+Na']:
643
+ if m > 1 and global_mod in ['+Acetate', '+Acetonitrile', '+Na', '+K']:
747
644
  continue
748
645
  annotated_subg = annotate_subgraph(subg,node_mod,global_mod,terminals)
749
646
  annotated_subg_mass = round(mass, 5)
@@ -766,7 +663,8 @@ def rank_chains(nx_mono):
766
663
  leaf_chains = []
767
664
  for og_leaf in og_leaves:
768
665
  leaf_chains.append(nx.shortest_path(nx_mono, source = og_leaf))
769
- 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)
770
668
  return zip(ranks, main_chains)
771
669
 
772
670
 
@@ -786,21 +684,23 @@ def domon_costello_to_node_labels(fragment, chain_rank):
786
684
  global_mod = None
787
685
  post_mono = None
788
686
  for cut in fragment:
789
- if cut[0] == 'M':
687
+ if cut.startswith('M'):
790
688
  global_mod = cut.split('_')[-1]
791
689
  continue
792
- split_cut = cut.split('_')
793
- chain = chain_rank[split_cut[2]]
794
- if split_cut[0][-1] in {'Y', 'Z'}:
795
- mono = chain[::-1][int(split_cut[1])]
796
- elif split_cut[0][-1] == 'X':
797
- mono = chain[::-1][int(split_cut[1])-1]
798
- elif split_cut[0][-1] in {'B', 'C'}:
799
- mono = chain[int(split_cut[1])]
800
- post_mono = chain[int(split_cut[1])-1]
801
- elif split_cut[0][-1] == 'A':
802
- mono = chain[int(split_cut[1])-1]
803
- 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
804
704
  return skelly_dict, post_mono, global_mod
805
705
 
806
706
 
@@ -810,7 +710,7 @@ def node_labels_to_domon_costello(cuts, chain_rank, global_mods = {}):
810
710
  | :-
811
711
  | cuts (list): a list of tuples each containing the cleavage type, and related integer node labels
812
712
  | chain_rank (list): a list of tuples each containing rank and a list of integer node labels representing the glycan chain
813
- | 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
814
714
  | Returns:
815
715
  | :-
816
716
  | Returns a list containing all of the cleavages making up the fragment in Domon-Costello form
@@ -827,13 +727,11 @@ def node_labels_to_domon_costello(cuts, chain_rank, global_mods = {}):
827
727
  elif cut_type[-1] in {'X'}:
828
728
  cut_rank, cut_chain = [(rank, chain) for rank, chain in chain_rank if cut[1] in chain][0]
829
729
  cut_number = cut_chain[::-1].index(cut[1])+1
830
- dc_cuts.append('_'.join((cut_type, str(cut_number), cut_rank)))
730
+ dc_cuts.append(f"{cut_type}_{cut_number}_{cut_rank}")
831
731
  if global_mods:
832
- global_mods = list(global_mods.values())
833
- dc_cuts.append('_'.join(('M', global_mods[0][0])))
834
- if not dc_cuts:
835
- dc_cuts = ['M']
836
- 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']
837
735
 
838
736
 
839
737
  def find_main_chain(subgraph, leaves, root_node):
@@ -848,12 +746,10 @@ def find_main_chain(subgraph, leaves, root_node):
848
746
  | Returns a list of integer node labels representing the inputs main chain
849
747
  """
850
748
  bond_dict = nx.get_edge_attributes(subgraph, 'bond_label')
851
- main_chains = []
852
- for leaf in leaves:
853
- for path in nx.all_simple_paths(subgraph, source = leaf, target = root_node):
854
- main_chains.append(path)
855
- main_chain_len = max([len(x) for x in main_chains])
856
- 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]
857
753
  for i in range(main_chain_len)[::-1]:
858
754
  step = [c[i] for c in main_chains]
859
755
  if len(set(step)) == 1:
@@ -874,9 +770,8 @@ def subgraph_to_label_skeleton(sub_g):
874
770
  | Returns a list of integer node labels and branching brackets in the same order as the IUPAC condensed string
875
771
  """
876
772
  if len(sub_g.nodes) == 1:
877
- return [str(x) for x in sub_g.nodes]
878
- root_node = [k for k, v in sub_g.out_degree if v == 0]
879
- 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)
880
775
  leaves = [v for v, d in sub_g.in_degree() if d == 0]
881
776
  main_chain = []
882
777
  n_skelly = []
@@ -920,17 +815,15 @@ def label_skeleton_to_string(n_skelly, sub_g):
920
815
 
921
816
 
922
817
  def mono_frag_to_string(sub_g):
923
- """Converts a monsaccharide graph to a string\n
818
+ """Converts a monosaccharide graph to a string\n
924
819
  | Arguments:
925
820
  | :-
926
821
  | subg (networkx_object): a graph or subgraph of monosaccharides\n
927
822
  | Returns:
928
823
  | :-
929
- | 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
930
825
  """
931
- n_skelly = subgraph_to_label_skeleton(sub_g)
932
- glycan_string = label_skeleton_to_string(n_skelly, sub_g)
933
- return glycan_string
826
+ return label_skeleton_to_string(subgraph_to_label_skeleton(sub_g), sub_g)
934
827
 
935
828
 
936
829
  def domon_costello_to_fragIUPAC(glycan_string, fragment):
@@ -1023,6 +916,7 @@ def subgraphs_to_domon_costello(nx_mono, subgs):
1023
916
  """
1024
917
  ion_names = []
1025
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()}
1026
920
  chain_rank = list(rank_chains(nx_mono))
1027
921
 
1028
922
  for subg in subgs:
@@ -1038,9 +932,8 @@ def subgraphs_to_domon_costello(nx_mono, subgs):
1038
932
  cuts.append((atom_mod, cut_node[0], node))
1039
933
  if atom_mod in {'red_bond', 'red_no_bond'}:
1040
934
  cuts.append((atom_mod, node))
1041
- cross_rings = [(k, v) for k, v in mono_mod_dict.items() if (k, v) not in node_dict.items()]
1042
- for node, mod in cross_rings:
1043
- 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)
1044
937
  dc_cuts = node_labels_to_domon_costello(cuts, chain_rank, global_mods = global_mods)
1045
938
  ion_names.append((dc_cuts))
1046
939
  return ion_names
@@ -1056,7 +949,7 @@ def priority_filter(dc_names, diffs):
1056
949
  | :-
1057
950
  | Returns a list of Domon-Costello fragment names sorted by number of cleavages and the observed mass difference
1058
951
  """
1059
- sorted_frags = sorted(list(zip(dc_names,diffs)),key=lambda x:(len(x[0]),x[1]))
952
+ sorted_frags = sorted(list(zip(dc_names, diffs)), key = lambda x:(len(x[0]), x[1]))
1060
953
  return [f[0] for f in sorted_frags]
1061
954
 
1062
955
 
@@ -1079,11 +972,11 @@ def match_fragment_properties(subg_frags, mass, mass_threshold, charge):
1079
972
  fragment_properties = []
1080
973
  modifier = np.sign(charge)
1081
974
  for z in range(1, abs(charge)+1):
1082
- charged_mass = (mass*z)-(z*modifier-modifier)
1083
- for k in subg_frags:
1084
- if abs(charged_mass-k) < mass_threshold:
1085
- for graph in subg_frags[k]:
1086
- 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))
1087
980
  if fragment_properties:
1088
981
  return list(zip(*fragment_properties))
1089
982
  else:
@@ -1100,16 +993,10 @@ def observed_fragments_checker(possible_fragments, observed_fragments):
1100
993
  | :-
1101
994
  | Returns a list containing integers corresponding to the largest overlap each possible fragment had with all previously observed fragments
1102
995
  """
1103
- max_overlaps_seen = []
1104
- for cleavage_combo in possible_fragments:
1105
- seen_cleavage_overlaps = []
1106
- for obs in observed_fragments:
1107
- if not obs:
1108
- seen_cleavage_overlaps.append(0)
1109
- continue
1110
- seen_cleavage_overlaps.append(len(set(cleavage_combo) & set(obs[0])))
1111
- max_overlaps_seen.append(max(seen_cleavage_overlaps, default = 0))
1112
- 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)]
1113
1000
 
1114
1001
 
1115
1002
  def simplify_fragments(dc_names):
@@ -1129,17 +1016,16 @@ def simplify_fragments(dc_names):
1129
1016
  observed_frags.append([])
1130
1017
  elif len(possible_frags[0]) == 1:
1131
1018
  observed_frags.append([possible_frags[0]])
1132
- continue
1133
1019
  else:
1134
1020
  frag_options = [x for x in possible_frags if len(x) == len(possible_frags[0])]
1135
1021
  max_overlaps_seen = (observed_fragments_checker(frag_options, observed_frags))
1136
1022
  max_overlap_idx = np.argsort(max_overlaps_seen, kind = 'stable')[-1]
1137
1023
  observed_frags.append([frag_options[max_overlap_idx]])
1138
- continue
1139
1024
  return observed_frags
1140
1025
 
1141
1026
 
1142
- def CandyCrumbs(glycan_string, fragment_masses, mass_threshold, libr = None,
1027
+ @rescue_glycans
1028
+ def CandyCrumbs(glycan_string, fragment_masses, mass_threshold,
1143
1029
  max_cleavages = 3, simplify = True, charge = -1, label_mass = 2.0156,
1144
1030
  iupac = False, intensities = None):
1145
1031
  """Basic wrapper for the annotation of observed masses with correct nomenclature given a glycan\n
@@ -1148,7 +1034,6 @@ def CandyCrumbs(glycan_string, fragment_masses, mass_threshold, libr = None,
1148
1034
  | glycan_string (string): glycan in IUPAC-condensed format
1149
1035
  | fragment_masses (list): all masses which are to be annotated with a fragment name
1150
1036
  | mass_threshold (float): the maximum tolerated mass difference around each observed mass at which to include fragments
1151
- | libr (list): library of monosaccharides; if you have one use it, otherwise a comprehensive lib will be used
1152
1037
  | max_cleavages (int): maximum number of allowed concurrent fragmentations per mass; default:3
1153
1038
  | simplify (bool): whether to try condensing fragment options to the most likely option; default:True
1154
1039
  | charge (int): the charge state of the precursor ion (singly-charged, doubly-charged); default:-1
@@ -1158,14 +1043,11 @@ def CandyCrumbs(glycan_string, fragment_masses, mass_threshold, libr = None,
1158
1043
  | :-
1159
1044
  | Returns a list of tuples containing the observed mass and all of the possible fragment names within the threshold
1160
1045
  """
1161
- if libr is None:
1162
- libr = lib
1163
1046
  hit_dict = {}
1164
- mode = 'negative' if charge < 0 else 'positive'
1165
1047
  fragment_masses = sorted(fragment_masses)
1166
1048
  mono_graph = glycan_to_graph_monos(glycan_string)
1167
- nx_mono = mono_graph_to_nx(mono_graph, directed = True, libr = libr)
1168
- 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)
1169
1051
  downstream_values = []
1170
1052
  for observed_mass in fragment_masses:
1171
1053
  fragment_properties = match_fragment_properties(subg_frags, observed_mass, mass_threshold, charge)