CandyCrunch 0.4.1__tar.gz → 0.5.2__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 (28) hide show
  1. CandyCrunch-0.4.1/CandyCrunch/merged_analysis.py → CandyCrunch-0.5.2/CandyCrunch/analysis.py +89 -42
  2. {CandyCrunch-0.4.1 → CandyCrunch-0.5.2}/CandyCrunch/candycrunch.pt +0 -0
  3. CandyCrunch-0.5.2/CandyCrunch/glycans.pkl +0 -0
  4. {CandyCrunch-0.4.1 → CandyCrunch-0.5.2}/CandyCrunch/model.py +2 -12
  5. {CandyCrunch-0.4.1 → CandyCrunch-0.5.2}/CandyCrunch/prediction.py +473 -179
  6. {CandyCrunch-0.4.1 → CandyCrunch-0.5.2}/CandyCrunch.egg-info/PKG-INFO +23 -8
  7. {CandyCrunch-0.4.1 → CandyCrunch-0.5.2}/CandyCrunch.egg-info/SOURCES.txt +4 -7
  8. {CandyCrunch-0.4.1 → CandyCrunch-0.5.2}/CandyCrunch.egg-info/requires.txt +3 -3
  9. {CandyCrunch-0.4.1 → CandyCrunch-0.5.2}/PKG-INFO +23 -8
  10. {CandyCrunch-0.4.1 → CandyCrunch-0.5.2}/README.md +1 -1
  11. CandyCrunch-0.5.2/pyproject.toml +52 -0
  12. CandyCrunch-0.5.2/tests/test_CandyCrumbs.py +102 -0
  13. CandyCrunch-0.5.2/tests/test_CandyCrunch.py +162 -0
  14. CandyCrunch-0.4.1/CandyCrunch/analysis.py +0 -1308
  15. CandyCrunch-0.4.1/CandyCrunch/glycans.pkl +0 -0
  16. CandyCrunch-0.4.1/CandyCrunch/multi_file_workflow_utils.py +0 -375
  17. CandyCrunch-0.4.1/CandyCrunch/test_CandyCrumbs.py +0 -38
  18. CandyCrunch-0.4.1/CandyCrunch/tester.py +0 -2
  19. CandyCrunch-0.4.1/LICENSE.txt +0 -19
  20. CandyCrunch-0.4.1/setup.py +0 -35
  21. {CandyCrunch-0.4.1 → CandyCrunch-0.5.2}/CandyCrunch/__init__.py +0 -0
  22. {CandyCrunch-0.4.1 → CandyCrunch-0.5.2}/CandyCrunch/cli.py +0 -0
  23. {CandyCrunch-0.4.1 → CandyCrunch-0.5.2}/CandyCrunch/glytoucan_mapping.pkl +0 -0
  24. {CandyCrunch-0.4.1 → CandyCrunch-0.5.2}/CandyCrunch.egg-info/dependency_links.txt +0 -0
  25. {CandyCrunch-0.4.1 → CandyCrunch-0.5.2}/CandyCrunch.egg-info/entry_points.txt +0 -0
  26. {CandyCrunch-0.4.1 → CandyCrunch-0.5.2}/CandyCrunch.egg-info/top_level.txt +0 -0
  27. {CandyCrunch-0.4.1 → CandyCrunch-0.5.2}/LICENSE +0 -0
  28. {CandyCrunch-0.4.1 → CandyCrunch-0.5.2}/setup.cfg +0 -0
@@ -5,7 +5,6 @@ import re
5
5
  from collections import Counter
6
6
  from itertools import product
7
7
  from operator import neg
8
- from tqdm import tqdm
9
8
 
10
9
  import matplotlib.pyplot as plt
11
10
  import networkx as nx
@@ -42,7 +41,7 @@ mono_attributes = {'Hex': {'mass': {'03X': 72.0211, '02X': 42.0106, '15X': 27.99
42
41
  '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],
43
42
  '04A': [6, 7, 8, 9], '24A': [4, 5], 'Neu5Gc': [1, 2, 3, 4, 5, 6, 7, 8, 9]}},
44
43
  'Neu5Ac8S': {'mass': {'02X': 70.0055, '04X': 170.0453, '24X': 271.0124, '02A': 301.0467,
45
- '04A': 201.0069 , '24A': 100.0398, 'Neu5Ac8S': 371.0522 },
44
+ '04A': 201.0069 , '24A': 100.0398, 'Neu5Ac8S': 371.0522},
46
45
  '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],
47
46
  '04A': [6, 7, 8, 9], '24A': [4, 5], 'Neu5Ac8S': [1, 2, 3, 4, 5, 6, 7, 8, 9]}},
48
47
  'Neu5Gc8S': {'mass': {'02X': 70.0055, '04X': 186.0402, '24X': 271.0124 , '02A': 317.0416,
@@ -116,7 +115,7 @@ ranks = ['Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon', 'Zeta', 'Eta']
116
115
 
117
116
  AA_masses = {'A':71.0371,'R':156.1011,'N':114.0429,'D':115.0269,
118
117
  'C':103.0091,'E':129.0425,'Q':128.0585,'G':57.0214,'H':137.0589,
119
- 'I':113.0840,'L':113.0840,'K':128.0949,'M':131.0404,'F':147.0684,
118
+ 'I':113.0840,'L':113.0840,'K':128.0949,'k':357.25783,'M':131.0404,'F':147.0684,
120
119
  'P':97.0527,'S':87.0320,'T':101.0476,'W':186.0793,'Y':163.0633,'V':99.0684}
121
120
  tester_ma_addition = {k:{'mass':{k:v},'atoms':{k:[1,2,3,4,5,6]}} for k,v in AA_masses.items()}
122
121
  mono_attributes = mono_attributes|tester_ma_addition
@@ -166,9 +165,11 @@ def glycan_to_graph_monos(glycan):
166
165
  adj_matrix = np.zeros((len(mono_proc), len(mono_proc)), dtype = int)
167
166
 
168
167
  for k in mono_mask_dic:
168
+ adjustment = 2 if k >= 100 else 1 if k >= 10 else 0
169
169
  for j in range(k + 1, len(mono_mask_dic)):
170
- adjustment = 2 if k >= 100 else 1 if k >= 10 else 0
171
- k_idx, j_idx = glycan.find(str(k), k),glycan.find(str(j), j)
170
+ min_idx_k = k+(10*max((k//10)-1,0))
171
+ min_idx_j = j+(10*max((j//10)-1,0))
172
+ k_idx, j_idx = glycan.find(str(k), min_idx_k),glycan.find(str(j), min_idx_j)
172
173
  glycan_part = glycan[k_idx+1:j_idx]
173
174
  if evaluate_adjacency_monos(glycan_part, adjustment):
174
175
  adj_matrix[k, j] = 1
@@ -348,14 +349,18 @@ def atom_mods_init(subg, present_breakages, terminals, terminal_labels):
348
349
  atomic_mod_dict[terminal] = {y: 0 for y in mono_attributes[terminal_label]['atoms'][terminal_label]}
349
350
 
350
351
  for bond, bond_label in present_breakages.items():
352
+ if bond_label == 'glycosite':
353
+ if bond[0] in subg.nodes():
354
+ atomic_mod_dict[bond[0]][3] = 1
355
+ else:
356
+ atomic_mod_dict[bond[1]][1] = 2
357
+ continue
351
358
  if bond_label == 'peptide':
352
359
  if bond[0] in subg.nodes():
353
360
  atomic_mod_dict[bond[0]][6] = 3
354
361
  else:
355
362
  atomic_mod_dict[bond[1]][1] = 4
356
- elif bond_label == 'glycosite':
357
- if bond[0] in subg.nodes():
358
- atomic_mod_dict[bond[0]][3] = 2
363
+ continue
359
364
  elif bond[0] in subg.nodes():
360
365
  red_breakage = int(bond_label[1])
361
366
  atomic_mod_dict[bond[0]][red_breakage] = 2
@@ -502,7 +507,7 @@ def temporary_root_calc_func(glyco_pep):
502
507
  return True,red_end
503
508
 
504
509
  def preliminary_calculate_mass(mono_mods_mass, atom_mods_mass, global_mods_mass, terminals,
505
- inner_mass, bonus_root_mass, bonus_root_node,label_mass, charge,mono_mod_perms):
510
+ inner_mass, bonus_root_mass, bonus_root_node,mass_tag, charge,mono_mod_perms):
506
511
  """Determines the mass of every permutation of monosaccharide, atom, and global modification\n
507
512
  | Arguments:
508
513
  | :-
@@ -512,7 +517,7 @@ def preliminary_calculate_mass(mono_mods_mass, atom_mods_mass, global_mods_mass,
512
517
  | terminals (list): string labels of nodes in terminals
513
518
  | inner_mass (float): total mass of non-terminal nodes in subgraph
514
519
  | true_root_node (int): the node label corresponding to the root of the parent glycan
515
- | label_mass (float): mass of the glycan label or reducing end modification
520
+ | mass_tag (float): mass of the glycan label or reducing end modification
516
521
  | charge (int): assumed charge of glycan\n
517
522
  | Returns:
518
523
  | :-
@@ -529,7 +534,7 @@ def preliminary_calculate_mass(mono_mods_mass, atom_mods_mass, global_mods_mass,
529
534
  if bonus_root_mass:
530
535
  mod_label = mono_mod_names[perm_number]
531
536
  if mod_label[root_node_idx] not in A_cross_rings:
532
- mass += 18.0105546 + label_mass
537
+ mass += 18.0105546 + mass_tag
533
538
  masses_list.append(mass)
534
539
  masses_list.extend([mass + mod_mass for mod_mass in global_mods_mass])
535
540
  return masses_list
@@ -630,7 +635,7 @@ def annotate_subgraph(subg,node_mod,global_mod,terminals):
630
635
  return mod_subg
631
636
 
632
637
  def generate_atomic_frags(nx_mono, global_mods, special_residues, allowed_X_cleavages, max_cleavages = 3, fragment_masses = [],
633
- threshold = 0.5, label_mass = 2.0156, charge = -1):
638
+ threshold = 0.5, mass_tag = None, charge = -1):
634
639
  """Calculates the graph and mass of all possible fragments of the input\n
635
640
  | Arguments:
636
641
  | :-
@@ -641,12 +646,14 @@ def generate_atomic_frags(nx_mono, global_mods, special_residues, allowed_X_clea
641
646
  | max_cleavages (int): maximum number of allowed concurrent fragmentations per mass; default:3
642
647
  | fragment_masses (list): all masses which are to be annotated with a fragment name
643
648
  | threshold (float): the range around the observed mass in which constrain potential fragments
644
- | label_mass (float): mass of the glycan label or reducing end modification; default:2.0156
649
+ | mass_tag (float): mass of the glycan label or reducing end modification; default:2.0156
645
650
  | charge (int): the maximum possible charge on the fragments to be matched; default:-1\n
646
651
  | Returns:
647
652
  | :-
648
653
  | Returns a dict of lists of networkx subgraphs
649
654
  """
655
+ if not mass_tag:
656
+ mass_tag = 2.0156
650
657
  charge_masses = np.array(extend_masses(fragment_masses, charge))
651
658
  threshold = abs(threshold)
652
659
  true_root_node = [v for v,d in nx_mono.out_degree() if d==0][0]
@@ -661,7 +668,10 @@ def generate_atomic_frags(nx_mono, global_mods, special_residues, allowed_X_clea
661
668
  nx_deg = nx_mono.degree
662
669
  for i,subg in enumerate(subgraphs):
663
670
  terminals = get_terminals(nx_deg,subg)
664
- other_terminals = [x for x in subg.nodes if x in all_other_terminals]
671
+ new_terminals = [x for x in terminals if x not in all_other_terminals]
672
+ if len(new_terminals)>max_cleavages:
673
+ continue
674
+ other_terminals = [x for x in subg.nodes if x in all_other_terminals and x not in terminals]
665
675
  terminals = terminals+other_terminals
666
676
  inner_mass = sum([mono_attributes[node_dict_basic[m]]['mass'][node_dict_basic[m]] for m in subg.nodes() if m not in terminals])
667
677
  max_graph_mass = inner_mass + sum([mono_attributes[node_dict_basic[m]]['mass'][node_dict_basic[m]] for m in terminals]) + 18.0105546*len(terminals)
@@ -683,7 +693,7 @@ def generate_atomic_frags(nx_mono, global_mods, special_residues, allowed_X_clea
683
693
  mono_mods_list = get_mono_mods_list(root_node, subg, terminals, terminal_labels, nx_edge_dict, allowed_X_cleavages)
684
694
  mono_mod_perms, atom_dict_perms = generate_mod_permutations(terminals, terminal_labels, mono_mods_list, atomic_mod_dict_subg)
685
695
  mono_masses, atom_masses, global_masses = precalculate_mod_masses(mono_mod_perms, atom_dict_perms, terminal_labels, subg_global_mods)
686
- initial_masses = np.array(preliminary_calculate_mass(mono_masses, atom_masses, global_masses, terminals, inner_mass, bonus_root_mass, bonus_root_node, label_mass, charge, mono_mod_perms))
696
+ initial_masses = np.array(preliminary_calculate_mass(mono_masses, atom_masses, global_masses, terminals, inner_mass, bonus_root_mass, bonus_root_node, mass_tag, charge, mono_mod_perms))
687
697
  valid_idx = np.where(check_masses(charge_masses, initial_masses, threshold))[0]
688
698
  if valid_idx.size == 0:
689
699
  continue
@@ -986,11 +996,11 @@ def subgraphs_to_domon_costello(nx_mono, subgs):
986
996
  cross_rings = [(v, k) for k, v in mono_mod_dict.items() if (k, v) not in node_dict.items()]
987
997
  cuts.extend(cross_rings)
988
998
  dc_cuts = node_labels_to_domon_costello(cuts, chain_rank, global_mods = global_mods)
989
- ion_names.append((dc_cuts))
999
+ ion_names.append(sorted(dc_cuts))
990
1000
  return ion_names
991
1001
 
992
1002
 
993
- def priority_filter(dc_names, diffs):
1003
+ def priority_filter(dc_names, diffs, peptide=False):
994
1004
  """Filters Domon-Costello fragment names by number of cleavages and difference from observed mass\n
995
1005
  | Arguments:
996
1006
  | :-
@@ -1000,7 +1010,10 @@ def priority_filter(dc_names, diffs):
1000
1010
  | :-
1001
1011
  | Returns a list of Domon-Costello fragment names sorted by number of cleavages and the observed mass difference
1002
1012
  """
1003
- sorted_frags = sorted(list(zip(dc_names, diffs)), key = lambda x:(len(x[0]), x[1]))
1013
+ if peptide:
1014
+ sorted_frags = sorted(list(zip(dc_names, diffs)), key = lambda x:(len([y for v in x[0] for y in v if y not in ['Peptide','M']]), x[1]))
1015
+ else:
1016
+ sorted_frags = sorted(list(zip(dc_names, diffs)), key = lambda x:(len(x[0]), x[1]))
1004
1017
  return [f[0] for f in sorted_frags]
1005
1018
 
1006
1019
 
@@ -1072,7 +1085,7 @@ def observed_fragments_checker(possible_fragments, observed_fragments):
1072
1085
  return [sums[i] - 1 if 'M' in ''.join(f) else sums[i] for i, f in enumerate(possible_fragments)]
1073
1086
 
1074
1087
 
1075
- def simplify_fragments(dc_names):
1088
+ def simplify_fragments(dc_names,peptide=False):
1076
1089
  """Sorts a list of possible fragments for each observed mass into a list of one fragment per observed mass\n
1077
1090
  | Arguments:
1078
1091
  | :-
@@ -1083,6 +1096,14 @@ def simplify_fragments(dc_names):
1083
1096
  | Returns a nested list with each list containing a single fragment or being empty
1084
1097
  """
1085
1098
  observed_frags = []
1099
+ if peptide:
1100
+ for possible_frags in dc_names:
1101
+ possible_frags = sorted(possible_frags, key = lambda x: len([y for v in x for y in v if y not in ['Peptide','M']]))
1102
+ if not possible_frags or len(possible_frags[0]) == 0:
1103
+ observed_frags.append([])
1104
+ else:
1105
+ observed_frags.append([possible_frags[0]])
1106
+ return observed_frags
1086
1107
  for possible_frags in dc_names:
1087
1108
  possible_frags = sorted(possible_frags, key = len)
1088
1109
  if not possible_frags or len(possible_frags[0]) == 0:
@@ -1132,34 +1153,36 @@ def create_glycopeptide_graph(peptide, glycans, glycosites):
1132
1153
  return glyco_pep,pep_gr
1133
1154
 
1134
1155
  def input_to_graph(input_dict):
1135
- if 'peptide' not in input_dict and 'glycosites' not in input_dict:
1156
+ if not input_dict['peptide'] and not input_dict['glycosites']:
1136
1157
  if isinstance(input_dict['glycans'],str):
1137
1158
  nx_mono = mono_graph_to_nx(glycan_to_graph_monos(input_dict['glycans']))
1138
1159
  return nx_mono,None
1139
1160
  if len(input_dict['glycans']) == 1:
1140
1161
  nx_mono = mono_graph_to_nx(glycan_to_graph_monos(input_dict['glycans'][0]))
1141
1162
  return nx_mono,None
1142
- if 'peptide' in input_dict:
1163
+ if input_dict['peptide']:
1143
1164
  nx_mono,pep_gr = create_glycopeptide_graph(input_dict['peptide'], input_dict['glycans'], input_dict['glycosites'])
1144
1165
  return nx_mono,pep_gr
1145
1166
 
1146
- def get_glycan_cleavages(gp,subg):
1167
+ def get_glycan_cleavages(gp,subg,glycosites):
1147
1168
  """Return Domon-Costello labels for all glycans on a glycopeptide"""
1148
- all_glycan_prefixes = set([x[0] for x in gp.nodes() if x[0]!='0'])
1149
1169
  subg_glycan_prefixes = set([x[0] for x in subg.nodes() if x[0]!='0'])
1170
+ subg_atom_dict = nx.get_node_attributes(subg,'atomic_mod_dict')
1150
1171
  all_mods = []
1151
- for prefix in all_glycan_prefixes:
1152
- if prefix in subg_glycan_prefixes:
1172
+ for prefix,glycosite in enumerate(glycosites,1):
1173
+ if str(prefix) in subg_glycan_prefixes:
1153
1174
  glyc = [x for x in gp.nodes() if f'{prefix}-' in x]
1154
1175
  subg_glyc = subg.subgraph(glyc)
1155
1176
  full_glyc = gp.subgraph(glyc)
1156
1177
  glyc_dc = subgraphs_to_domon_costello(full_glyc,[subg_glyc])
1157
- all_mods.append(glyc_dc[0])
1178
+ all_mods.extend(glyc_dc)
1179
+ elif f'0-{glycosite}' in subg_atom_dict and subg_atom_dict[f'0-{glycosite}'][3]:
1180
+ all_mods.append([f'{cut_type_dict[subg_atom_dict[f"0-{glycosite}"][3]]}_0_Alpha'])
1158
1181
  else:
1159
- all_mods.append(f'loss of glycan {prefix}')
1182
+ all_mods.append([f'loss of glycan {prefix}'])
1160
1183
  return all_mods
1161
1184
 
1162
- def peptide_to_RF_nomenclature(peptide,pep_subg,iupac = False):
1185
+ def peptide_to_RF_nomenclature(peptide,pep_subg, iupac = False):
1163
1186
  """Return Roepstorff and Fohlman peptide fragment nomenclature"""
1164
1187
  RF_cleavages = []
1165
1188
  all_peptide_nodes = list(peptide.nodes)
@@ -1168,6 +1191,7 @@ def peptide_to_RF_nomenclature(peptide,pep_subg,iupac = False):
1168
1191
  return ['No Peptide']
1169
1192
  pep_atom_dict = nx.get_node_attributes(pep_subg,'atomic_mod_dict')
1170
1193
  pep_atom_dict = {k:v for k,v in pep_atom_dict.items() if '0-' in k}
1194
+ global_mods = nx.get_node_attributes(pep_subg, 'global_mod')
1171
1195
  for node,cleavages in pep_atom_dict.items():
1172
1196
  for cleavage in [x for x in cleavages.values() if isinstance(x,str) and 'peptide' in x]:
1173
1197
  if cleavage[-1] in ['x','y','z']:
@@ -1177,14 +1201,17 @@ def peptide_to_RF_nomenclature(peptide,pep_subg,iupac = False):
1177
1201
  cut_site = all_peptide_nodes.index(node)+1
1178
1202
  RF_cleavages.append(f'{cleavage[-1]}_{cut_site}')
1179
1203
  else:
1180
- assert 1==1
1204
+ assert 1==2
1205
+ if global_mods:
1206
+ global_mods = list(global_mods.values())[0][0]
1207
+ RF_cleavages.append(f"M_{global_mods}")
1181
1208
  if not RF_cleavages:
1182
1209
  RF_cleavages = ['Peptide']
1183
1210
  if iupac == True:
1184
1211
  subg_peptide_labels = {k:v for k,v in nx.get_node_attributes(pep_subg,'string_labels').items() if '0-' in k}
1185
- return RF_cleavages,''.join([x[1] for x in sorted(subg_peptide_labels.items(),key=lambda x:x[0][-1])])
1212
+ return sorted(RF_cleavages),''.join([x[1] for x in sorted(subg_peptide_labels.items(),key=lambda x:x[0][-1])])
1186
1213
  else:
1187
- return RF_cleavages
1214
+ return sorted(RF_cleavages)
1188
1215
 
1189
1216
  def nested_lazy_product_vect(perm_lists, atom_dict_lists, global_mods, indices):
1190
1217
  """Calculates the permutation of glycan modifications based on indices of matching masses"""
@@ -1222,9 +1249,26 @@ def check_masses(desired_masses, new_masses, threshold):
1222
1249
  within_threshold = np.abs(f - d) < threshold
1223
1250
  return np.any(within_threshold, axis=1)
1224
1251
 
1252
+ def glycopeptide_string_to_input(gpep_string):
1253
+ input_dict = {k:[] for k in ['glycans','peptide','glycosites']}
1254
+ split_string = gpep_string.split("*")
1255
+ if len(split_string) == 1:
1256
+ chem_string = split_string[0]
1257
+ if "(" in chem_string or chem_string[-1] == 'c':
1258
+ input_dict['glycans'] = [chem_string]
1259
+ return input_dict
1260
+ else:
1261
+ input_dict['peptide'] = chem_string
1262
+ return input_dict
1263
+ else:
1264
+ input_dict['peptide'] = ''.join(split_string[::2])
1265
+ input_dict['glycans'] = split_string[1::2]
1266
+ input_dict['glycosites'] = np.cumsum([len(x) for x in split_string[::2][:-1]])-1
1267
+ return input_dict
1268
+
1225
1269
  @rescue_glycans
1226
- def CandyCrumbs(input_dict, fragment_masses, mass_threshold,
1227
- max_cleavages = 3, simplify = True, charge = -1, label_mass = 2.0156,
1270
+ def CandyCrumbs(input_string, fragment_masses, mass_threshold,
1271
+ max_cleavages = 3, simplify = True, charge = -1, mass_tag = None,
1228
1272
  iupac = False, intensities = None, disable_global_mods=False, disable_X_cross_rings=False):
1229
1273
  """Basic wrapper for the annotation of observed masses with correct nomenclature given a glycan\n
1230
1274
  | Arguments:
@@ -1235,41 +1279,44 @@ def CandyCrumbs(input_dict, fragment_masses, mass_threshold,
1235
1279
  | max_cleavages (int): maximum number of allowed concurrent fragmentations per mass; default:3
1236
1280
  | simplify (bool): whether to try condensing fragment options to the most likely option; default:True
1237
1281
  | charge (int): the charge state of the precursor ion (singly-charged, doubly-charged); default:-1
1238
- | label_mass (float): mass of the glycan label or reducing end modification; default:2.0156
1282
+ | mass_tag (float): mass of the glycan label or reducing end modification; default:2.0156
1239
1283
  | iupac (bool): whether to add the fragment sequence in IUPAC-condensed nomenclature to the annotations; default:False\n
1240
1284
  | Returns:
1241
1285
  | :-
1242
1286
  | Returns a list of tuples containing the observed mass and all of the possible fragment names within the threshold
1243
1287
  """
1244
1288
  hit_dict = {}
1289
+ input_dict = glycopeptide_string_to_input(input_string)
1245
1290
  fragment_masses = sorted(fragment_masses)
1246
1291
  nx_mono,pep_gr = input_to_graph(input_dict)
1247
1292
  global_mods,special_residues = get_initial_global_mods(nx_mono, charge,disable_global_mods = disable_global_mods)
1248
1293
  allowed_X_cleavages = [] if disable_X_cross_rings else X_cross_rings
1249
- subg_frags = generate_atomic_frags(nx_mono, global_mods, special_residues, allowed_X_cleavages,max_cleavages = max_cleavages, fragment_masses = fragment_masses, threshold = mass_threshold, label_mass = label_mass, charge = charge)
1294
+ subg_frags = generate_atomic_frags(nx_mono, global_mods, special_residues, allowed_X_cleavages,max_cleavages = max_cleavages, fragment_masses = fragment_masses, threshold = mass_threshold, mass_tag = mass_tag, charge = charge)
1250
1295
  downstream_values = []
1251
- if 'peptide' in input_dict:
1296
+ if input_dict['peptide']:
1297
+ peptide=True
1252
1298
  for observed_mass in fragment_masses:
1253
1299
  all_gp_names = []
1254
1300
  fragment_properties = match_fragment_properties(subg_frags, observed_mass, mass_threshold, charge)
1255
1301
  for frag_subg in fragment_properties[-1]:
1256
1302
  rf_names = peptide_to_RF_nomenclature(pep_gr,frag_subg)
1257
- dc_names = get_glycan_cleavages(nx_mono,frag_subg)
1258
- gp_names = rf_names + dc_names
1303
+ dc_names = get_glycan_cleavages(nx_mono,frag_subg,input_dict['glycosites'])
1304
+ gp_names = [rf_names] + dc_names
1259
1305
  all_gp_names.append(gp_names)
1260
1306
  downstream_values.append((*fragment_properties,all_gp_names))
1261
- else:
1307
+ else:
1308
+ peptide=False
1262
1309
  for observed_mass in fragment_masses:
1263
1310
  fragment_properties = match_fragment_properties(subg_frags, observed_mass, mass_threshold, charge)
1264
1311
  dc_names = subgraphs_to_domon_costello(nx_mono, fragment_properties[-1])
1265
1312
  downstream_values.append((*fragment_properties,dc_names))
1266
- filtered_dc_names = [priority_filter(x[5], x[2]) if x[0] else [] for x in downstream_values]
1313
+ filtered_dc_names = [priority_filter(x[5], x[2],peptide=peptide) if x[0] else [] for x in downstream_values]
1267
1314
  if simplify:
1268
- filtered_dc_names = simplify_fragments(filtered_dc_names)
1315
+ filtered_dc_names = simplify_fragments(filtered_dc_names,peptide=peptide)
1269
1316
  for i,frag_dc_names in enumerate(filtered_dc_names):
1270
1317
  if frag_dc_names:
1271
1318
  filtered_properties = list(zip(*downstream_values[i]))
1272
- final_hits = [[y for y in filtered_properties if y[5]==x][0] for x in frag_dc_names]
1319
+ final_hits = [[y for y in filtered_properties if y[5]==x][0] for x in frag_dc_names][:5]
1273
1320
  final_hits = [list(x) for x in list(zip(*final_hits))]
1274
1321
  hit_dict[fragment_masses[i]] = {'Theoretical fragment masses':final_hits[1],'Domon-Costello nomenclatures':final_hits[5], 'Fragment charges':final_hits[3]}
1275
1322
  if iupac:
@@ -59,9 +59,6 @@ class SimpleDataset(torch.utils.data.Dataset):
59
59
  self.x = x
60
60
  self.y = y
61
61
  self.transform_mz = transform_mz
62
- self.transform_prec = transform_prec
63
- self.transform_prec_neg = transform_prec_neg
64
- self.transform_prec_pos = transform_prec_pos
65
62
  self.transform_rt = transform_rt
66
63
 
67
64
  def __len__(self):
@@ -73,23 +70,16 @@ class SimpleDataset(torch.utils.data.Dataset):
73
70
  mz = self.transform_mz(mz)
74
71
  mz_r = self.x[index][1]
75
72
  prec = self.x[index][2]
76
- if self.transform_prec:
77
- prec = self.transform_prec(prec)
78
73
  glycan_type = self.x[index][3]
79
74
  RT = self.x[index][4]
80
75
  if self.transform_rt:
81
76
  RT = self.transform_rt(RT)
82
77
  mode = self.x[index][5]
83
- if any([self.transform_prec_neg, self.transform_prec_pos]):
84
- if mode == 0:
85
- prec = self.transform_prec_neg(prec)
86
- else:
87
- prec = self.transform_prec_pos(prec)
88
78
  lc = self.x[index][6]
89
79
  modification = self.x[index][7]
90
80
  trap = self.x[index][8]
91
81
  out = self.y[index]
92
- return torch.FloatTensor(mz), torch.FloatTensor(mz_r), torch.FloatTensor([prec]), torch.LongTensor([glycan_type]), torch.FloatTensor([RT]), torch.LongTensor([mode]), torch.LongTensor([lc]), torch.LongTensor([modification]), torch.LongTensor([trap]), torch.LongTensor([out])
82
+ return torch.FloatTensor(mz), torch.FloatTensor(mz_r), torch.FloatTensor(prec), torch.LongTensor([glycan_type]), torch.FloatTensor([RT]), torch.LongTensor([mode]), torch.LongTensor([lc]), torch.LongTensor([modification]), torch.LongTensor([trap]), torch.LongTensor([out])
93
83
 
94
84
 
95
85
  class ResUnit(nn.Module):
@@ -134,7 +124,7 @@ class CandyCrunch_CNN(torch.nn.Module):
134
124
  self.input_dim = input_dim
135
125
 
136
126
  self.mz_lin1 = torch.nn.Linear(input_dim, 2*hidden_dim)
137
- self.prec_lin1 = torch.nn.Linear(1, 24)
127
+ self.prec_lin1 = torch.nn.Linear(12, 24)
138
128
  self.rt_lin1 = torch.nn.Linear(1, 24)
139
129
  self.comb_lin1 = torch.nn.Linear(2*hidden_dim+24+24+24+24+24+24+24, 2*512)
140
130
  self.comb_lin2 = torch.nn.Linear(2*512, 2*256)