Skip to content

Commit 95bf10d

Browse files
committed
cluster_alot etc
1 parent 90b827e commit 95bf10d

19 files changed

+1808
-257
lines changed

docs/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ All notable changes to PySingleCellNet should be listed here. The definition of
44

55
## [Unreleased]
66

7+
## [0.1.3] - 2025-09-15
8+
79
### Changed
810

911
- replace cl with tl
@@ -15,16 +17,18 @@ All notable changes to PySingleCellNet should be listed here. The definition of
1517
- tl.discover_cell_cliques labels cells by consensus cluster labels, kind of
1618
- tl.clustering_quality_vs_nn_summary computes metrics of clustering quality
1719
- tl.cluster_alot
18-
- resurrected gene clustering functions
20+
- tl.cluster_subcluster
21+
- resurrected gene clustering functions
22+
- notebook tutorial on cell clustering
1923

2024
### Fixed
2125

2226
- `filter_anndata_slots` to handle .uns and dependencies across slots
27+
- `classify_anndata` bug that prevented writing h5ad. see https://github.com/CahanLab/PySingleCellNet/issues/13
2328

2429
### Removed
2530

2631
- ut.mito_rib_heme
27-
-
2832
- lots of stuff that is old or has been moved to other packages like STUF
2933

3034
## [0.1.2] - 2025-08-05

docs/classifier.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/install.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
The easiest way to install PySingleCellNet is available on PyPI. Install it from there with:
1+
PySingleCellNet is available on PyPI. You can install it with:
22

33
```
44
pip install pySingleCellNet
55
```
66

7-
Alternatively, you can install directly from GitHub with:
7+
You could also install it directly from GitHub with:
88

99
```shell
1010
pip install git+https://github.com/CahanLab/pySingleCellNet.git

docs/notebooks/categorize.ipynb

Lines changed: 52 additions & 41 deletions
Large diffs are not rendered by default.

docs/notebooks/cluster_alot.ipynb

Lines changed: 542 additions & 0 deletions
Large diffs are not rendered by default.

docs/notebooks/quickstart.ipynb

Lines changed: 53 additions & 30 deletions
Large diffs are not rendered by default.

docs/tools.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# analysis tools including classification
2+
3+
Functions that create or require the classifier `clf` object, and friends
4+
5+
::: pySingleCellNet.tools
6+
7+

mkdocs.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ nav:
6363
- Tutorials:
6464
- 'Quickstart': notebooks/quickstart.ipynb
6565
- 'Explore': notebooks/categorize.ipynb
66+
- 'Clustering cells': notebooks/cluster_alot.ipynb
67+
# - 'Clustering genes': notebooks/gene_modules.ipynb
6668
# - 'train & classify': 'notebooks/Basics.ipynb'
6769
# - 'analyze _in vitro_ cells': 'notebooks/explore.ipynb'
6870
# - 'prepare training data': 'notebooks/how-to_prepare_reference_data.ipynb'
@@ -71,9 +73,9 @@ nav:
7173
- Training data: training_data.md
7274
- References: refs.md
7375
- API:
74-
- 'Utilities': 'utils.md'
75-
- 'Classifier': 'classifier.md'
76-
- 'Plotting': 'plotting.md'
76+
- 'Utilities': utils.md
77+
- 'Tools': tools.md
78+
- 'Plotting': plotting.md
7779
- Release Notes: CHANGELOG.md
7880

7981

src/pySingleCellNet/plotting/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
from .dot import (
2222
umi_counts_ranked,
2323
ontogeny_graph,
24-
dotplot_deg,
25-
dotplot_diff_gene,
2624
dotplot_scn_scores,
2725
umap_scores,
2826
)
2927

3028
from .heatmap import (
29+
heatmap_clustering_eval,
3130
heatmap_classifier_report,
3231
heatmap_scores,
3332
heatmap_gsea,
@@ -53,10 +52,9 @@
5352
"bar_classifier_f1",
5453
"umi_counts_ranked",
5554
"ontogeny_graph",
56-
"dotplot_deg",
57-
"dotplot_diff_gene",
5855
"dotplot_scn_scores",
5956
"umap_scores",
57+
"heatmap_clustering_eval",
6058
"heatmap_classifier_report",
6159
"heatmap_scores",
6260
"heatmap_gsea",

src/pySingleCellNet/plotting/dot.py

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,13 @@
88
import umap
99
import anndata as ad
1010
import igraph as ig
11-
# from palettable.colorbrewer.qualitative import Set2_6
12-
# from palettable.tableau import GreenOrange_6
13-
# from palettable.cartocolors.qualitative import Safe_6
14-
# from palettable.cartocolors.qualitative import Vivid_4
15-
# from palettable.cartocolors.qualitative import Vivid_6
16-
# from palettable.cartocolors.qualitative import Vivid_10
17-
# from palettable.scientific.diverging import Roma_20
18-
from palettable.scientific.sequential import LaJolla_20
19-
from palettable.scientific.sequential import Batlow_20
11+
from palettable.scientific.sequential import LaJolla_20, Batlow_20
2012
from anndata import AnnData
2113
from scipy.sparse import csr_matrix
2214
from scipy import sparse
2315
from typing import Optional, Callable
2416
from ..utils import *
2517

26-
27-
2818
def umi_counts_ranked(adata, total_counts_column="total_counts"):
2919
"""
3020
Identifies and plors the knee point of the UMI count distribution in an AnnData object.
@@ -117,55 +107,7 @@ def ontogeny_graph(gra, color_dict):
117107
ig.plot(gra, **v_style, vertex_size=node_sizes)
118108
plt.show()
119109

120-
def dotplot_deg(
121-
adata: AnnData,
122-
diff_gene_dict: dict,
123-
#samples_obsvals: list = [],
124-
groupby_obsname: str = "comb_sampname", # I think that this is the column that splits cells for DEG
125-
cellgrp_obsname: str = "comb_cellgrp", # I think that this is the column that splits into discint clusters or cell types
126-
cellgrp_obsvals: list = [], # this is the subset of clusters or cell types to limit this visualization to
127-
num_genes: int = 10,
128-
order_by = 'scores',
129-
new_obsname = 'grp_by_samp',
130-
use_raw=False
131-
):
132110

133-
# remove celltypes unspecified in diff_gene_dict
134-
dd_dict = diff_gene_dict['geneTab_dict']
135-
tokeep = list(dd_dict.keys())
136-
137-
# also remove cell_types not listed in celltype_names
138-
# default for celltype_names is all celltypes included in dd_dict
139-
if len(cellgrp_obsvals) > 0:
140-
cellgrp_obsvals = list(set(cellgrp_obsvals).intersection(set(tokeep)))
141-
else:
142-
cellgrp_obsvals = tokeep
143-
144-
adNew = adata.copy()
145-
adNew = adNew[adNew.obs[cellgrp_obsname].isin(cellgrp_obsvals)].copy()
146-
147-
# remove categories unspecified in diff_gene_dict
148-
dictkey = list(diff_gene_dict.keys())[0]
149-
sample_names = diff_gene_dict[dictkey]
150-
adNew = adNew[adNew.obs[groupby_obsname].isin(sample_names)].copy()
151-
152-
# add column 'grp_by_samp' to obs that indicates cellgrp by sample
153-
adNew.obs[new_obsname] = adNew.obs[cellgrp_obsname].astype(str) + "_X_" + adNew.obs[groupby_obsname].astype(str)
154-
155-
# define dict of marker genes based on threshold
156-
genes_to_plot = dict()
157-
for cellgrp in cellgrp_obsvals:
158-
print(f"{cellgrp}")
159-
for sname in sample_names:
160-
print(f"{sname}")
161-
genes_to_plot[cellgrp + "_X_" + sname] = pull_out_genes_v2(diff_gene_dict, cell_type = cellgrp, category = sname, num_genes = num_genes, order_by=order_by)
162-
163-
# return adNew, genes_to_plot
164-
plt.rcParams['figure.constrained_layout.use'] = True
165-
#xplot = sc.pl.DotPlot(adNew, genes_to_plot, 'ct_by_cat', cmap='RdPu', var_group_rotation = 0) #, dendrogram=True,ax=ax2, show=False)
166-
xplot = sc.pl.DotPlot(adNew, genes_to_plot, new_obsname, cmap=LaJolla_20.mpl_colormap, var_group_rotation = 0, use_raw=False) #, dendrogram=True,ax=ax2, show=False)
167-
xplot.swap_axes(True) # see sc.pl.DotPlot docs for useful info
168-
return xplot
169111

170112

171113
def dotplot_diff_gene(
@@ -229,15 +171,6 @@ def dotplot_scn_scores(
229171
adTemp.obs[groupby] = adata.obs[groupby]
230172
sc.pl.dotplot(adTemp, adTemp.var_names.values, groupby=groupby, expression_cutoff=expression_cutoff, cmap=Batlow_20.mpl_colormap, colorbar_title="SCN score")
231173

232-
def umap_scores_old(
233-
adata: AnnData,
234-
scn_classes: list,
235-
obsm_name = 'SCN_score'
236-
):
237-
adTemp = AnnData(adata.obsm[obsm_name], obs=adata.obs)
238-
adTemp.obsm['X_umap'] = adata.obsm['X_umap'].copy()
239-
sc.pl.umap(adTemp,color=scn_classes, alpha=.75, s=10, vmin=0, vmax=1)
240-
241174

242175
def umap_scores(
243176
adata: AnnData,

0 commit comments

Comments
 (0)