<jupyter_start><jupyter_text>Metabolites directed graph<jupyter_code>from cameo.network_analysis.networkx_based import model_to_network
plt.figure(figsize=(20, 10))
G = model_to_network(model, max_distance=1)
# Conversion from directed multi graph to directed graph
G = nx.DiGraph(G)
nx.draw_kamada_kawai(G, with_labels=True)
plt.show()<jupyter_output><empty_output><jupyter_text>Adjacency matrix of directed multi graph<jupyter_code>G_mulit = model_to_network(model, max_distance=1)
A = nx.to_pandas_adjacency(G_mulit)
A<jupyter_output><empty_output><jupyter_text>Adjacency matrix of directed graph<jupyter_code>A = nx.to_pandas_adjacency(G)
A<jupyter_output><empty_output><jupyter_text>Feature vector fo embedded graph<jupyter_code>import scipy.stats as stats

def embed_graph(G):
    graph_embedding = pd.DataFrame(index=[model.id])
    
    for value, feature in zip([G.in_degree(), G.out_degree(), nx.clustering(G)], ['vertex in degree', 'vertex out degree', 'clustering coefficient']):
        vector = np.asarray(list(dict(value).values()))
        graph_embedding['avg ' + feature] = vector.mean()
        graph_embedding['std ' + feature] = vector.std()
        graph_embedding['kurtosis ' + feature] = stats.kurtosis(vector)
        graph_embedding['skewness ' + feature] = stats.skew(vector)
        
    G = nx.Graph(G)
    for value, feature in zip([nx.eccentricity(G)], ['vertex eccentricity']):
        vector = np.asarray(list(dict(value).values()))
        graph_embedding['avg ' + feature] = vector.mean()
        graph_embedding['std ' + feature] = vector.std()
        graph_embedding['kurtosis ' + feature] = stats.kurtosis(vector)
        graph_embedding['skewness ' + feature] = stats.skew(vector)
        
    graph_embedding['avg node connectivity'] = nx.average_node_connectivity(G)
    graph_embedding['diameter'] = nx.diameter(G)
    graph_embedding['avg node connectivity'] = nx.average_node_connectivity(G)
    graph_embedding['avg shortest path length'] = nx.average_shortest_path_length(G)
    
    return graph_embedding
    
embed_graph(G)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12363290537327627, 'fraction_numerical': 0.0028530670470756064, 'mean_word_length': 5.170087976539589, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '247753', 'license': 'MIT', 'n_tokens_mistral': 743, 'n_tokens_neox': 719, 'n_words': 121, 'path': 'analysis/metabolic_pathways_visualisation.ipynb', 'repo_name': 'andrzejmalota/Metabolic_Pathways_Analysis', 'size': '2103'}