plotting functions
Various plotting functions.
bar_classifier_f1
bar_classifier_f1(adata, ground_truth='celltype', class_prediction='SCN_class', bar_height=0.8)
Plots a bar graph of F1 scores per class based on ground truth and predicted classifications.
Parameters:
-
adata(AnnData) –Annotated data matrix.
-
ground_truth(str, default:'celltype') –The column name in
adata.obscontaining the true class labels. Defaults to "celltype". -
class_prediction(str, default:'SCN_class') –The column name in
adata.obscontaining the predicted class labels. Defaults to "SCN_class".
Returns:
-
–
None
Source code in src/pySingleCellNet/plotting/bar.py
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 | |
bar_compare_celltype_composition
bar_compare_celltype_composition(adata1, adata2, celltype_col, min_delta, colors=None, metric='log_ratio')
Compare cell type proportions between two AnnData objects and plot either log-ratio or differences for significant changes.
Parameters:
-
adata1(AnnData) –First AnnData object.
-
adata2(AnnData) –Second AnnData object.
-
celltype_col(str) –Column name in
.obsindicating cell types. -
min_delta(float) –Minimum absolute difference in percentages to include in the plot.
-
colors(dict, default:None) –Dictionary with cell types as keys and colors as values for the bars.
-
metric(str, default:'log_ratio') –"log_ratio" or "difference" to specify which metric to plot. Defaults to "log_ratio".
Returns:
-
None–Displays the bar plot.
Source code in src/pySingleCellNet/plotting/bar.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
dotplot_scn_scores
dotplot_scn_scores(adata, groupby, expression_cutoff=0.1, obsm_name='SCN_score')
Create a dot plot of SCN classification scores grouped by a specified column.
Constructs a temporary AnnData from the SCN score matrix and renders a scanpy dot plot colored by score intensity.
Parameters:
-
adata(AnnData) –An AnnData object with SCN scores stored in
.obsm. -
groupby(str) –Column name in
.obsto group cells by. -
expression_cutoff(float, default:0.1) –Minimum score threshold for dot display. Defaults to 0.1.
-
obsm_name(str, default:'SCN_score') –Key in
.obsmcontaining the SCN score matrix. Defaults to 'SCN_score'.
Returns:
-
None–Displays the dot plot.
Source code in src/pySingleCellNet/plotting/dot.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
heatmap_classifier_report
heatmap_classifier_report(df, width=2.5, height=7)
Plot a heatmap of classifier precision, recall, and F1-score with support bar chart.
Renders a Marsilea heatmap from a classification report DataFrame, separating per-class rows from aggregate average rows, and displaying a support count bar chart on the right.
Parameters:
-
df(DataFrame) –Classification report DataFrame with columns 'Label', 'Precision', 'Recall', 'F1-Score', and 'Support'.
-
width(float, default:2.5) –Width of the heatmap in inches. Defaults to 2.5.
-
height(float, default:7) –Height of the heatmap in inches. Defaults to 7.
Returns:
-
None–Renders the heatmap inline.
Source code in src/pySingleCellNet/plotting/heatmap.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
heatmap_clustering_eval
heatmap_clustering_eval(df, index_col='label_col', metrics=('n_clusters', 'unique_strict_genes', 'unique_naive_genes', 'frac_pairs_with_at_least_n_strict'), bar_sum_cols=('unique_strict_genes', 'unique_naive_genes'), cmap_eval='viridis', scale_eval='zscore', linewidth=0.5, value_fmt=None, title='Clustering parameter sweep (select best rows)', render=True, set_default_font=True)
Plot a Marsilea heatmap to guide clustering parameter selection.
Displays parsed parameters (pc, k, res) on the left, an evaluation heatmap with raw numbers in cells at center, and a bar chart of combined unique gene counts on the right. Rows are sorted by descending selection score.
Parameters:
-
df(DataFrame) –DataFrame containing clustering evaluation metrics.
-
index_col(str, default:'label_col') –Column name used as row identifier. Defaults to "label_col".
-
metrics(tuple, default:('n_clusters', 'unique_strict_genes', 'unique_naive_genes', 'frac_pairs_with_at_least_n_strict')) –Column names to display in the heatmap. Defaults to ("n_clusters", "unique_strict_genes", "unique_naive_genes", "frac_pairs_with_at_least_n_strict").
-
bar_sum_cols(tuple, default:('unique_strict_genes', 'unique_naive_genes')) –Columns to sum for the right-side bar chart. Defaults to ("unique_strict_genes", "unique_naive_genes").
-
cmap_eval(str, default:'viridis') –Colormap for the evaluation heatmap. Defaults to "viridis".
-
scale_eval(str, default:'zscore') –Scaling method for heatmap coloring: 'zscore', 'minmax', or 'none'. Defaults to "zscore".
-
linewidth(float, default:0.5) –Line width between heatmap cells. Defaults to 0.5.
-
value_fmt(dict or None, default:None) –Format strings per metric column for cell text. Defaults to None (auto-detected).
-
title(str, default:'Clustering parameter sweep (select best rows)') –Title for the heatmap. Defaults to "Clustering parameter sweep (select best rows)".
-
render(bool, default:True) –Whether to render the plot immediately. Defaults to True.
-
set_default_font(bool, default:True) –Whether to set a default font to avoid font-family warnings. Defaults to True.
Returns:
-
dict–Dictionary with keys 'canvas' (Marsilea heatmap object), 'row_order' (list), 'score' (pd.Series), and 'params' (pd.DataFrame of parsed pc/k/res values).
Source code in src/pySingleCellNet/plotting/heatmap.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
heatmap_genes
heatmap_genes(adQuery, adTrain=None, cgenes_list={}, list_of_types_toshow=[], list_of_training_to_show=[], number_of_genes_toshow=3, query_annotation_togroup='SCN_class', training_annotation_togroup='SCN_class', split_show=False, save=False)
Plot a heatmap of top classifier genes for selected cell types across query and training data.
Constructs a combined expression matrix from query (and optionally training) cells for specified cell types, selects top genes per type from a ranked gene list, and renders a scanpy heatmap grouped by cell annotation.
Parameters:
-
adQuery(AnnData) –Query AnnData object with SCN classification results.
-
adTrain(AnnData, default:None) –Training AnnData object. Required if any entry in list_of_training_to_show is True. Defaults to None.
-
cgenes_list(dict, default:{}) –Dictionary mapping cell type names to ranked gene lists. Defaults to {}.
-
list_of_types_toshow(list, default:[]) –Cell types to include in the heatmap. Defaults to [] (all SCN_class types).
-
list_of_training_to_show(list[bool], default:[]) –Boolean list indicating whether to include training cells for each corresponding cell type. Defaults to [] (all False).
-
number_of_genes_toshow(int, default:3) –Number of top genes to display per cell type. Defaults to 3.
-
query_annotation_togroup(str, default:'SCN_class') –Column in adQuery.obs to group cells by. Defaults to 'SCN_class'.
-
training_annotation_togroup(str, default:'SCN_class') –Column in adTrain.obs to group cells by. Defaults to 'SCN_class'.
-
split_show(bool, default:False) –Whether to append '_Query' or '_Train' suffix to annotations. Defaults to False.
-
save(bool, default:False) –Whether to save the heatmap figure. Defaults to False.
Returns:
-
–
The result of sc.pl.heatmap (figure or None depending on scanpy version).
Source code in src/pySingleCellNet/plotting/heatmap.py
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 | |
heatmap_gsea
heatmap_gsea(gmat, clean_signatures=False, clean_cells=False, column_colors=None, figsize=(8, 6), label_font_size=7, cbar_pos=[0.2, 0.92, 0.6, 0.02], dendro_ratio=(0.3, 0.1), cbar_title='NES', col_cluster=False, row_cluster=False)
Generates a heatmap with hierarchical clustering for gene set enrichment analysis (GSEA) results.
Parameters:
-
gmat(DataFrame) –A matrix of GSEA scores with gene sets as rows and samples as columns.
-
clean_signatures(bool, default:False) –If True, removes gene sets with zero enrichment scores across all samples. Defaults to False.
-
clean_cells(bool, default:False) –If True, removes samples with zero enrichment scores across all gene sets. Defaults to False.
-
column_colors(Series or DataFrame, default:None) –Colors to annotate columns, typically representing sample groups. Defaults to None.
-
figsize(tuple, default:(8, 6)) –Figure size in inches (width, height). Defaults to (8, 6).
-
label_font_size(int, default:7) –Font size for axis and colorbar labels. Defaults to 7.
-
cbar_pos(list, default:[0.2, 0.92, 0.6, 0.02]) –Position of the colorbar [left, bottom, width, height]. Defaults to [0.2, 0.92, 0.6, 0.02] for a horizontal top placement.
-
dendro_ratio(tuple, default:(0.3, 0.1)) –Proportion of the figure allocated to the row and column dendrograms. Defaults to (0.3, 0.1).
-
cbar_title(str, default:'NES') –Title of the colorbar. Defaults to 'NES'.
-
col_cluster(bool, default:False) –If True, performs hierarchical clustering on columns. Defaults to False.
-
row_cluster(bool, default:False) –If True, performs hierarchical clustering on rows. Defaults to False.
Returns:
-
–
None
Displays
A heatmap with optional hierarchical clustering and a horizontal colorbar at the top.
Source code in src/pySingleCellNet/plotting/heatmap.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
heatmap_scores
heatmap_scores(adata, groupby, vmin=0, vmax=1, obsm_name='SCN_score', order_by=None, figure_subplot_bottom=0.4)
Plots a heatmap of single cell scores, grouping cells according to a specified .obs column and optionally ordering within each group.
Parameters:
-
adata(AnnData) –An AnnData object containing the single cell data.
-
groupby(str) –The name of the column in .obs used for grouping cells in the heatmap.
-
vmin(float, default:0) –Minimum value for color scaling. Defaults to 0.
-
vmax(float, default:1) –Maximum value for color scaling. Defaults to 1.
-
obsm_name(str, default:'SCN_score') –The key in .obsm to retrieve the matrix for plotting. Defaults to 'SCN_score'.
-
order_by(str, default:None) –The name of the column in .obs used for ordering cells within each group. Defaults to None.
Returns:
-
None–The function plots a heatmap and does not return any value.
Source code in src/pySingleCellNet/plotting/heatmap.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
make_bivariate_cmap
make_bivariate_cmap(c00='#f0f0f0', c10='#e31a1c', c01='#1f78b4', c11='#ffff00', n=128)
Create a bivariate colormap by bilinear‐interpolating four corner colors.
This builds an (n × n) grid of RGB colors, blending smoothly between the specified corner colors: - c00 at (low, low) - c10 at (high, low) - c01 at (low, high) - c11 at (high, high)
Parameters:
-
c00(str, default:'#f0f0f0') –Matplotlib color spec (hex, name, or RGB tuple) for the low/low corner.
-
c10(str, default:'#e31a1c') –Color for the high/low corner.
-
c01(str, default:'#1f78b4') –Color for the low/high corner.
-
c11(str, default:'#ffff00') –Color for the high/high corner.
-
n(int, default:128) –Resolution per axis. The total length of the returned colormap is n*n.
Returns:
-
ListedColormap(ListedColormap) –A colormap with n*n entries blending between the four corners.
Source code in src/pySingleCellNet/plotting/helpers.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
ontogeny_graph
ontogeny_graph(gra, color_dict)
Plot an ontogeny relationship graph with colored vertices.
Renders an igraph graph using the Fruchterman-Reingold layout with vertex colors from the provided color dictionary and vertex sizes scaled by cell count.
Parameters:
-
gra(Graph) –An igraph Graph object with vertex attributes 'name' and 'ncells'.
-
color_dict(dict) –Dictionary mapping vertex names to RGB color tuples.
Returns:
-
None–Displays the graph plot.
Source code in src/pySingleCellNet/plotting/dot.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
plot_spatial_two_genes_stack
plot_spatial_two_genes_stack(adatas, gene1, gene2, cmap, width_ratios=(3, 1), **kwargs)
Plot stacked bivariate spatial gene expression panels for multiple AnnData objects.
Creates a vertically stacked grid of bivariate spatial plots, one row per AnnData object, each showing the co-expression of two genes using the provided bivariate colormap.
Parameters:
-
adatas(list[AnnData]) –List of AnnData objects, each with spatial coordinates.
-
gene1(str) –First gene name to plot.
-
gene2(str) –Second gene name to plot.
-
cmap(ListedColormap) –Bivariate colormap (n x n LUT) from
make_bivariate_cmap. -
width_ratios(tuple[float, float], default:(3, 1)) –Relative widths of (scatter, colorbar) panels. Defaults to (3, 1).
-
**kwargs–Additional keyword arguments passed to
spatial_two_genes.
Returns:
-
–
matplotlib.figure.Figure: The generated figure object.
Source code in src/pySingleCellNet/plotting/spatial.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
scatter_genes_oneper
scatter_genes_oneper(adata, genes, embedding_key='X_spatial', spot_size=2, alpha=0.9, clip_percentiles=(0, 99.5), log_transform=True, cmap='Reds', figsize=None, panel_width=4.0, n_rows=1)
Plot expression of multiple genes on a 2D embedding arranged in a grid.
Each gene is optionally log-transformed, percentile-clipped, and rescaled to [0,1].
Cells are plotted on the embedding, colored by expression, with highest values
drawn on top. A single colorbar is placed to the right of the grid.
If figsize is None, each panel has width panel_width and height
proportional to the embedding's aspect ratio; total figure dims reflect
n_rows and computed columns.
Parameters:
-
adata(AnnData) –AnnData containing the embedding in
adata.obsm[embedding_key]. -
embedding_key(str, default:'X_spatial') –Key in
.obsmfor an (n_obs, 2) coordinate array. -
genes(Sequence[str]) –List of gene names to plot (must be in
adata.var_names). -
spot_size(float, default:2) –Marker size for scatter plots. Default 2.
-
alpha(float, default:0.9) –Transparency for markers. Default 0.9.
-
clip_percentiles(tuple, default:(0, 99.5)) –(low_pct, high_pct) to clip expression before rescaling.
-
log_transform(bool, default:True) –If True, apply
np.log1pto raw expression. -
cmap(Union[str, Colormap], default:'Reds') –Colormap or name for all plots.
-
figsize(Optional[tuple], default:None) –(width, height) of entire figure. If None, computed from
panel_width,n_rows, and embedding aspect ratio. -
panel_width(float, default:4.0) –Width (in inches) of each panel when
figsizeis None. -
n_rows(int, default:1) –Number of rows in the grid. Default 1.
Returns:
-
None(None) –Displays the figure.
Raises:
-
ValueError–If embedding is missing/malformed or genes not found.
Source code in src/pySingleCellNet/plotting/spatial.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
scatter_qc_adata
scatter_qc_adata(adata, title_suffix='')
Creates a figure with two scatter plot panels for visualizing data from an AnnData object.
The first panel shows 'total_counts' vs 'n_genes_by_counts', colored by 'pct_counts_mt'. The second panel shows 'n_genes_by_counts' vs 'pct_counts_mt'. An optional title suffix can be added to customize the axis titles.
Parameters:
-
adata(AnnData) –The AnnData object containing the dataset. Must contain 'total_counts', 'n_genes_by_counts', and 'pct_counts_mt' in
adata.obs. -
title_suffix(str, default:'') –A string to append to the axis titles, useful for specifying experimental conditions (e.g., "C11 day 2"). Defaults to an empty string.
Returns:
-
None–The function displays a matplotlib figure with two scatter plots.
Example
plot_scatter_with_contours(adata, title_suffix="C11 day 2")
Source code in src/pySingleCellNet/plotting/scatter.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
spatial_contours
spatial_contours(adata, genes, spatial_key='spatial', summary_func=np.mean, spot_size=30, alpha=0.8, log_transform=True, clip_percentiles=(1, 99), cmap='viridis', contour_kwargs=None, scatter_kwargs=None)
Scatter spatial expression of one or more genes with smooth contour overlay.
If multiple genes are provided, each is preprocessed (log1p → clip
→ normalize), then combined per cell via summary_func (e.g. mean, sum,
max) on the normalized values. A smooth contour of the summarized signal
is overlaid onto the spatial scatter.
Parameters:
-
adata(AnnData) –AnnData with spatial coordinates in
adata.obsm[spatial_key]. -
genes(Union[str, Sequence[str]]) –Single gene name or list of gene names to plot (must be in
adata.var_names). -
spatial_key(str, default:'spatial') –Key in
.obsmfor an (n_obs, 2) coords array. -
summary_func(Callable[[ndarray], ndarray], default:mean) –Function to combine multiple normalized gene arrays (takes an (n_obs, n_genes) array, returns length-n_obs array). Defaults to
np.mean. -
spot_size(float, default:30) –Scatter marker size.
-
alpha(float, default:0.8) –Scatter alpha transparency.
-
log_transform(bool, default:True) –If True, apply
np.log1pto raw expression before clipping. -
clip_percentiles(tuple, default:(1, 99)) –Tuple
(low_pct, high_pct)percentiles to clip each gene. -
cmap(str, default:'viridis') –Colormap name for the scatter (e.g. 'viridis').
-
contour_kwargs(dict, default:None) –Dict of parameters for smoothing & contouring: - levels: int or list of levels (default 6) - grid_res: int grid resolution (default 200) - smooth_sigma: float Gaussian blur sigma (default 2) - contour_kwargs: dict of line style kwargs (default {'colors':'k','linewidths':1})
-
scatter_kwargs(dict, default:None) –Extra kwargs passed to
ax.scatter.
Returns:
-
None(None) –Displays the figure.
Raises:
-
ValueError–If any gene is missing or spatial coords are malformed.
Source code in src/pySingleCellNet/plotting/spatial.py
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | |
spatial_two_genes
spatial_two_genes(adata, gene1, gene2, cmap, spot_size=2, alpha=0.9, spatial_key='X_spatial', log_transform=False, clip_percentiles=(0, 99.5), priority_metric='sum', show_xcoords=False, show_ycoords=False, show_bbox=False, show_legend=True, width_ratios=(10, 1))
Plot two‐gene spatial expression with a bivariate colormap.
Parameters:
-
adata(AnnData) –AnnData with spatial coords in
adata.obsm[spatial_key]. -
gene1(str) –First gene name (must be in
adata.var_names). -
gene2(str) –Second gene name.
-
cmap(ListedColormap) –Bivariate colormap from
make_bivariate_cmap(n×n LUT). -
spot_size(float, default:2) –Scatter point size.
-
alpha(float, default:0.9) –Point alpha transparency.
-
spatial_key(str, default:'X_spatial') –Key in
adata.obsmfor an (n_obs, 2) coords array. -
log_transform(bool, default:False) –If True, apply
np.log1pto raw expression. -
clip_percentiles(tuple, default:(0, 99.5)) –Tuple
(low_pct, high_pct)to clip each gene. -
priority_metric(str, default:'sum') –Which metric to sort drawing order by: - 'sum': u + v (default) - 'gene1': u only - 'gene2': v only
-
show_xcoords(bool, default:False) –Whether to display x-axis ticks and labels.
-
show_ycoords(bool, default:False) –Whether to display y-axis ticks and labels.
-
show_bbox(bool, default:False) –Whether to display the bounding box (spines).
-
show_legend(bool, default:True) –Whether to display the legend/colorbar.
-
width_ratios(Tuple[float, float], default:(10, 1)) –2‐tuple giving the relative widths of (scatter_panel, legend_panel). Defaults to (3,1).
Returns:
-
None(None) –Displays the figure.
Raises:
-
ValueError–If spatial coords are missing/malformed or if
priority_metricis invalid.
Source code in src/pySingleCellNet/plotting/spatial.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | |
stackedbar_categories
stackedbar_categories(adata, scn_classes_to_display=None, bar_height=0.8, color_dict=None, class_col_name='SCN_class_argmax', category_col_name='SCN_class_type', title=None, show_pct_total=False, legend_loc='best')
Plot horizontal stacked bar chart of SCN classification categories per cell type.
Parameters:
-
adata(AnnData) –An AnnData object containing SCN classification results.
-
scn_classes_to_display(list, default:None) –Subset of SCN classes to include. Defaults to None (all classes).
-
bar_height(float, default:0.8) –Height of the horizontal bars. Defaults to 0.8.
-
color_dict(dict, default:None) –Dictionary mapping category names to colors. Defaults to None (uses SCN_CATEGORY_COLOR_DICT).
-
class_col_name(str, default:'SCN_class_argmax') –Column name in
.obsfor the cell type labels. Defaults to 'SCN_class_argmax'. -
category_col_name(str, default:'SCN_class_type') –Column name in
.obsfor the SCN category labels. Defaults to 'SCN_class_type'. -
title(str, default:None) –Title for the plot. Defaults to None ('Cell typing categorization').
-
show_pct_total(bool, default:False) –Whether to display count and percentage text inside bars. Defaults to False.
-
legend_loc(str, default:'best') –Location of the legend. Defaults to "best".
Returns:
-
–
matplotlib.figure.Figure: The generated figure object.
Source code in src/pySingleCellNet/plotting/bar.py
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | |
stackedbar_categories_list
stackedbar_categories_list(ads, titles=None, scn_classes_to_display=None, bar_height=0.8, bar_groups_obsname='SCN_class_argmax', bar_subgroups_obsname='SCN_class_type', ncell_min=None, color_dict=None, show_pct_total=False, legend_loc='outside center right')
Plot side-by-side horizontal stacked bar charts of SCN categories for multiple AnnData objects.
Parameters:
-
ads(list[AnnData]) –List of AnnData objects to plot.
-
titles(list[str], default:None) –Titles for each subplot. Defaults to None ('SCN Class Proportions' for each).
-
scn_classes_to_display(list, default:None) –Subset of SCN classes to include. Defaults to None (all classes).
-
bar_height(float, default:0.8) –Height of the horizontal bars. Defaults to 0.8.
-
bar_groups_obsname(str, default:'SCN_class_argmax') –Column name in
.obsfor the cell type groups. Defaults to 'SCN_class_argmax'. -
bar_subgroups_obsname(str, default:'SCN_class_type') –Column name in
.obsfor the SCN category subgroups. Defaults to 'SCN_class_type'. -
ncell_min(int, default:None) –Minimum number of cells required to display a class. Defaults to None.
-
color_dict(dict, default:None) –Dictionary mapping category names to colors. Defaults to None (uses SCN_CATEGORY_COLOR_DICT).
-
show_pct_total(bool, default:False) –Whether to display count and percentage text inside bars. Defaults to False.
-
legend_loc(str, default:'outside center right') –Location of the legend. Defaults to "outside center right".
Returns:
-
–
matplotlib.figure.Figure: The generated figure object.
Source code in src/pySingleCellNet/plotting/bar.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 | |
stackedbar_composition
stackedbar_composition(adata, groupby, obs_column='SCN_class', labels=None, bar_width=0.75, color_dict=None, ax=None, order_by_similarity=False, similarity_metric='correlation', include_legend=True, legend_rows=10)
Plots a stacked bar chart of cell type proportions for a single AnnData object grouped by a specified column.
Parameters:
-
adata(AnnData) –An AnnData object.
-
groupby(str) –The column in
.obsto group by. -
obs_column(str, default:'SCN_class') –The name of the
.obscolumn to use for categories. Defaults to 'SCN_class'. -
labels(List[str], default:None) –Custom labels for each group to be displayed on the x-axis. If not provided, the unique values of the groupby column will be used. The length of
labelsmust match the number of unique groups. -
bar_width(float, default:0.75) –The width of the bars in the plot. Defaults to 0.75.
-
color_dict(Dict[str, str], default:None) –A dictionary mapping categories to specific colors. If not provided, default colors will be used.
-
ax(Axes, default:None) –The axis to plot on. If not provided, a new figure and axis will be created.
-
order_by_similarity(bool, default:False) –Whether to order the bars by similarity in composition. Defaults to False.
-
similarity_metric(str, default:'correlation') –The metric to use for similarity ordering. Defaults to 'correlation'.
-
include_legend(bool, default:True) –Whether to include a legend in the plot. Defaults to True.
-
legend_rows(int, default:10) –The number of rows in the legend. Defaults to 10.
Returns:
-
–
matplotlib.axes.Axes or None: The axes object if
axwas provided, otherwise None (displays the plot).
Raises:
-
ValueError–If the length of
labelsdoes not match the number of unique groups.
Examples:
>>> stackedbar_composition(adata, groupby='sample', obs_column='your_column_name')
>>> fig, ax = plt.subplots()
>>> stackedbar_composition(adata, groupby='sample', obs_column='your_column_name', ax=ax, include_legend=False, legend_rows=5)
Source code in src/pySingleCellNet/plotting/bar.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
stackedbar_composition_list
stackedbar_composition_list(adata_list, obs_column='SCN_class', labels=None, bar_width=0.75, color_dict=None, legend_loc='outside center right')
Plots a stacked bar chart of category proportions for a list of AnnData objects.
This function takes a list of AnnData objects, and for a specified column in the .obs attribute,
it plots a stacked bar chart. Each bar represents an AnnData object with segments showing the proportion
of each category within that object.
Parameters:
-
adata_list(List[AnnData]) –A list of AnnData objects.
-
obs_column(str, default:'SCN_class') –The name of the
.obscolumn to use for categories. Defaults to 'SCN_class'. -
labels(List[str], default:None) –Custom labels for each AnnData object to be displayed on the x-axis. If not provided, defaults to 'AnnData {i+1}' for each object. The length of
labelsmust match the number of AnnData objects provided. -
bar_width(float, default:0.75) –The width of the bars in the plot. Defaults to 0.75.
-
color_dict(Dict[str, str], default:None) –A dictionary mapping categories to specific colors. If not provided, default colors will be used.
Returns:
-
–
matplotlib.figure.Figure: The generated figure object.
Raises:
-
ValueError–If the length of
labelsdoes not match the number of AnnData objects.
Examples:
>>> plot_cell_type_proportions([adata1, adata2], obs_column='your_column_name', labels=['Sample 1', 'Sample 2'])
Source code in src/pySingleCellNet/plotting/bar.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | |
umap_scores
umap_scores(adata, scn_classes, obsm_name='SCN_score', alpha=0.75, s=10, display=True)
Plots UMAP projections of scRNA-seq data with specified scores.
Parameters:
-
adata(AnnData) –The AnnData object containing the scRNA-seq data.
-
scn_classes(list) –A list of SCN classes to visualize on the UMAP.
-
obsm_name(str, default:'SCN_score') –The name of the obsm key containing the SCN scores. Defaults to 'SCN_score'.
-
alpha(float, default:0.75) –The transparency level of the points on the UMAP plot. Defaults to 0.75.
-
s(int, default:10) –The size of the points on the UMAP plot. Defaults to 10.
-
display(bool, default:True) –If True, the plot is displayed immediately. If False, the axis object is returned. Defaults to True.
Returns:
-
–
matplotlib.axes.Axes or None: If
displayis False, returns the matplotlib axes object. Otherwise, returns None.
Source code in src/pySingleCellNet/plotting/dot.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
umi_counts_ranked
umi_counts_ranked(adata, total_counts_column='total_counts')
Identify and plot the knee point of the UMI count distribution in an AnnData object.
Parameters:
-
adata(AnnData) –The input AnnData object.
-
total_counts_column(str, default:'total_counts') –Column in
adata.obscontaining total UMI counts. Defaults to "total_counts".
Returns:
-
None–Displays a log-log plot with the knee point.
Source code in src/pySingleCellNet/plotting/dot.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |