<jupyter_start><jupyter_text>**Filepaths** MON_SMILES : .csv or .txt file of macromolecule monomersBOND_SMILES : .csv or .txt file of macromolecule bondsTXT_DATA_PATH : For dataset, to be used for trainingDF_PATH : For dataset, to be used for graph labels during trainingMODEL_PATH : For models, to be used when training to save the model, optimizer, and configuration fileFIG_PATH : For plots, to be used when saving ROC-AUC or parity plot figures<jupyter_code>MON_SMILES = './tables/SMILES_glycans_monomer.txt'
BOND_SMILES = './tables/SMILES_glycans_bond.txt'

TXT_DATA_PATH = './dataset/classification/'
DF_PATH = './tables/glycobase_immuno_mini.txt'
MODEL_PATH = './'
FIG_PATH = './'<jupyter_output><empty_output><jupyter_text>**Variables** FEAT : Type of features for macromolecule monomers and bonds -- fingerprints ('fp') or one-hot encodings ('onehot') (default = 'fp')FP_RADIUS_MON : Radius of topological exploration for monomer fingerprint (default = 3)FP_BITS_MON : Size of fingerprint bit-vector for monomer (default = 128)FP_RADIUS_BOND : Radius of topological exploration for bond fingerprint (default = 3)FP_BITS_BOND : Size of fingerprint bit-vector for bond (default = 16)SEED : Random seed for shuffling dataset (default = 108)TASK : Learning task (classification, regression) (default = 'classification')MODEL : Model architecture for supervised learning (Weave, MPNN, Attentive FP, GCN, GAT) (default = 'Weave')LABELNAME : Name of label to classify (default = 'Immunogenic')SPLIT : Proportion of the dataset to use for training, validation and test (default = '0.8,0.1,0.1')NORM: Normalization method for regression labels -- quantile transform ('qt') or standard scaler ('ss') (default = 'qt')NUM_EPOCHS: Maximum number of epochs allowed for training (default = 1000)NUM_WORKERS: Number of processes for data loading (default: 1)SAVE_MODEL: Whether to save full model file. Model state dict will be saved automatically (default = False)SAVE_OPT: Whether to save optimizer files (default = False)SAVE_CONFIG: Whether to save configuration file (default = False)PLOT_TYPE: Dataset to plot ('val' for validation or 'test' for test)CUSTOM_PARAMS: Dictionary of hyperparameters for model<jupyter_code>FEAT = 'fp'
FP_RADIUS_MON = 3
FP_BITS_MON = 128
FP_RADIUS_BOND = 3
FP_BITS_BOND = 16

SEED = 108
TASK = 'classification'
MODEL = 'AttentiveFP'
LABELNAME = 'Immunogenic'
SPLIT = '0.6,0.2,0.2'
NORM = 'qt'

NUM_EPOCHS = 10
NUM_WORKERS = 1

SAVE_MODEL = False
SAVE_OPT = False
SAVE_CONFIG = False

PLOT_TYPE = 'val'

CUSTOM_PARAMS = {}<jupyter_output><empty_output><jupyter_text>**Load featurized NetworkX graphs**<jupyter_code>NX_GRAPHS = networkx_feat(
    TXT_DATA_PATH = TXT_DATA_PATH, 
    MON_SMILES = MON_SMILES, 
    BOND_SMILES = BOND_SMILES, 
    FEAT = FEAT, 
    FP_RADIUS_MON = FP_RADIUS_MON, 
    FP_RADIUS_BOND = FP_RADIUS_BOND, 
    FP_BITS_MON = FP_BITS_MON, 
    FP_BITS_BOND = FP_BITS_BOND
)
plot.graph(NX_GRAPHS['GBID10271'])
plot.graph(NX_GRAPHS['GBID10330'])<jupyter_output>{0: 'Glc', 1: 'QuiNBut', 2: 'Glc', 3: 'GlcOAcA', 4: 'GlcNAc', 5: 'QuiNBut'}<jupyter_text>Alignment of 2 arbitrary graphs - Similarity Computation<jupyter_code>unsup.edit_distance(NX_GRAPHS['GBID10271'], NX_GRAPHS['GBID10330'])<jupyter_output><empty_output><jupyter_text>Unsupervised Learning<jupyter_code>sim_matrix = unsup.similarity_matrix(dict_graphs = NX_GRAPHS)
embeddings = unsup.dimensionality_reduction(
    matrix = sim_matrix, 
    method = 'umap', 
    n_neighbors=3)
unsup.plot_embeddings(
    embeddings = embeddings, 
    NX_GRAPHS = NX_GRAPHS, 
    DF_PATH = DF_PATH, 
    method = 'UMAP')<jupyter_output><empty_output><jupyter_text>**Load DGL dataset with labels and masks**<jupyter_code>dgl_dict = MacroDataset(
    DF_PATH = DF_PATH, 
    SEED = SEED, 
    TASK = TASK, 
    LABELNAME = LABELNAME, 
    MODEL = MODEL, 
    NX_GRAPHS = NX_GRAPHS, 
    NORM = NORM)<jupyter_output><empty_output><jupyter_text>Supervised learning Training model and obtaining validation and test metrics<jupyter_code>random.seed(SEED)

macro_supervised = MacroSupervised(
    MacroDataset = dgl_dict, 
    MON_SMILES = MON_SMILES, 
    BOND_SMILES = BOND_SMILES, 
    FEAT = FEAT, 
    FP_BITS_MON = FP_BITS_MON, 
    FP_BITS_BOND = FP_BITS_BOND, 
    SEED = SEED, 
    MODEL = MODEL, 
    SPLIT = SPLIT, 
    NUM_EPOCHS = NUM_EPOCHS, 
    NUM_WORKERS = NUM_WORKERS, 
    CUSTOM_PARAMS = CUSTOM_PARAMS, 
    MODEL_PATH = MODEL_PATH, 
    SAVE_MODEL = SAVE_MODEL, 
    SAVE_OPT = SAVE_OPT, 
    SAVE_CONFIG = SAVE_CONFIG)
macro_supervised.main()
macro_supervised.rocauc_plot('test', './')<jupyter_output><empty_output><jupyter_text>Attribution<jupyter_code>random.seed(SEED)
input_graph = dgl_dict.graphs[0]

attribution = Attribution(
    model_name = MODEL, 
    attribution_type = 'integrated_gradients')

attribution.calculate_attribution(
    model_instance = macro_supervised.model, 
    input_graph = input_graph)
attribution.plot_graph(
    input_graph = input_graph, 
    NX_GRAPHS = NX_GRAPHS)
attribution.plot_fp(node_idx=0)
index = 16
mol, bi = attribution.display_substructure(
    monomer = 'Xyl', 
    MON_SMILES_PATH = MON_SMILES, 
    RADIUS = FP_RADIUS_MON, 
    N_BITS = FP_BITS_MON)
Draw.DrawMorganBit(mol, index, bi)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09726962457337884, 'fraction_numerical': 0.013651877133105802, 'mean_word_length': 5.176814988290398, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '440481', 'license': 'MIT', 'n_tokens_mistral': 2110, 'n_tokens_neox': 1898, 'n_words': 438, 'path': 'Tutorial.ipynb', 'repo_name': 'learningmatter-mit/GLAMOUR', 'size': '5274'}