### Install glycowork with all extras Source: https://github.com/bojarlab/glycowork/blob/master/index.ipynb Install glycowork with all optional extras, including machine learning and chemical analysis functionalities. This provides the most comprehensive installation. ```bash pip install glycowork[all] ``` -------------------------------- ### MZ to Structures Example Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Provides an example of using mz_to_structures to find glycan structures corresponding to a given precursor mass. It specifies the glycan class 'O'. ```python mz_to_structures([674.29], glycan_class = 'O') ``` -------------------------------- ### Example: Plot Network Source: https://github.com/bojarlab/glycowork/blob/master/04_network.ipynb A simple example showing how to call the plot_network function with a previously constructed network object. ```python plot_network(network) ``` -------------------------------- ### Example: Construct and View Network Nodes Source: https://github.com/bojarlab/glycowork/blob/master/04_network.ipynb Demonstrates how to construct a glycan network from a list of glycan strings and then retrieve the nodes present in the constructed network. ```python glycans = ["Gal(b1-4)Glc-ol", "GlcNAc(b1-3)Gal(b1-4)Glc-ol", "GlcNAc6S(b1-3)Gal(b1-4)Glc-ol", "Gal(b1-4)GlcNAc(b1-3)Gal(b1-4)Glc-ol", "Fuc(a1-2)Gal(b1-4)Glc-ol", "Neu5Ac(a2-3)Gal(b1-4)GlcNAc(b1-3)[Gal(b1-3)GlcNAc(b1-6)]Gal(b1-4)Glc-ol"] network = construct_network(glycans) network.nodes() ``` -------------------------------- ### Install glycowork and nbdev hooks Source: https://github.com/bojarlab/glycowork/blob/master/CONTRIBUTING.md Install the project in editable mode with all development dependencies and set up nbdev's Git hooks. ```bash pip install -e ".[all,dev]" nbdev-install-hooks ``` -------------------------------- ### Prepare and Use LectinOracle Model Source: https://github.com/bojarlab/glycowork/blob/master/05_examples.ipynb Install fair-esm, import necessary modules, load an ESMC model, get protein representations, prepare the LectinOracle model, and predict glycan binding. ```python !pip install fair-esm from esm.models.esmc import ESMC from glycowork.ml.inference import get_esmc_representations, get_lectin_preds from glycowork.ml.models import prep_model model = ESMC.from_pretrained("esmc_300m") rep = get_esmc_representations(["QWERTFVCF"], model) leor = prep_model("LectinOracle", 1, trained = True) get_lectin_preds("QWERTFVCF", ['Neu5Ac(a2-6)GalNAc', 'Gal(b1-4)Glc'], leor, rep) ``` -------------------------------- ### Install glycowork with chemical analysis extras Source: https://github.com/bojarlab/glycowork/blob/master/index.ipynb Install glycowork with optional extras for analyzing atomic and chemical properties of glycans. This includes specialized libraries for chemical analysis. ```bash pip install glycowork[chem] ``` -------------------------------- ### Install glycowork from GitHub Source: https://github.com/bojarlab/glycowork/blob/master/index.ipynb Install the glycowork package directly from its GitHub repository. This is useful for installing the latest development version. ```bash pip install git+https://github.com/BojarLab/glycowork.git import glycowork ``` -------------------------------- ### Example: Plot Evolutionarily Pruned Network Source: https://github.com/bojarlab/glycowork/blob/master/04_network.ipynb Demonstrates plotting a network after it has been pruned using evolutionary data. This visualizes the result of the `evoprune_network` function. ```python plot_network(evoprune_network(network)) ``` -------------------------------- ### Install Glycowork with ML Dependencies Source: https://github.com/bojarlab/glycowork/blob/master/00_core.ipynb Install glycowork with optional dependencies for machine learning, which is necessary for running the `glycowork.ml` module, especially on systems requiring GPU support. ```bash !pip install "glycowork[ml]" ``` -------------------------------- ### ML Model Training Setup Source: https://github.com/bojarlab/glycowork/blob/master/02_ml.ipynb Prepares the optimizer, learning rate scheduler, and loss criterion for model training. Supports different prediction task modes and optional SAM optimizer. ```python def training_setup( model:Module, # graph neural network for analyzing glycans lr:float, # learning rate lr_patience:int=4, # epochs before reducing learning rate factor:float=0.2, # factor to multiply lr on reduction weight_decay:float=0.0001, # regularization parameter mode:str='multiclass', # type of prediction task num_classes:int=2, # number of classes for classification gsam_alpha:float=0.0, # if >0, uses GSAM instead of SAM optimizer warmup_epochs:int=5, # if >0, uses a learning rate warm-up schedule for training stability )->tuple: # optimizer, scheduler, criterion ``` -------------------------------- ### Tokenize Glycan String Example Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Demonstrates the usage of string_to_labels with a sample glycan string. The result shows None for each tokenized element, indicating no mapping was found in the default library. ```python string_to_labels(['Man','a1-3','Man','a1-6','Man']) ``` -------------------------------- ### ML Model Training Example Source: https://github.com/bojarlab/glycowork/blob/master/02_ml.ipynb Example of training a machine learning model using `train_ml_model` with feature calculation and returning features. Includes data splitting and model evaluation. ```python human = [1 if k == 'Homo_sapiens' else 0 for k in df_species[df_species.Order=='Primates'].Species.values.tolist()] X_train, X_test, y_train, y_test = general_split(df_species[df_species.Order=='Primates'].glycan.values.tolist(), human) model_ft, _, X_test = train_ml_model(X_train, X_test, y_train, y_test, feature_calc = True, feature_set = ['terminal'], return_features = True) ``` -------------------------------- ### Install glycowork with pip Source: https://github.com/bojarlab/glycowork/blob/master/index.ipynb Install the glycowork package using pip. This is the standard method for installing Python packages. ```bash pip install glycowork import glycowork ``` -------------------------------- ### Pad Glycan Sequence Example Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Illustrates padding a tokenized glycan sequence to a target length of 7 using the pad_sequence function. The output shows the original sequence followed by padding tokens. ```python pad_sequence(string_to_labels(['Man','a1-3','Man','a1-6','Man']), 7) ``` -------------------------------- ### Install PyTorch and PyTorch Geometric Source: https://github.com/bojarlab/glycowork/blob/master/05_examples.ipynb Install specific versions of PyTorch and PyTorch Geometric for deep learning. Ensure these versions are compatible with the glycowork library. ```bash !pip install torch==2.5.1 !pip install torch-geometric==2.6.0 ``` -------------------------------- ### Condense Composition Matching Example Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Demonstrates the usage of condense_composition_matching after matching a composition. It takes a list of matching glycans and returns a condensed list. ```python match_comp = match_composition_relaxed({'Hex':1, 'HexNAc':1, 'Neu5Ac':1}, glycan_class = 'O') print(match_comp) condense_composition_matching(match_comp) ``` -------------------------------- ### Example: Extracting Sequence from N-glycan Branch Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Demonstrates using get_match to extract a specific sequence from the a1-6 branch of N-glycans, showcasing the use of quantifiers and lookaheads in the pattern. ```python # {} = between min and max occurrences, e.g., "Hex-HexNAc-([Hex|Fuc]){1,2}-HexNAc" # * = zero or more occurrences, e.g., "Hex-HexNAc-([Hex|Fuc])*-HexNAc" # + = one or more occurrences, e.g., "Hex-HexNAc-([Hex|Fuc])+-HexNAc" # ? = zero or one occurrence, e.g., "Hex-HexNAc-([Hex|Fuc])?-HexNAc" # {1,} = at minimum one occurrence, e.g., "Hex-HexNAc-([Hex|Fuc]){1,}-HexNAc" # {,1} = at maximum one occurrence, e.g., "Hex-HexNAc-([Hex|Fuc]){,1}-HexNAc" # {2} = exactly two occurrences, e.g., "Hex-HexNAc-([Hex|Fuc]){2}-HexNAc" # ^ = start of sequence, e.g., "^Hex-HexNAc-([Hex|Fuc]){1,2}-HexNAc" # % = middle of sequence (i.e., neither start nor end) # $ = end of sequence, e.g., "Hex-HexNAc-([Hex|Fuc]){1,2}-HexNAc$" # ?<= = lookbehind (i.e., provided pattern must be present before rest of pattern but is not included in match), e.g., "(?<=Xyl-)Hex-HexNAc-([Hex|Fuc]){1,2}-HexNAc" # ?dict: # dict of protein sequence:ESMC-300M representation ``` ```bash !pip install fair-esm ``` ```python from esm.models.esmc import ESMC model = ESMC.from_pretrained("esmc_300m").to(device) ``` -------------------------------- ### Show Documentation for mz_to_composition Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Displays the documentation for the mz_to_composition function, which maps mass spectrometry m/z values to potential glycan compositions. ```python show_doc(mz_to_composition) ``` -------------------------------- ### Train a SweetNet Model Source: https://github.com/bojarlab/glycowork/blob/master/05_examples.ipynb Prepare data, split it for training and validation, initialize a SweetNet model, set up the optimizer and loss function, and train the model for a specified number of epochs. ```python train_x, val_x, train_y, val_y, id_val, class_list, class_converter = hierarchy_filter(df_species, rank = 'Kingdom') dataloaders = split_data_to_train(train_x, val_x, train_y, val_y) model = models.prep_model('SweetNet', len(class_list)) optimizer_ft, scheduler, criterion = model_training.training_setup(model, 0.0005, num_classes = len(class_list)) model_ft = model_training.train_model(model, dataloaders, criterion, optimizer_ft, scheduler, num_epochs = 100) ``` -------------------------------- ### Misclassification Analysis Example Source: https://github.com/bojarlab/glycowork/blob/master/02_ml.ipynb Example of using `get_mismatch` to find and display the top misclassifications of a trained ML model. ```python get_mismatch(model_ft, X_test, y_test) ``` -------------------------------- ### Show Documentation for string_to_labels Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Displays the documentation for the string_to_labels function, which is used for tokenizing glycan strings. ```python show_doc(string_to_labels) ``` -------------------------------- ### Run preparation and tests Source: https://github.com/bojarlab/glycowork/blob/master/CONTRIBUTING.md Execute nbdev_prepare to ensure the project is ready for development and run the pytest suite to verify all tests pass. ```bash nbdev-prepare cd tests pytest ``` -------------------------------- ### Prepare and Use LectinOracle_flex Model Source: https://github.com/bojarlab/glycowork/blob/master/05_examples.ipynb Import necessary modules, prepare the LectinOracle_flex model with flex=True, and predict glycan binding directly using protein sequences. ```python from glycowork.ml.inference import get_lectin_preds from glycowork.ml.models import prep_model leor = prep_model("LectinOracle_flex", 1, trained = True) get_lectin_preds("QWERTFVCF", ['Neu5Ac(a2-6)GalNAc', 'Gal(b1-4)Glc'], leor, flex = True) ``` -------------------------------- ### Show Documentation for compositions_to_structures Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Displays the documentation for the compositions_to_structures function. This function converts a list of glycan compositions into their corresponding structures. ```python show_doc(compositions_to_structures) ``` -------------------------------- ### get_esmc_representations Source: https://github.com/bojarlab/glycowork/blob/master/02_ml.ipynb Retrieves ESMC-300M representations of protein sequences, which can be used as input for models like LectinOracle. Requires installation of the 'fair-esm' package. ```APIDOC ## get_esmc_representations ### Description Retrieves ESMC-300M representations of protein sequences, which can be used as input for models like LectinOracle. Requires installation of the 'fair-esm' package. ### Method N/A (Function Call) ### Prerequisites ```bash !pip install fair-esm ``` ```python from esm.models.esmc import ESMC model = ESMC.from_pretrained("esmc_300m").to(device) ``` ### Parameters - **prots** (list) - Required - list of protein sequences to convert. - **model** (Module) - Required - trained ESMC model. ### Returns - dict - Dictionary of protein sequence:ESMC-300M representation. ``` -------------------------------- ### Show Documentation for mz_to_structures Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Displays the documentation for the mz_to_structures function. This function maps precursor masses to glycan structures, supporting relative intensities and various matching parameters. ```python show_doc(mz_to_structures) ``` -------------------------------- ### Show Documentation for get_heatmap Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Displays the documentation for the get_heatmap function. ```python show_doc(get_heatmap) ``` -------------------------------- ### Get Possible Linkages with Wildcard Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Retrieves all linkages from a predefined list that match a given wildcard pattern. The wildcard character '?' can be used to match any character. ```python show_doc(get_possible_linkages) get_possible_linkages("a1-?") ``` -------------------------------- ### Display Documentation for get_glycoshift_per_site Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Displays the documentation for the get_glycoshift_per_site function, outlining its parameters and return types. This is useful for understanding the function's capabilities before implementation. ```python show_doc(get_glycoshift_per_site) ``` -------------------------------- ### Get Biodiversity Metrics Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Calculates alpha and beta diversity measures from glycomics data. Use when comparing diversity between groups or analyzing motif diversity. ```python def get_biodiversity( df:pandas.core.frame.DataFrame | str | pathlib.Path, # DataFrame with glycans in rows (col 1), abundances in columns group1:list, # First group column indices or group labels group2:list, # Second group indices or additional group labels metrics:list=['alpha', 'beta'], # Diversity metrics to calculate motifs:bool=False, # Analyze motifs instead of sequences feature_set:list=['exhaustive', 'known'], # Feature sets to use; exhaustive, known, terminal1, terminal2, terminal3, chemical, graph, custom, size_branch custom_motifs:list=[], # Custom motifs if using 'custom' feature set paired:bool=False, # Whether samples are paired permutations:int=999, # Number of permutations for ANOSIM/PERMANOVA transform:str | None=None, # Transformation type: "CLR" or "ALR" gamma:float=0.1, # Uncertainty parameter for CLR transform custom_scale:float | dict=0, # Ratio of total signal in group2/group1 for an informed scale model (or group_idx: mean(group)/min(mean(groups)) signal dict for multivariate) random_state:int | numpy.random._generator.Generator | None=None, # optional random state for reproducibility )->tuple: # First DataFrame with diversity indices and test statistics, second with beta-diversity distance matrix ``` -------------------------------- ### Show Documentation for SweetNet Source: https://github.com/bojarlab/glycowork/blob/master/02_ml.ipynb Displays the documentation for the SweetNet model. This model is designed for graph-based glycan analysis. ```python show_doc(SweetNet) ``` ```python def SweetNet( lib_size:int, # number of unique tokens for graph nodes num_classes:int=1, # number of output classes (>1 for multilabel) hidden_dim:int=128, # dimension of hidden layers )->None: ``` -------------------------------- ### Get Terminal Structures of a Glycan Source: https://github.com/bojarlab/glycowork/blob/master/index.ipynb Identifies and returns the terminal glycan structures within a larger glycan sequence. This is useful for analyzing the non-reducing end of glycans. ```python #or you could find the terminal epitopes of a glycan from glycowork.motif.annotate import get_terminal_structures print("\nTerminal structures:") print(get_terminal_structures('Man(a1-3)[Man(a1-6)]Man(b1-4)GlcNAc(b1-4)[Fuc(a1-6)]GlcNAc')) ``` -------------------------------- ### Find Nth Occurrence of Motif Source: https://github.com/bojarlab/glycowork/blob/master/01_glycan_data.ipynb Locates the starting index of the n-th occurrence of a substring (needle) within a larger string (haystack). Note that 'n' is not zero-indexed. ```python show_doc(find_nth) ``` ```python find_nth('This is as good as it gets', 'as', 2) ``` -------------------------------- ### Show Documentation for get_representative_substructures Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Displays the documentation for the get_representative_substructures function. ```python show_doc(get_representative_substructures) ``` -------------------------------- ### Import Libraries and Ignore Warnings Source: https://github.com/bojarlab/glycowork/blob/master/index.ipynb Imports necessary libraries for data manipulation and visualization, and suppresses warning messages. This is a common setup for data analysis tasks. ```python #| include: false import warnings warnings.filterwarnings("ignore") from IPython.display import HTML import pandas as pd import re ``` -------------------------------- ### Display Documentation for glytoucan_to_glycan Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Displays the documentation for the `glytoucan_to_glycan` function. This is useful for understanding the function's parameters and return types. ```python show_doc(glytoucan_to_glycan) ``` -------------------------------- ### Stemify Glycan Example Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Demonstrates removing modifications from a complex glycan string using stemify_glycan. The output shows the glycan with modifications like 'Ac' and 'S' removed. ```python stemify_glycan("Neu5Ac9Ac(a2-3)Gal6S(b1-3)[Neu5Ac(a2-6)]GalNAc") ``` -------------------------------- ### Initialize Model Weights Source: https://github.com/bojarlab/glycowork/blob/master/02_ml.ipynb Initializes linear layers of a PyTorch model with a specified weight initialization algorithm and sparsity. ```python def init_weights( model:Module, # neural network for analyzing glycans mode:str='sparse', # initialization algorithm: 'sparse', 'kaiming', 'xavier' sparsity:float=0.1, # proportion of sparsity after initialization )->None: ``` -------------------------------- ### Prepare PyTorch Model Source: https://github.com/bojarlab/glycowork/blob/master/02_ml.ipynb A wrapper function to instantiate, initialize, and move a PyTorch model to the GPU. Supports different model types and pretrained options. ```python def prep_model( model_type:Literal, # type of model to create num_classes:int, # number of unique classes for classification libr:dict[str, int] | None=None, # dictionary of form glycoletter:index trained:bool=False, # whether to use pretrained model hidden_dim:int=128, # hidden dimension for the model (SweetNet only) )->Module: # initialized PyTorch model ``` -------------------------------- ### Get Glycan Embeddings Source: https://github.com/bojarlab/glycowork/blob/master/02_ml.ipynb Generates learned representations for a list of glycans using a trained GNN model. Requires a list of glycans in IUPAC-condensed format and the trained model. ```python show_doc(glycans_to_emb) ``` ```python def glycans_to_emb( glycans:list, # list of glycans in IUPAC-condensed model:Module, # trained graph neural network for analyzing glycans libr:dict[str, int] | None=None, # dictionary of form glycoletter:index batch_size:int=32, # batch size used during training rep:bool=True, # True returns representations, False returns predicted labels class_list:list[str] | None=None, # list of unique classes to map predictions multilabel:bool=False, # whether to output predictions for a multilabel-task )->pandas.core.frame.DataFrame | list[str]: # dataframe of representations or list of predictions ``` -------------------------------- ### Display get_match_batch Documentation Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Displays the documentation for the get_match_batch function, which is used for finding glyco-regular expression matches across a list of glycans. ```python show_doc(get_match_batch) ``` -------------------------------- ### Get Biosynthetic Coherence Function Signature Source: https://github.com/bojarlab/glycowork/blob/master/04_network.ipynb Defines the function signature for get_biosynthetic_coherence, which takes a DataFrame of glycan abundances and group information to test for differences in biosynthetic coherence between groups. ```python def get_biosynthetic_coherence( df:DataFrame, # Glycan abundances (glycans as index or first column, samples as columns) group1:list, # First group column names group2:list, # Second group column names network:networkx.classes.digraph.DiGraph | None=None, # Pre-built network; built from df if not provided paired:bool=False, # Whether samples are paired )->DataFrame: # Test results with group means, difference, t-statistic, p-value, and Cohen's d ``` -------------------------------- ### Show Documentation for match_composition_relaxed Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Displays the documentation for the match_composition_relaxed function, which finds matching glycans for a given coarse-grained composition. ```python show_doc(match_composition_relaxed) ``` -------------------------------- ### Get Bayes Factor from p-value Source: https://github.com/bojarlab/glycowork/blob/master/01_glycan_data.ipynb Transforms a p-value into Jeffreys' approximate Bayes factor (BF). Use this to quantify evidence for the alternative hypothesis (H1) over the null hypothesis (H0). ```python def get_BF( n:int, # sample size p:float, # p-value z:bool=False, # True if p-value from z-statistic, False if t-statistic method:str='robust', # method for choice of 'b': "JAB", "min", "robust", "balanced" upper:float=10, # upper limit for range of realistic effect sizes )->float: # Bayes factor in favor of H1 *Transforms a p-value into Jeffreys' approximate Bayes factor (BF)* ``` ```python get_BF(6, 0.05) ``` -------------------------------- ### Show Documentation for condense_composition_matching Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Displays the documentation for the condense_composition_matching function. This function is used to find a minimal set of representative glycans that characterize a matched composition. ```python show_doc(condense_composition_matching) ``` -------------------------------- ### Get SparCC Correlation Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Calculates SparCC (Sparse Correlations for Compositional Data) between two matching datasets. Use for analyzing correlations in glycomics data, especially when dealing with compositional data. ```python def get_SparCC( df1:pandas.core.frame.DataFrame | str | pathlib.Path, # First DataFrame with glycans in rows (col 1) and abundances in columns df2:pandas.core.frame.DataFrame | str | pathlib.Path, # Second DataFrame with same format as df1 motifs:bool=False, # Analyze motifs instead of sequences feature_set:list=['known', 'exhaustive'], # Feature sets to use; exhaustive, known, terminal1, terminal2, terminal3, chemical, graph, custom, size_branch custom_motifs:list=[], # Custom motifs if using 'custom' feature set transform:str | None=None, # Transformation type: "CLR" or "ALR" gamma:float=0.1, # Uncertainty parameter for CLR transform partial_correlations:bool=False, # Use regularized partial correlations )->tuple: # (Spearman correlation matrix, FDR-corrected p-value matrix) ``` -------------------------------- ### Get Representative Substructures Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Constructs minimal glycan structures that represent significantly enriched motifs. This function optimizes for motif content while minimizing structure size using subgraph isomorphism. ```python get_representative_substructures(enrichment_df) ``` -------------------------------- ### Get Maximum Flow Path from Flow Dictionary Source: https://github.com/bojarlab/glycowork/blob/master/04_network.ipynb Retrieves the specific path of edges that contribute to the maximum flow between a source and a given sink, using the flow results obtained from `get_maximum_flow`. ```python show_doc(get_reaction_flow) ``` -------------------------------- ### Display Documentation for annotate_dataset Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Displays the documentation for the `annotate_dataset` function, outlining its parameters for batch glycan annotation. ```python show_doc(annotate_dataset) ``` -------------------------------- ### Displaying Documentation for get_insight Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Use `show_doc` to display the documentation for the `get_insight` function, which is used for querying glycan databases. ```python show_doc(get_insight) ``` -------------------------------- ### Prepare and Display Fish Glycan Data Source: https://github.com/bojarlab/glycowork/blob/master/05_examples.ipynb Creates a deep copy of the fish glycan dataframe, sets 'glycan' as the index, and displays the first few rows with custom styling. ```python #| echo: false df_fish2 = copy.deepcopy(df_fish) df_fish2.set_index("glycan", inplace = True) df_fish2.head().style.set_properties(**{'font-size': '11pt', 'font-family': 'Helvetica','border-collapse': 'collapse','border': '1px solid black'}) ``` -------------------------------- ### Display get_match Documentation Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Displays the documentation for the get_match function, which is used for finding glyco-regular expression matches in glycans. ```python show_doc(get_match) ``` -------------------------------- ### Get Aggregated Reaction Flows Source: https://github.com/bojarlab/glycowork/blob/master/04_network.ipynb Calculates and returns the flow values for each reaction type within a biosynthetic network, based on the flow results from `get_maximum_flow`. Aggregation options include sum or mean. ```python show_doc(get_differential_biosynthesis) ``` -------------------------------- ### Show Documentation for stemify_dataset Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Displays the documentation for the stemify_dataset function, which applies glycan stemming to an entire dataset. ```python show_doc(stemify_dataset) ``` -------------------------------- ### Show Documentation for get_pvals_motifs Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Displays the documentation for the get_pvals_motifs function. ```python show_doc(get_pvals_motifs) ``` -------------------------------- ### Get Unique Topologies for Composition Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Retrieves a list of all observed unique base topologies for a given glycan composition and class. This function can be filtered by taxonomic rank and value, and supports custom monosaccharide mappings. ```python get_unique_topologies({'HexNAc':2, 'Hex':1}, 'O', universal_replacers = {'dHex':'Fuc'}) ``` -------------------------------- ### Get Possible Monosaccharides by Type Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Retrieves a set of common monosaccharide names that match a specified type. Supported types include Hex, HexNAc, dHex, Sia, HexA, Pen, HexOS, and HexNAcOS. ```python show_doc(get_possible_monosaccharides) get_possible_monosaccharides("HexNAc") ``` -------------------------------- ### Show Documentation for pad_sequence Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Displays the documentation for the pad_sequence function, used to standardize the length of glycan sequences. ```python show_doc(pad_sequence) ``` -------------------------------- ### Prepare and Display Glycan Dataframe Source: https://github.com/bojarlab/glycowork/blob/master/01_glycan_data.ipynb Creates a copy of the species dataframe, sets 'glycan' as the index, and displays the first few rows with custom styling. This is useful for preparing data for indexed lookups and visual inspection. ```python #| echo: false df_species2 = copy.deepcopy(df_species) df_species2.set_index("glycan", inplace = True) df_species2.head().style.set_properties(**{'font-size': '11pt', 'font-family': 'Helvetica','border-collapse': 'collapse','border': '1px solid black'}) ``` -------------------------------- ### Display Documentation for annotate_glycan Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Displays the documentation for the `annotate_glycan` function, showing its parameters and return types. ```python show_doc(annotate_glycan) ``` -------------------------------- ### Analyze Motifs for Rhythmic Expression using JTK Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Adapt the get_jtk function to analyze motifs instead of sequences by setting `motifs=True`. This example also specifies a `feature_set` to include only terminal motifs. Ensure your input DataFrame is correctly formatted. ```python t_dic = {} t_dic["Neu5Ac(a2-3)Gal(b1-3)GalNAc"] = [0.433138901, 0.149729209, 0.358018822, 0.537641256, 1.526963756, 1.349986672, 0.75156406, 0.736710183] t_dic["Gal(b1-3)GalNAc"] = [0.919762334, 0.760237184, 0.725566662, 0.459945797, 0.523801515, 0.695106926, 0.627632047, 1.183511209] t_dic["Gal(b1-3)[Neu5Ac(a2-6)]GalNAc"] = [0.533138901, 0.119729209, 0.458018822, 0.637641256, 1.726963756, 1.249986672, 0.55156406, 0.436710183] t_dic["Fuc(a1-2)Gal(b1-3)GalNAc"] = [3.862169504, 5.455032837, 3.858163289, 5.614650335, 3.124254095, 4.189550337, 4.641831312, 4.19538484] tps = 8 # number of timepoints in experiment periods = [8] # potential cycles to test interval = 3 # units of time between experimental timepoints t_df = pd.DataFrame(t_dic).T t_df.columns = ["T3", "T6", "T9", "T12", "T15", "T18", "T21", "T24"] get_jtk(t_df.reset_index(), tps, interval, periods = periods, motifs = True, feature_set = ['terminal']) ``` -------------------------------- ### Get Glycoshift Per Site Function Signature Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Provides the function signature for get_glycoshift_per_site, detailing input parameters such as DataFrame, group indices, pairing status, imputation, minimum samples, gamma, custom scale, and random state. It also specifies the return type as a DataFrame containing GLM coefficients and FDR-corrected p-values. ```python def get_glycoshift_per_site( df:pandas.core.frame.DataFrame | str | pathlib.Path, # DataFrame with rows formatted as 'protein_site_composition' in col 1, abundances in remaining cols group1:list, # First group indices/names or group labels for multi-group group2:list, # Second group indices/names paired:bool=False, # Whether samples are paired impute:bool=True, # Replace zeros with Random Forest model min_samples:float=0.2, # Min percent of non-zero samples required gamma:float=0.1, # Uncertainty parameter for CLR transform custom_scale:float | dict=0, # Ratio of total signal in group2/group1 for an informed scale model (or group_idx: mean(group)/min(mean(groups)) signal dict for multivariate) random_state:int | numpy.random._generator.Generator | None=None, # optional random state for reproducibility )->DataFrame: # DataFrame with GLM coefficients and FDR-corrected p-values ``` -------------------------------- ### Display Documentation for quantify_motifs Source: https://github.com/bojarlab/glycowork/blob/master/03_motif.ipynb Displays the documentation for the `quantify_motifs` function, which is used for quantifying motifs within a dataset of glycans. ```python show_doc(quantify_motifs) ``` -------------------------------- ### Show Documentation for LectinOracle_flex Source: https://github.com/bojarlab/glycowork/blob/master/02_ml.ipynb Displays the documentation for the flexible LectinOracle model. This version allows for more adaptable input sizes, particularly for protein representations. ```python show_doc(LectinOracle_flex) ``` ```python def LectinOracle_flex( input_size_glyco:int, # number of unique tokens for graph nodes hidden_size:int=128, # layer size for graph convolutions num_classes:int=1, # number of output classes (>1 for multilabel) data_min:float=-11.355, # minimum observed value in training data data_max:float=23.892, # maximum observed value in training data input_size_prot:int=1000, # maximum protein sequence length for padding/cutting )->None: ``` -------------------------------- ### Constructing and Plotting a Biosynthetic Network Source: https://github.com/bojarlab/glycowork/blob/master/05_examples.ipynb Builds a biosynthetic network from a list of glycans and visualizes it. Assumes default parameters are suitable for milk glycans. ```python glycans = ["Gal(b1-4)Glc-ol", "GlcNAc(b1-3)Gal(b1-4)Glc-ol", "GlcNAc6S(b1-3)Gal(b1-4)Glc-ol", "Gal(b1-4)GlcNAc(b1-3)Gal(b1-4)Glc-ol", "Fuc(a1-2)Gal(b1-4)Glc-ol", "Gal(b1-4)GlcNAc(b1-3)[Gal(b1-3)GlcNAc(b1-6)]Gal(b1-4)Glc-ol"] network = construct_network(glycans) plot_network(network) ```