mobiusklein / glypy

Glycan Analysis and Glycoinformatics Library for Python
Apache License 2.0
27 stars 14 forks source link

Mass calculation GlycanComposition #25

Closed tiskapot closed 1 year ago

tiskapot commented 1 year ago

Hi

If a GlycanComposition is used directly to calculate the mass, I am able to get the average and the monoisotopic mass, but when a GlycanComposition is assigned to a variable, it always returns the average mass regardless whether the average argument is True or False. Is there a way to obtain the monoisotopic mass?

from glypy import GlycanComposition

print(GlycanComposition(Hex=3, HexNAc=1).mass(average=True))
print(GlycanComposition(Hex=3, HexNAc=1).mass(average=False))
print("")

gly = GlycanComposition(Hex=3, HexNAc=1)

print(gly.mass(average=True))
print(gly.mass(average=False))
707.6259521715149
707.2484074587101

707.6259521715149
707.6259521715149
mobiusklein commented 1 year ago

Hello,

Thank you for pointing this out, I've been using this in a vacuum. GlycanComposition and it's subclasses cache the first calculation of mass automatically, but I failed to document this. I've pushed a new commit to the master branch that will only cache the monoisotopic mass, which I still need to be on the fastest path.

If you can use the latest commit to confirm the behavior meets your needs, I can cut a new release on PyPI. If not convenient, it's a simple enough change that I've already tested against your examples and they look correct to me so I can just release it directly.

tiskapot commented 1 year ago

Seems to work fine. Thanks!

mobiusklein commented 1 year ago

Release v1.0.8 contains this fix.