Skip to content

Commit

Permalink
Remove python-louvain as a necessary dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Bribak committed Mar 9, 2024
1 parent 3d0290d commit c22ded5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
1 change: 0 additions & 1 deletion glycowork.egg-info/requires.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ xgboost
mpld3
pandas>=1.3
matplotlib-inline
python-louvain

[all]
torch_geometric
Expand Down
21 changes: 9 additions & 12 deletions glycowork/network/evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import pickle
import numpy as np
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
from community import community_louvain
from scipy.spatial.distance import cosine
from scipy.cluster.hierarchy import dendrogram, linkage
from glycowork.motif.graph import subgraph_isomorphism
Expand Down Expand Up @@ -189,26 +189,23 @@ def check_conservation(glycan, df, network_dic = None, rank = 'Order', threshold
return conserved


def get_communities(graph_list, label_list = None):
def get_communities(network_list, label_list = None):
"""Find communities for each graph in a list of graphs\n
| Arguments:
| :-
| graph_list (list): list of undirected biosynthetic networks, in the form of networkx objects
| network_list (list): list of undirected biosynthetic networks, in the form of networkx objects
| label_list (list): labels to create the community names, which are running_number + _ + label[k] for graph_list[k]; default:range(len(graph_list))\n
| Returns:
| :-
| Returns a merged dictionary of community : glycans in that community
"""
# Perform community detection on each network graph
comm_list = [community_louvain.best_partition(g) for g in graph_list]
if label_list is None:
label_list = list(range(len(comm_list)))
label_list = list(range(len(network_list)))
final_comm_dict = {}
# Label the communities by species name and running number to distinguish them afterwards
for comm_dict, label in zip(comm_list, label_list):
updated_dict = {
f"{value}_{label}": [k for k, v in comm_dict.items() if v == value]
for value in set(comm_dict.values())
}
final_comm_dict.update(updated_dict)
for i, network in enumerate(network_list):
communities = nx.algorithms.community.louvain.louvain_communities(network)
for comm_index, community in enumerate(communities):
comm_name = f"{comm_index}_{label_list[i]}"
final_comm_dict[comm_name] = list(community)
return final_comm_dict
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
install_requires=["scikit-learn", "regex", "networkx>=3.0",
"statsmodels", "scipy", "torch",
"seaborn", "xgboost", "mpld3",
"pandas>=1.3", "matplotlib-inline",
"python-louvain"],
"pandas>=1.3", "matplotlib-inline"],
extras_require={'all':["torch_geometric", "CairoSVG",
"drawSvg~=2.0", "glyles", "pubchempy", "requests",
"Pillow", "openpyxl"],
Expand Down

0 comments on commit c22ded5

Please sign in to comment.