Skip to content

Commit 8b55bca

Browse files
tony-kuoKuo
andauthored
refactor model wrapper classes (#1)
* refactor model wrapper classes * documentation updates --------- Co-authored-by: Kuo <[email protected]>
1 parent 4bed4f1 commit 8b55bca

19 files changed

+1989
-597
lines changed
22.9 KB
Loading

docs/api.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ API Reference
2222
:hidden:
2323

2424
modules/models/scimilarity
25+
modules/models/scfoundation
26+
modules/models/scvi
27+
modules/models/ssl
2528

2629
.. toctree::
2730
:maxdepth: 2
@@ -44,6 +47,9 @@ Models
4447
These modules provide functionality for wrapping models to generate attributions.
4548

4649
* :mod:`SIGnature.models.scimilarity`
50+
* :mod:`SIGnature.models.scfoundation`
51+
* :mod:`SIGnature.models.scvi`
52+
* :mod:`SIGnature.models.ssl`
4753

4854
Utilities
4955
--------------------------------------------------------------------------------

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
nbsphinx_thumbnails = {
5858
'notebooks/1-QueryingAttributions': '_static/query_thumbnail.png',
5959
'notebooks/2-GeneratingAttributions': '_static/generate_thumbnail.png',
60+
'notebooks/3-IntegratingAttributions': '_static/integrate_thumbnail.png',
6061
}
6162

6263
# Add any paths that contain templates here, relative to this directory.

docs/install.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,17 @@ https://zenodo.org/communities/signature/
2525
Downloading models
2626
--------------------------------------------------------------------------------
2727

28-
Download the SCimilarity model from Zenodo:
29-
https://zenodo.org/records/15729925
28+
To generate attribution scores on new data, helper files can be downloaded from Zenodo:
29+
https://zenodo.org/records/17903196
30+
31+
SIGnature currently supports calculating attributions using the following models:
32+
33+
34+
1. `SCimilarity <https://doi.org/10.1038/s41586-024-08411-y>`_: pretrained weights included in helper files, but can also be downloaded here: https://zenodo.org/records/15729925
35+
2. `scFoundation <https://doi.org/10.1038/s41592-024-02305-7>`_: pretrained weights can be downloaded here: https://huggingface.co/genbio-ai/scFoundation/tree/main
36+
3. `scVI <https://doi.org/10.1038/s41592-018-0229-2>`_: pretrained weights for scVI models trained on CZI Census data can be downloaded here: https://cellxgene.cziscience.com/census-models
37+
4. `SSL-scTab <https://doi.org/10.1038/s42256-024-00934-3>`_: pretrained weights for self-supervised learning models trained on scTab data can be downloaded here: https://huggingface.co/TillR/sc_pretrained/tree/main
38+
3039

3140
Conda environment setup
3241
--------------------------------------------------------------------------------
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SIGnature.models.scfoundation
2+
--------------------------------------------------------------------------------
3+
4+
.. automodule:: SIGnature.models.scfoundation
5+
:members:
6+
:show-inheritance:

docs/modules/models/scvi.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SIGnature.models.scvi
2+
--------------------------------------------------------------------------------
3+
4+
.. automodule:: SIGnature.models.scvi
5+
:members:
6+
:show-inheritance:

docs/modules/models/ssl.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SIGnature.models.ssl
2+
--------------------------------------------------------------------------------
3+
4+
.. automodule:: SIGnature.models.ssl
5+
:members:
6+
:show-inheritance:

docs/notebooks/1-QueryingAttributions.ipynb

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
"\n",
1414
"Before running this tutorial, you need to:\n",
1515
"\n",
16-
"1. Download the SCimilarity model from https://zenodo.org/records/15729925\n",
17-
"2. Download the cell type-level attributions you are interested in from https://zenodo.org/communities/signature/. For this tutorial, you will need two attribution folders from Zenodo (https://zenodo.org/records/15794176):\n",
16+
"1. Download the model_files folder from [here](https://zenodo.org/records/17903196)\n",
17+
"2. Download the cell type-level attributions you are interested in from [here](https://zenodo.org/communities/signature/). For this tutorial, you will need two attribution folders from [here](https://zenodo.org/records/17905668):\n",
1818
"\n",
19-
" 1. `celltype_attributions_lung`: contains data for the first part of the tutorial showing a simple querying example. This folder can be extracted with the command `tar -xzf celltype_attributions_lung.tar.gz`\n",
20-
" 2. `celltype_attributions`: contains data from myeloid cells to replicate the MS1 signature analysis from the paper. This folder can be extracted with the command `tar -xzf celltype_attributions.tar.gz`"
19+
" 1. **celltype_attributions_lung**: contains data for the first part of the tutorial showing a simple querying example. This folder can be extracted with the command \"tar -xzf celltype_attributions_lung.tar.gz\"\n",
20+
" 2. **celltype_attributions**: contains data from myeloid cells to replicate the MS1 signature analysis from the paper. This folder can be extracted with the command \"tar -xzf celltype_attributions.tar.gz\""
2121
]
2222
},
2323
{
@@ -33,9 +33,8 @@
3333
"from os.path import join\n",
3434
"import pandas as pd\n",
3535
"import seaborn as sns\n",
36-
"from SIGnature import SIGnature, SCimilarity, Meta\n",
37-
"import tiledb\n",
38-
"import time\n",
36+
"from SIGnature import SIGnature, Meta\n",
37+
"from SIGnature.models.scimilarity import SCimilarityWrapper\n",
3938
"from tqdm import tqdm\n",
4039
"import warnings\n",
4140
"\n",
@@ -67,10 +66,10 @@
6766
"metadata": {},
6867
"outputs": [],
6968
"source": [
70-
"## Path to Scimilarity Model Downloaded from Zenodo (https://zenodo.org/records/15729925)\n",
71-
"scim_model_path = \"/home/scimilarity_model\"\n",
69+
"## Path to Scimilarity Model Downloaded from Zenodo (https://zenodo.org/records/17903196)\n",
70+
"scim_model_path = \"/home/model_files/scimilarity\" # change to path where model_files was downloaded\n",
7271
"## Set use_gpu false when querying attributions\n",
73-
"scim = SCimilarity(model_path=scim_model_path, use_gpu=False)"
72+
"scim = SCimilarityWrapper(model_path=scim_model_path, use_gpu=False)"
7473
]
7574
},
7675
{
@@ -80,8 +79,7 @@
8079
"metadata": {},
8180
"outputs": [],
8281
"source": [
83-
"## Folder where the cell type attributions are stored\n",
84-
"## Downloaded from Zenodo (https://zenodo.org/records/15794176)\n",
82+
"## Folder where the cell type attributions are stored, Downloaded from Zenodo (https://zenodo.org/records/17905668)\n",
8583
"ct_base = \"/home/celltype_attributions_lung\"\n",
8684
"all_ct = os.listdir(ct_base)"
8785
]
@@ -103,7 +101,7 @@
103101
"source": [
104102
"## Check genes (AT1 associated genes from CellMarker)\n",
105103
"goi = ['CAV1', 'CAV2', 'CLIC5']\n",
106-
"sig = SIGnature(gene_order=scim.gene_order, model=scim)\n",
104+
"sig = SIGnature(gene_order=scim.gene_order)\n",
107105
"gene_list = sig.check_genes(goi)"
108106
]
109107
},
@@ -259,10 +257,10 @@
259257
"metadata": {},
260258
"outputs": [],
261259
"source": [
262-
"## Path to Scimilarity Model Downloaded from Zenodo (https://zenodo.org/records/15794176)\n",
263-
"scim_model_path = \"/home/scimilarity_model\"\n",
260+
"## Path to Scimilarity Model Downloaded from Zenodo (https://zenodo.org/records/17903196)\n",
261+
"scim_model_path = \"/home/model_files/scimilarity\"\n",
264262
"## Set use_gpu false when querying attributions\n",
265-
"scim = SCimilarity(model_path=scim_model_path, use_gpu=False)"
263+
"scim = SCimilarityWrapper(model_path=scim_model_path, use_gpu=False)"
266264
]
267265
},
268266
{
@@ -272,8 +270,7 @@
272270
"metadata": {},
273271
"outputs": [],
274272
"source": [
275-
"## This should be the folder where the attributions are stored\n",
276-
"## Path to cell type attributions downloaded from Zenodo (https://zenodo.org/records/15794176)\n",
273+
"## This should be the folder where the attributions are stored, downloaded from Zenodo (https://zenodo.org/records/17905668)\n",
277274
"ct_base = \"/home/celltype_attributions\"\n",
278275
"all_ct = os.listdir(ct_base)"
279276
]
@@ -343,7 +340,7 @@
343340
}
344341
],
345342
"source": [
346-
"sig = SIGnature(gene_order=scim.gene_order, model=scim)\n",
343+
"sig = SIGnature(gene_order=scim.gene_order)\n",
347344
"gene_list = sig.check_genes(ms1_genes)"
348345
]
349346
},
@@ -867,14 +864,6 @@
867864
" dotsize=9,\n",
868865
")"
869866
]
870-
},
871-
{
872-
"cell_type": "code",
873-
"execution_count": null,
874-
"id": "e98b6563-124d-40c5-a9be-783944f52e01",
875-
"metadata": {},
876-
"outputs": [],
877-
"source": []
878867
}
879868
],
880869
"metadata": {

0 commit comments

Comments
 (0)