Skip to content

Commit

Permalink
add node_group_dict back to the vis module; revert the example in the…
Browse files Browse the repository at this point in the history
… doc website
  • Loading branch information
haozhu233 committed May 11, 2024
1 parent 44b2c56 commit 25b57c6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 111 deletions.
6 changes: 2 additions & 4 deletions docs/quick_tour.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,9 @@ You can also apply the clustering information to your visual.

```python
>>> gene_group_dict = dict()
>>> gene_group_dict = {g:[
>>> 'red', 'blue', 'yellow', 'green'
>>> ][c] for g, c in zip(nxg.nodes(), node_labels)}
>>> gene_group_dict = {g:str(c) for g, c in zip(nxg.nodes(), node_labels)}
>>> g = grn.visualize_local_neighborhood(
>>> 'HIST1H1D', k=40, node_color_dict=gene_group_dict
>>> 'HIST1H1D', k=40, node_group_dict=gene_group_dict
>>> )
>>> g.show('view.html')
```
Expand Down
136 changes: 31 additions & 105 deletions example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 3,
"id": "bc3a63a5-b5dc-4ec3-82b6-b8cb2dd341b1",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Training loss: 0.233, Change on Adj: -0.000: 100%|███████████████████████████████████████████████████████████████| 1000/1000 [00:06<00:00, 149.83it/s]\n"
"Training loss: 0.208, Change on Adj: -0.000: 100%|████████████████████████████████████████████████████████| 1000/1000 [00:07<00:00, 131.75it/s]\n"
]
}
],
Expand All @@ -161,21 +161,21 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 4,
"id": "31bd6acc-bf8f-4e67-a0e7-fdc85ed1abde",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'AUROC': 0.6132166098363903,\n",
" 'AUPR': 0.05205800776865746,\n",
" 'AUPRR': 2.447880617451527,\n",
" 'EP': 748,\n",
" 'EPR': 4.148199666781842}"
"{'AUROC': 0.6121613001722375,\n",
" 'AUPR': 0.05236067534187729,\n",
" 'AUPRR': 2.462112704267227,\n",
" 'EP': 761,\n",
" 'EPR': 4.220294046017355}"
]
},
"execution_count": 21,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -198,7 +198,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 4,
"id": "52ea6e49-9f2e-4662-914d-c6f5c9d92a85",
"metadata": {},
"outputs": [
Expand All @@ -208,7 +208,7 @@
"Inferred GRN: 1,620 TFs x 1,620 Target Genes"
]
},
"execution_count": 22,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -280,7 +280,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 7,
"id": "1d5bac96-23f4-4aa8-87b9-f5ecd6362e60",
"metadata": {},
"outputs": [
Expand All @@ -290,7 +290,7 @@
"'HIST1H1D'"
]
},
"execution_count": 23,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -311,7 +311,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 5,
"id": "6c64e64a-9d05-41b2-ad8e-611347dcc074",
"metadata": {},
"outputs": [
Expand All @@ -337,10 +337,10 @@
" "
],
"text/plain": [
"<IPython.lib.display.IFrame at 0x2afeaaa89a50>"
"<IPython.lib.display.IFrame at 0x2b4caf056150>"
]
},
"execution_count": 24,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -360,7 +360,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 6,
"id": "48469757-7d04-4daf-88ea-b3ff34000190",
"metadata": {},
"outputs": [
Expand All @@ -370,11 +370,11 @@
"text": [
"/cluster/tufts/slonimlab/hzhu07/miniconda3/envs/grn/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n",
"Computing transition probabilities: 100%|███████████████████████████████████████████████████████████████████████████| 52/52 [00:00<00:00, 1973.90it/s]\n",
"Generating walks (CPU: 3): 100%|█████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 172.69it/s]\n",
"Generating walks (CPU: 1): 100%|█████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 172.33it/s]\n",
"Generating walks (CPU: 2): 100%|█████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 170.24it/s]\n",
"Generating walks (CPU: 4): 100%|█████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 169.11it/s]\n",
"Computing transition probabilities: 100%|████████████████████████████████████████████████████████████████████| 49/49 [00:00<00:00, 2035.81it/s]\n",
"Generating walks (CPU: 2): 100%|██████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 201.35it/s]\n",
"Generating walks (CPU: 4): 100%|██████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 206.38it/s]\n",
"Generating walks (CPU: 1): 100%|██████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 177.20it/s]\n",
"Generating walks (CPU: 3): 100%|██████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 155.50it/s]\n",
"/cluster/tufts/slonimlab/hzhu07/miniconda3/envs/grn/lib/python3.11/site-packages/sklearn/cluster/_kmeans.py:1416: FutureWarning: The default value of `n_init` will change from 10 to 'auto' in 1.4. Set the value of `n_init` explicitly to suppress the warning\n",
" super()._check_params_vs_input(X, default_n_init=10)\n"
]
Expand All @@ -384,10 +384,10 @@
"output_type": "stream",
"text": [
"Clusters:\n",
"Cluster 0: RBL1,H1F0,KAT2B\n",
"Cluster 1: MCM6,MCM4,RBBP4,SP1,RRM2,EZH2,MCM10,UNG,RAD51,UHRF1,E2F1,MCM3,PCNA,MCM7,BARD1,ABTB1\n",
"Cluster 2: GM44335,TOP2A,KPNA2,GM10184,POLR3B,FZR1,ATF4\n",
"Cluster 3: FBXO5,HIST1H1D,KNTC1,BRCA1,RAD54B,HIST1H2BL,HIST1H2BB,HIST1H3H,HIST1H2AC,HIST1H2BF,HIST1H1A,DNMT1,HIST1H4K,HIST1H1B,HIST1H2AK,HIST1H2BN,HIST1H2AI,HIST1H2BK,HIST1H2AG,HIST1H2AF,EGR1,GM26448,TAF1,DEK,GM9531,GM37404\n"
"Cluster 0: FBXO5,HIST1H1D,GM44335,KNTC1,RAD54B,BRCA1,DNMT1,HIST1H1B,HIST1H2BN,HIST1H2BK,HIST1H2BL,HIST1H2AC,HIST1H1A,HIST1H2BB,HIST1H3H,HIST1H2AK,HIST1H2AF,HIST1H2AG,HIST1H2AI,HIST1H2BF,HIST1H4K,TAF1,DEK,GM9531,ABTB1,GM26448,EGR1\n",
"Cluster 1: MAZ,GM37404,RBL1,STAG3\n",
"Cluster 2: RRM2,PCNA,MCM6,RAD51,MCM10,MCM7,UHRF1,BARD1,E2F1,MCM4,RBBP4,ZFP367,UNG,MCM3\n",
"Cluster 3: TOP2A,GM10184,KANK3,POLR3B\n"
]
}
],
Expand Down Expand Up @@ -417,79 +417,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"id": "1497f58c-4619-4eaf-ace3-176a4ad858aa",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'FBXO5': '3',\n",
" 'HIST1H1D': '3',\n",
" 'KNTC1': '3',\n",
" 'BRCA1': '3',\n",
" 'GM44335': '2',\n",
" 'RAD54B': '3',\n",
" 'HIST1H2BL': '3',\n",
" 'HIST1H2BB': '3',\n",
" 'HIST1H3H': '3',\n",
" 'HIST1H2AC': '3',\n",
" 'HIST1H2BF': '3',\n",
" 'HIST1H1A': '3',\n",
" 'DNMT1': '3',\n",
" 'HIST1H4K': '3',\n",
" 'HIST1H1B': '3',\n",
" 'HIST1H2AK': '3',\n",
" 'HIST1H2BN': '3',\n",
" 'HIST1H2AI': '3',\n",
" 'HIST1H2BK': '3',\n",
" 'HIST1H2AG': '3',\n",
" 'HIST1H2AF': '3',\n",
" 'EGR1': '3',\n",
" 'GM26448': '3',\n",
" 'TAF1': '3',\n",
" 'MCM6': '1',\n",
" 'DEK': '3',\n",
" 'MCM4': '1',\n",
" 'RBBP4': '1',\n",
" 'RBL1': '0',\n",
" 'SP1': '1',\n",
" 'RRM2': '1',\n",
" 'EZH2': '1',\n",
" 'MCM10': '1',\n",
" 'UNG': '1',\n",
" 'RAD51': '1',\n",
" 'UHRF1': '1',\n",
" 'E2F1': '1',\n",
" 'MCM3': '1',\n",
" 'PCNA': '1',\n",
" 'MCM7': '1',\n",
" 'TOP2A': '2',\n",
" 'BARD1': '1',\n",
" 'H1F0': '0',\n",
" 'KPNA2': '2',\n",
" 'GM10184': '2',\n",
" 'POLR3B': '2',\n",
" 'FZR1': '2',\n",
" 'ATF4': '2',\n",
" 'GM9531': '3',\n",
" 'KAT2B': '0',\n",
" 'ABTB1': '1',\n",
" 'GM37404': '3'}"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gene_group_dict"
]
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 7,
"id": "a22e59ec-33a2-4560-86e0-67cc5725e4b5",
"metadata": {},
"outputs": [
Expand All @@ -515,21 +443,19 @@
" "
],
"text/plain": [
"<IPython.lib.display.IFrame at 0x2afefb4b45d0>"
"<IPython.lib.display.IFrame at 0x2b4d66fb7290>"
]
},
"execution_count": 29,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gene_group_dict = dict()\n",
"gene_group_dict = {g:[\n",
" 'red', 'blue', 'yellow', 'green'\n",
"][c] for g, c in zip(nxg.nodes(), node_labels)}\n",
"gene_group_dict = {g:str(c) for g, c in zip(nxg.nodes(), node_labels)}\n",
"g = grn.visualize_local_neighborhood(\n",
" 'HIST1H1D', k=40, node_color_dict=gene_group_dict\n",
" 'HIST1H1D', k=40, node_group_dict=gene_group_dict\n",
" )\n",
"g.show('view.html')"
]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ maintainers = [
]
readme = "README.md"
license = {file = "LICENSE"}
version = "0.0.7"
version = "0.0.8"
description = "Gene Regulatory Networks Inference using diffusion model"

classifiers = ["License :: OSI Approved :: Apache Software License"]
Expand Down
6 changes: 5 additions & 1 deletion regdiffusion/plot/pyvis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def plot_pyvis(
node_size: int = 8,
font_size: int = 30,
node_color_dict: Dict = None,
node_group_dict: Dict = None,
cdn_resources: str = 'remote', notebook: bool = True):
"""
Generate a vis.js network visualization given an edge list
Expand All @@ -21,6 +22,8 @@ def plot_pyvis(
font_size (int): The font size for nodes labels.
node_color_dict (dict): A dictionary with keys being the names of
genes and values being the color.
node_group_dict (dict): A dictionary with keys being the names of
genes and values being the group.
cdn_resources (str): Where to load vis.js resources. Default is
'remote'.
notebook (bool): Boolean value indicating whether the visualization
Expand All @@ -41,8 +44,9 @@ def plot_pyvis(
node_shape = 'star' if node in star_genes else 'dot'
this_node_size = 2 * node_size if node in star_genes else node_size
node_color = None if node_color_dict is None else node_color_dict[node]
node_group = None if node_group_dict is None else node_group_dict[node]
g.add_node(node, label=node, size=this_node_size,
shape=node_shape, color=node_color,
shape=node_shape, color=node_color, group=node_group,
font={"size": font_size})

if 'edge_width' in pandas_edgelist.columns:
Expand Down

0 comments on commit 25b57c6

Please sign in to comment.