Skip to content

Commit

Permalink
📌 v0.2.2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
xiachenrui committed Oct 26, 2023
1 parent fba97cf commit 5d3c59b
Show file tree
Hide file tree
Showing 15 changed files with 1,645 additions and 184 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*.gz
*.whl
*.html
*.DS_Store

# folder
**/conda/
Expand Down
213 changes: 147 additions & 66 deletions benchmark/analysis/aggr_datasets.ipynb

Large diffs are not rendered by default.

173 changes: 83 additions & 90 deletions benchmark/analysis/celltype_region_analysis.ipynb

Large diffs are not rendered by default.

248 changes: 248 additions & 0 deletions benchmark/analysis/check_MERFISH.ipynb

Large diffs are not rendered by default.

245 changes: 245 additions & 0 deletions benchmark/analysis/hetero.ipynb

Large diffs are not rendered by default.

466 changes: 466 additions & 0 deletions benchmark/analysis/plot_confusion_matrix.ipynb

Large diffs are not rendered by default.

376 changes: 376 additions & 0 deletions benchmark/analysis/plot_keypoints.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions benchmark/config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#-------------------------------- Global ----------------------------------#
timeout: 24h
timehold: 200h
seed: 8
seed: 1
sample: 0
fix_sample: True

use:
# - benchmark
- perturb
- benchmark
# - perturb
# - split_data
# - build_3d

Expand Down
2 changes: 1 addition & 1 deletion benchmark/profiles/impetus/impetus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ __default__:
output: ".slurm/{rule}.out"
error: ".slurm/{rule}.err"
account: gglab
partition: cpu2
partition: fat2
n_node: 1
n_task: 1
n_cpu: "{threads}"
Expand Down
2 changes: 1 addition & 1 deletion benchmark/workflow/notebooks/data_split.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.8.17"
},
"orig_nbformat": 4,
"vscode": {
Expand Down
79 changes: 69 additions & 10 deletions benchmark/workflow/notebooks/emb2metrics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"import pandas as pd\n",
"import scanpy as sc\n",
"import scipy.sparse as sp\n",
"from sklearn.metrics import f1_score\n",
"import matplotlib.pyplot as plt\n",
"from sklearn.metrics import f1_score, confusion_matrix, ConfusionMatrixDisplay\n",
"\n",
"\n",
"from scSLAT.model import spatial_match\n",
"from scSLAT.metrics import global_score, euclidean_dis, rotation_angle\n",
Expand Down Expand Up @@ -108,6 +110,16 @@
" spot_size = 5"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"out_dir = Path(os.path.dirname(metric_file))\n",
"sc.settings.figdir = out_dir"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -190,7 +202,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ground truth (perturb)"
"## Confusion Matrix"
]
},
{
Expand All @@ -199,18 +211,55 @@
"metadata": {},
"outputs": [],
"source": [
"if 'perturb' in matching_file:\n",
" match_ratio = (matching[0] == matching[1]).sum() / len(matching[0])\n",
"else:\n",
" match_ratio = -1"
"celltype_label = adata2.obs[biology_meta].unique().tolist()\n",
"region_label = adata2.obs[topology_meta].unique().tolist()\n",
"celltype_region_label = adata2.obs['celltype_region'].unique().tolist()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(len(celltype_region_label) / 2, len(celltype_region_label) /2))\n",
"cm = confusion_matrix(adata2.obs['celltype_region'], adata2.obs['target_celltype_region'], labels=celltype_region_label)\n",
"disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=celltype_region_label)\n",
"disp.plot(cmap='Reds', xticks_rotation='vertical', ax=plt.gca())\n",
"plt.savefig(out_dir / 'joint_confusing_matrix.png', dpi=300, bbox_inches='tight')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(len(celltype_label) / 2, len(celltype_label) /2))\n",
"cm = confusion_matrix(adata2.obs[biology_meta], adata2.obs['target_celltype'], labels=celltype_label)\n",
"disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=celltype_label)\n",
"disp.plot(cmap='Reds', xticks_rotation='vertical', ax=plt.gca())\n",
"plt.savefig(out_dir / 'celltype_confusing_matrix.png', dpi=300, bbox_inches='tight')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(len(region_label) / 2, len(region_label) /2))\n",
"cm = confusion_matrix(adata2.obs[topology_meta], adata2.obs['target_region'], labels=region_label)\n",
"disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=region_label)\n",
"disp.plot(cmap='Reds', xticks_rotation='vertical', ax=plt.gca())\n",
"plt.savefig(out_dir / 'region_confusing_matrix.png', dpi=300, bbox_inches='tight')"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Save"
"## Ground truth (perturb)"
]
},
{
Expand All @@ -219,8 +268,18 @@
"metadata": {},
"outputs": [],
"source": [
"out_dir = Path(os.path.dirname(metric_file))\n",
"sc.settings.figdir = out_dir"
"if 'perturb' in matching_file:\n",
" match_ratio = (matching[0] == matching[1]).sum() / len(matching[0])\n",
"else:\n",
" match_ratio = -1"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Save"
]
},
{
Expand Down
6 changes: 1 addition & 5 deletions benchmark/workflow/notebooks/run_SLAT_dpca.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,21 @@
" biology_meta = 'cell_type'\n",
" topology_meta = 'layer_guess'\n",
" alpha = 10\n",
" LGCN_layer = 2\n",
" spot_size = 5\n",
"elif 'merfish' and 'hypothalamic' in adata1_file:\n",
" biology_meta = 'Cell_class'\n",
" topology_meta = 'region'\n",
" alpha = 25\n",
" LGCN_layer = 2\n",
" spot_size = 15\n",
"elif 'stereo' and 'embryo' in adata1_file:\n",
" biology_meta = 'annotation'\n",
" topology_meta = 'region'\n",
" alpha = 3\n",
" LGCN_layer = 1\n",
" spot_size = 5\n",
"elif 'brain' in adata1_file:\n",
" biology_meta = 'layer_guess'\n",
" topology_meta = 'layer_guess'\n",
" alpha = 10\n",
" LGCN_layer = 2\n",
" spot_size = 5"
]
},
Expand Down Expand Up @@ -154,7 +150,7 @@
"Cal_Spatial_Net(adata1, k_cutoff=20, model='KNN')\n",
"Cal_Spatial_Net(adata2, k_cutoff=20, model='KNN')\n",
"edges, features = load_anndatas([adata1, adata2], feature='dpca', singular=True, dim=30)\n",
"embd0, embd1, time1 = run_SLAT(features, edges, 6, LGCN_layer=LGCN_layer)\n",
"embd0, embd1, time1 = run_SLAT(features, edges, 6, LGCN_layer=3)\n",
"run_time = str(time.time() - start)\n",
"print('Runtime: ' + run_time)"
]
Expand Down
6 changes: 1 addition & 5 deletions benchmark/workflow/notebooks/run_SLAT_dpca_one2many.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,21 @@
" biology_meta = 'cell_type'\n",
" topology_meta = 'layer_guess'\n",
" alpha = 10\n",
" LGCN_layer = 2\n",
" spot_size = 5\n",
"elif 'merfish' and 'hypothalamic' in adata1_file:\n",
" biology_meta = 'Cell_class'\n",
" topology_meta = 'region'\n",
" alpha = 25\n",
" LGCN_layer = 2\n",
" spot_size = 15\n",
"elif 'stereo' and 'embryo' in adata1_file:\n",
" biology_meta = 'annotation'\n",
" topology_meta = 'region'\n",
" alpha = 3\n",
" LGCN_layer = 1\n",
" spot_size = 5\n",
"elif 'brain' in adata1_file:\n",
" biology_meta = 'layer_guess'\n",
" topology_meta = 'layer_guess'\n",
" alpha = 10\n",
" LGCN_layer = 2\n",
" spot_size = 5"
]
},
Expand Down Expand Up @@ -152,7 +148,7 @@
"Cal_Spatial_Net(adata1, k_cutoff=20, model='KNN')\n",
"Cal_Spatial_Net(adata2, k_cutoff=20, model='KNN')\n",
"edges, features = load_anndatas([adata1, adata2], feature='dpca', singular=True, dim=30)\n",
"embd0, embd1, time1 = run_SLAT(features, edges, 6, LGCN_layer=LGCN_layer)\n",
"embd0, embd1, time1 = run_SLAT(features, edges, 6, LGCN_layer=3)\n",
"run_time = str(time.time() - start)\n",
"print('Runtime: ' + run_time)"
]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ classifiers = [
[tool.poetry.dependencies]
python = "^3.8"
numpy = ">1.19"
scipy = ">1.3"
scipy = ">1.3, <1.9"
pandas = ">1.1, <2.0"
matplotlib = ">3.1.2, <3.7"
seaborn = ">0.9"
Expand Down
4 changes: 2 additions & 2 deletions scSLAT/viz/multi_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,9 @@ class match_3D_celltype(match_3D_multi):
highlight_cell
color to highlight the cell
meta
dataframe colname of meta, such as celltype
dataframe col name of meta, such as celltype
expr
dataframe colname of gene expr
dataframe col name of gene expr
subsample_size
subsample size of matches
reliability
Expand Down

0 comments on commit 5d3c59b

Please sign in to comment.