BojarLab / glycowork

Package for processing and analyzing glycans and their role in biology.
https://Bojarlab.github.io/glycowork
MIT License
56 stars 11 forks source link

annotate_figure() cannot draw terminal glycans #51

Closed mattias-erhardsson closed 3 months ago

mattias-erhardsson commented 3 months ago

anootate_figure() does not draw terminal glycan structures generated by for example get_differential_expression(). Example code:

import pandas as pd
from glycowork.motif.analysis import get_differential_expression
from glycowork.motif.analysis import get_volcano
from glycowork.motif.draw import annotate_figure
from glycowork.motif.draw import GlycoDraw
data = {
    'Glycan': ['Gal(b1-3)GalNAc', 'GalOS(b1-3)GalNAc', 'Gal(b1-3)[Fuc(a1-?)]GalNAc', 'GlcNAc(b1-2)Man(a1-3)Man', 'Man(a1-6)[Man(a1-3)]Man(b1-4)GlcNAc(b1-4)GlcNAc', 'Neu5Ac(a2-6)Gal(b1-4)GlcNAc(b1-2)Man', 'Neu5Ac(a2-3)Gal(b1-3)GalNAc'],
    'Sample1': [1.1, 0.2, 0.3, 0.5, 0.7, 1.0, 0.6],
    'Sample2': [1.2, 0.1, 0.2, 0.4, 0.8, 0.9, 0.5],
    'Sample3': [0.1, 1.8, 1.9, 0.3, 0.6, 0.8, 1.2],
    'Sample4': [0.2, 1.1, 1.2, 0.2, 0.5, 0.7, 1.1],
    'Sample5': [1.3, 0.3, 0.4, 0.6, 0.9, 1.1, 0.7],
    'Sample6': [1.4, 0.4, 0.5, 0.7, 1.0, 1.2, 0.8],
    'Sample7': [0.3, 1.9, 2.0, 0.4, 0.7, 0.9, 1.3],
    'Sample8': [0.4, 1.2, 1.3, 0.3, 0.6, 0.8, 1.2]
}
differential_glycomics_df = pd.DataFrame(data)

# Define the groups
group1 = ['Sample1', 'Sample2', 'Sample5', 'Sample6']
group2 = ['Sample3', 'Sample4', 'Sample7', 'Sample8']

differential_expression = get_differential_expression(df = differential_glycomics_df,
                            group1 = group1,
                            group2 = group2,
                            motifs = True,
                            feature_set = ['terminal1', 'terminal2', 'terminal3'],
                            paired = False,
                            min_samples = 0.1)

print(differential_expression)
# Differential glycomics volcano plot
volcano = get_volcano(differential_expression,
                      y_thresh = 0.05,
                      annotate_volcano = True,
                      filepath = './volcano.svg')

For an example that works, just replace the feature_set with 'exhaustive' or 'known'.

GlycoDraw can draw terminal glycans, even though it looks a bit weird. It seems to be interpreted as a modification called "Terminal_" on the left-most glycan. Example:

GlycoDraw('Terminal_Gal(b1-?)[Fuc(a1-?)]GalNAc')

A more logical representation might perhaps be to draw a linkage at the reducing end? If so it seems to me that this would require changes in how terminal structures are determined.

Bribak commented 3 months ago

Thanks! On the dev branch, we have recently changed the nomenclature of dynamically generated terminal motifs, to have a "Terminal_" prefix (to really make it clear that this is a terminal motif, rather than the implicit dangling linkage we had before). But you're right in that GlycoDraw was not yet synced with this. Now GlycoDraw correctly handles terminal structures again

The same with annotatefigure; it basically looks for text on the figure that could be a glycan; was confused with the "Terminal" but now can handle it

This issue is fixed with 21049e1