Skip to content

Commit

Permalink
Monster commit: cluster migration, python2/3 compatibility, GlycanDat…
Browse files Browse the repository at this point in the history
…a release, new GlycanData model and export strategy, image generation, GlycanResource changes
  • Loading branch information
edwardsnj committed Jun 28, 2021
1 parent a754a86 commit 74adb50
Show file tree
Hide file tree
Showing 249 changed files with 205,194 additions and 458,898 deletions.
2 changes: 1 addition & 1 deletion pygly/CompositionTable.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import re
from collections import defaultdict
from ConstantsTable import ConstantsTable
from . ConstantsTable import ConstantsTable

class Composition(defaultdict):
def __init__(self,*args,**kw):
Expand Down
4 changes: 2 additions & 2 deletions pygly/ConstantsTable.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

from ReferenceTable import ReferenceTable
from Monosaccharide import constantLookup
from . ReferenceTable import ReferenceTable
from . Monosaccharide import constantLookup

class ConstantsTable(ReferenceTable):
def parseSection(self,name,kv):
Expand Down
4 changes: 2 additions & 2 deletions pygly/ElementMass.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

from __future__ import print_function

from ElementTable import ElementTable
from IsoShape import IsoShape
from . ElementTable import ElementTable
from . IsoShape import IsoShape

class MonoisotopicElementMass(dict):
def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion pygly/ElementTable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from ReferenceTable import ReferenceTable
from . ReferenceTable import ReferenceTable

class Element:
def __init__(self,name,symbol,mono,ave,isotopes):
Expand Down
13 changes: 8 additions & 5 deletions pygly/GNOme.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,10 @@ def all_synonym(self):



from alignment import GlycanSubsumption, GlycanEqual, GlycanEqualWithWURCSCheck
from Monosaccharide import Anomer
from GlycanResource import GlyTouCan, GlyCosmos
from manipulation import Topology, Composition, BaseComposition
from . alignment import GlycanSubsumption, GlycanEqual, GlycanEqualWithWURCSCheck
from . Monosaccharide import Anomer
from . GlycanResource import GlyTouCan, GlyCosmos
from . manipulation import Topology, Composition, BaseComposition


class SubsumptionGraph(GNOmeAPI):
Expand Down Expand Up @@ -2387,8 +2387,8 @@ def score(self, g):
res = int(res * 10000)
return res

def main():

if __name__ == "__main__":
cmd = sys.argv[1]
sys.argv.pop(1)

Expand Down Expand Up @@ -2594,3 +2594,6 @@ def symFile2dict(fpath):
else:
print >> sys.stderr, "Bad command: %s" % (cmd,)
sys.exit(1)

if __name__ == "__main__":
main()
100 changes: 49 additions & 51 deletions pygly/Glycan.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
try:
from itertools import permutations, product
except ImportError:
from combinatorics import permutations, product
from . combinatorics import permutations, product

from combinatorics import itermatchings, iterecmatchings
from . combinatorics import itermatchings, iterecmatchings

from Monosaccharide import Monosaccharide, Linkage, Mod
from MonoFormatter import IUPACSym, LinCodeSym
from . Monosaccharide import Monosaccharide, Linkage, Mod
from . MonoFormatter import IUPACSym, LinCodeSym

iupacSym = IUPACSym()
lcSym = LinCodeSym()

from CompositionTable import Composition,ResidueCompositionTable,PermethylCompositionTable
from ElementMass import MonoisotopicElementMass
from MonoFactory import MonoFactory
from MonoFormatter import MassSym
from . CompositionTable import Composition,ResidueCompositionTable,PermethylCompositionTable
from . ElementMass import MonoisotopicElementMass
from . MonoFactory import MonoFactory
from . MonoFormatter import MassSym

ctable = ResidueCompositionTable()
pctable = PermethylCompositionTable()
Expand Down Expand Up @@ -87,7 +87,7 @@ def undetermined_roots(self):
for ec in self._undetermined:
for r in ec:
yield r

def undetermined_root_reprs(self):
if self._undetermined != None:
for ec in self._undetermined:
Expand Down Expand Up @@ -195,14 +195,14 @@ def fully_determined(self):
## bad = True
## break
## if bad:
## continue
## continue
## bad = False
## for m,c in counts.items():
## if c > 1:
## bad = True
## break
## if bad:
## continue
## continue
## # print counts,counts1
## self.add_instantiation(inst)

Expand Down Expand Up @@ -248,7 +248,7 @@ def uninstantiate(self):
return self
self.set_instantiation(set())
return self

def instantiation_count(self):
total = 1
for ur in self.undetermined_roots():
Expand Down Expand Up @@ -283,10 +283,10 @@ def dfsvisit_post(self,f,m=None,subst=False):

class SubtreeCompositionVisit:
def __init__(self,sym=None,comp=None):

self.sym = sym
self.comp = comp

def visit(self,m):

if self.comp:
Expand All @@ -307,10 +307,10 @@ def visit(self,m):

class ElementalCompositionVisit:
def __init__(self,comp):

self.table = comp
self.eltcomp = Composition()

def visit(self,m):
self.eltcomp.add(m.composition(self.table))

Expand Down Expand Up @@ -353,7 +353,7 @@ def composition(self,force=False):

def native_elemental_composition(self):
return self.elemental_composition(ctable)

def permethylated_elemental_composition(self):
return self.elemental_composition(pctable)

Expand All @@ -364,7 +364,7 @@ def underivitized_molecular_weight(self,adduct='H2O'):
def permethylated_molecular_weight(self,adduct='C2H6O'):
return self.permethylated_elemental_composition().mass(elmt) + \
Composition.fromstr(adduct).mass(elmt)

def fragments(self,r=None,force=False):
atroot = False
if r == None:
Expand All @@ -381,7 +381,7 @@ def fragments(self,r=None,force=False):
copy.copy(r._elemental_composition),True,0)
yield fr
return

fragstore0 = []
fragstore1 = []
for l in links:
Expand Down Expand Up @@ -449,29 +449,29 @@ def all_nodes(self,subst=False,undet_subst=False):
iupac_aldi_composition_syms = ['Man+aldi','Gal+aldi','Glc+aldi','Fuc+aldi','ManNAc+aldi','GlcNAc+aldi','GalNAc+aldi','Hex+aldi','HexNAc+aldi','dHex+aldi']
subst_composition_syms = ['S','P','Me','aldi']

def iupac_composition(self, floating_substituents=True,
aggregate_basecomposition=True,
def iupac_composition(self, floating_substituents=True,
aggregate_basecomposition=True,
redend_only=False):
validsyms = self.iupac_composition_syms + self.subst_composition_syms
if not floating_substituents:
validsyms += self.iupac_aldi_composition_syms
validsyms = self.iupac_composition_syms + self.subst_composition_syms
if not floating_substituents:
validsyms += self.iupac_aldi_composition_syms

c = Composition()
for sym in (validsyms + ['Xxx','X']):
c[sym] = 0
if not redend_only:
nodeiterable = self.all_nodes(undet_subst=True)
else:
if self.has_root():
nodeiterable = [ self.root() ]
else:
nodeiterable = []
if not redend_only:
nodeiterable = self.all_nodes(undet_subst=True)
else:
if self.has_root():
nodeiterable = [ self.root() ]
else:
nodeiterable = []
for m in nodeiterable:

try:
sym = iupacSym.toStr(m)
except KeyError:
if isinstance(m,Monosaccharide):
if isinstance(m,Monosaccharide):
c['Xxx'] += 1
else:
c['X'] += 1
Expand All @@ -487,7 +487,7 @@ def iupac_composition(self, floating_substituents=True,
syms[0] = 'Xxx'
else:
syms[0] = 'X'

for i in range(1,len(syms)):
if syms[i] not in self.subst_composition_syms:
syms[i] = 'X'
Expand Down Expand Up @@ -515,23 +515,23 @@ def iupac_composition(self, floating_substituents=True,
c['Sia'] = sum(map(c.__getitem__,('NeuAc','NeuGc','Sia')))
c['HexA'] = sum(map(c.__getitem__,('GlcA','GalA','IdoA','ManA','HexA')))
c['HexN'] = sum(map(c.__getitem__,('GlcN','GalN','ManN','HexN')))

return c

def iupac_redend(self, floating_substituents=True, aggregate_basecomposition=True):
comp = self.iupac_composition(floating_substituents=floating_substituents,
aggregate_basecomposition=aggregate_basecomposition,
redend_only=True)
return [ key for key in comp if comp[key] > 0 and key not in self.subst_composition_syms and key != "Count"]
comp = self.iupac_composition(floating_substituents=floating_substituents,
aggregate_basecomposition=aggregate_basecomposition,
redend_only=True)
return [ key for key in comp if comp[key] > 0 and key not in self.subst_composition_syms and key != "Count"]

def glycoct(self):
from GlycanFormatter import GlycoCTFormat
from . GlycanFormatter import GlycoCTFormat
if not self.glycoctformat:
self.glycoctformat = GlycoCTFormat()
return self.glycoctformat.toStr(self)

def glycam(self):
from GlycanFormatter import IUPACGlycamFormat
from . GlycanFormatter import IUPACGlycamFormat
if not self.glycamformat:
self.glycamformat = IUPACGlycamFormat()
return self.glycamformat.toStr(self)
Expand Down Expand Up @@ -598,7 +598,7 @@ def equals(self,g):
# then the ids of each monosaccharide in each glycan will match
# their counterpart.

self.set_ids()
self.set_ids()
g.unset_ids()

if self.has_root() and g.has_root():
Expand Down Expand Up @@ -727,7 +727,7 @@ def __str__(self):
def dump(self, m=None, level=0, branch='', monofmt=iupacSym):
if m == None:
m = self.root()

br = branch + " " + monofmt.toStr(m)
child_list = []

Expand All @@ -746,8 +746,8 @@ def dump(self, m=None, level=0, branch='', monofmt=iupacSym):

if __name__ == '__main__':

from MonoFactory import MonoFactory
from Monosaccharide import Linkage
from . MonoFactory import MonoFactory
from . Monosaccharide import Linkage
mf = MonoFactory()

gc1 = mf.new("GlcNAc")
Expand All @@ -760,7 +760,7 @@ def dump(self, m=None, level=0, branch='', monofmt=iupacSym):
m1 = mf.new('bdMan')
m2 = mf.new('adMan')
m3 = mf.new('adMan')

gc2.add_child(m1,parent_pos=4,
parent_type=Linkage.oxygenPreserved,
child_type=Linkage.oxygenLost)
Expand All @@ -779,7 +779,7 @@ def dump(self, m=None, level=0, branch='', monofmt=iupacSym):
m3.add_child(gc4,parent_pos=2,
parent_type=Linkage.oxygenPreserved,
child_type=Linkage.oxygenLost)

g1 = mf.new('bdGal')
gc3.add_child(g1,parent_pos=4,
parent_type=Linkage.oxygenPreserved,
Expand All @@ -801,11 +801,11 @@ def dump(self, m=None, level=0, branch='', monofmt=iupacSym):
gc4.add_child(f1,parent_pos=4,child_pos=1,
parent_type=Linkage.oxygenPreserved,
child_type=Linkage.oxygenLost)

g = Glycan(gc1)

print(g.glycoct())

g.dump()

print(g.str()+'\n')
Expand All @@ -826,5 +826,3 @@ def dump(self, m=None, level=0, branch='', monofmt=iupacSym):

# for fr in sorted(set(map(lambda fr: str(fr[0]),g.fragments()))):
# print fr


12 changes: 6 additions & 6 deletions pygly/GlycanFormatter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

from __future__ import print_function

from MonoFormatter import GlycoCTMonoFormat, LinCodeSym, LinCodeRank, IUPACSym, GlycamSym
from Monosaccharide import Monosaccharide, Linkage, Anomer, Substituent, Mod
from Glycan import Glycan
from MonoFactory import MonoFactory
from . MonoFormatter import GlycoCTMonoFormat, LinCodeSym, LinCodeRank, IUPACSym, GlycamSym
from . Monosaccharide import Monosaccharide, Linkage, Anomer, Substituent, Mod
from . Glycan import Glycan
from . MonoFactory import MonoFactory

import re, sys, traceback
import copy
Expand Down Expand Up @@ -1310,7 +1310,7 @@ class UnexpectedFloatingSubstError(WURCS20ParseError):
def __init__(self,instr):
self.message = "WURCS2.0 parser: Unexpected floating substituent:\n %s"%(instr,)

import WURCS20MonoFormatter
from . import WURCS20MonoFormatter

class WURCS20Format(GlycanFormatter):
def __init__(self):
Expand Down Expand Up @@ -1349,7 +1349,7 @@ def toGlycan(self,s):
raise ZeroPlusLinkCountError()
else:
raise UndeterminedLinkCountError()
counts = map(int,m.group(1).split(','))
counts = list(map(int,m.group(1).split(',')))
distinctmono = {}; mono = {};
for i,ms in enumerate(m.group(2)[1:-1].split('][')):
distinctmono[i+1] = ms
Expand Down
Loading

0 comments on commit 74adb50

Please sign in to comment.