Skip to content

Commit 8bd619b

Browse files
Merge pull request #13 from theislab/sergio_dev
sphinx_errors_corrected
2 parents 49932da + e6f5c12 commit 8bd619b

21 files changed

Lines changed: 482 additions & 423 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Package for the analysis of transcripts outside segmented cells in python
1010

11-
![Alt text][images/logo_fish.png]
11+
![alt text](images/logo_fish.png)
1212

1313
## Getting started
1414

docs/api.md

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@
99
.. autosummary::
1010
:toctree: generated
1111
12+
pp.create_grid_squares
13+
pp.aggregate_extracellular_transcripts
1214
pp.compute_extracellular_counts
1315
pp.define_extracellular
14-
pp.compute_crosstab
16+
pp.filter_xrna
17+
pp.process_dataframe
18+
pp.segmentation_free_sainsc
19+
pp.xenium_converter
20+
pp.cosmx_converter
1521
pp.format_adata
1622
```
1723

@@ -24,24 +30,27 @@
2430
.. autosummary::
2531
:toctree: generated
2632
27-
tl.compute_source_cells
28-
tl.distance_to_source_cell
29-
tl.compute_distant_cells_prop
30-
tl.get_proportion_expressed_per_cell_type
31-
tl.calculate_target_cells
32-
tl.define_target_by_celltype
3333
tl.colocalization_proportion
34+
tl.latent_factor
35+
tl.apply_exrna_factors_to_cells
36+
tl.image_intensities_per_transcript
37+
tl.get_gene_interaction_strength
38+
tl.compute_communication_strength
39+
tl.gene_specific_interactions
3440
tl.spatial_variability
3541
tl.create_xrna_metadata
3642
tl.quantify_overexpression
3743
tl.extracellular_enrichment
3844
tl.spatial_colocalization
39-
tl.get_number_of_communication_genes
40-
tl.get_gene_interaction_strength
41-
tl.apply_nmf_to_adata
42-
tl.nmf
43-
tl.apply_exrna_factors_to_cells
45+
tl.in_out_correlation
46+
tl.assess_diffussion
47+
tl.cluster_distribution_from_source
48+
tl.compute_js_divergence
49+
tl.compare_intra_extra_distribution
4450
tl.segmentation_free_clustering
51+
tl.get_proportion_expressed_per_cell_type
52+
tl.compute_source_score
53+
tl.compute_target_score
4554
```
4655

4756
## Plotting
@@ -53,18 +62,35 @@
5362
.. autosummary::
5463
:toctree: generated
5564
65+
pl.pie
66+
pl.crosstab
67+
pl.histogram
68+
pl.get_palette
69+
pl.get_colormap
70+
pl.celltype_communication
71+
pl.gene_communication
72+
pl.target_score_by_celltype
73+
pl.rank_factor_genes_loadings
74+
pl.rank_factor_genes_loadings_matrixplot
75+
pl.factors_in_cells
76+
pl.top_bottom_probes_of_metric
77+
pl.metric_scatter
78+
pl.logfoldratio_over_noise
79+
pl.gene_metric_heatmap
5680
pl.sorted_heatmap
5781
pl.coupled_scatter
5882
pl.heatmap
59-
pl.plot_crosstab
60-
pl.pie_of_positive
6183
pl.genes_over_noise
6284
pl.moranI_histogram
63-
pl.proportion_above_threshold
64-
pl.nmf_factors_exrna_cells_W
65-
pl.nmf_gene_contributions
66-
pl.apply_exrnaH_to_cellular_to_create_cellularW
67-
pl.paired_nmf_factors
6885
pl.spatial_interactions
6986
pl.interactions_with_arrows
87+
pl.intra_extra_density
88+
pl.spatial_inout_expression
89+
pl.diffusion_results
90+
pl.spatial_transcripts
91+
pl.global_distribution_from_source
92+
pl.distributions_by_cluster
93+
pl.gene_distribution_from_source
94+
pl.source_score_by_celltype
95+
7096
```

docs/conf.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
from datetime import datetime
1010
from importlib.metadata import metadata
1111
from pathlib import Path
12+
import os
1213

1314
HERE = Path(__file__).parent
1415
sys.path.insert(0, str(HERE / "extensions"))
15-
16+
sys.path.insert(0, os.path.abspath("../src"))
1617

1718
# -- Project information -----------------------------------------------------
1819

@@ -91,13 +92,19 @@
9192
".myst": "myst-nb",
9293
}
9394

95+
autodoc_mock_imports = [
96+
"mpl_chord_diagram",
97+
# add others here if they’re missing
98+
]
99+
94100
intersphinx_mapping = {
95101
"python": ("https://docs.python.org/3", None),
96102
"anndata": ("https://anndata.readthedocs.io/en/stable/", None),
97103
"scanpy": ("https://scanpy.readthedocs.io/en/stable/", None),
98104
"numpy": ("https://numpy.org/doc/stable/", None),
99105
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
100106
"spatialdata": ("https://spatialdata.scverse.org/en/stable/", None),
107+
"matplotlib": ("https://matplotlib.org/stable/", None),
101108
}
102109

103110
# List of patterns, relative to source directory, that match files and

docs/images/logo_fish.png

167 KB
Loading

src/troutpy/pl/basic.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -105,33 +105,33 @@ def crosstab(
105105
106106
Parameters
107107
----------
108-
sdata : sd.SpatialData
108+
sdata : spatialdata.SpatialData
109109
The input spatial data object containing the categorical variables.
110110
xvar : str
111111
The categorical variable for the x-axis.
112112
yvar : str
113113
The categorical variable for the y-axis.
114-
layer : str, optional
114+
layer : str
115115
The layer in `sdata.points` to extract data from (default is "transcripts").
116-
normalize : bool, optional
116+
normalize : bool
117117
Whether to normalize proportions (default is True).
118-
axis : int, optional
118+
axis : int
119119
Axis to normalize across (1 = row, 0 = column).
120-
kind : str, optional
120+
kind : str
121121
Plot type: 'barh', 'bar', 'heatmap', 'clustermap'.
122-
save : bool, optional
122+
save : bool
123123
Whether to save the plot (default is True).
124-
figures_path : str, optional
124+
figures_path : str
125125
Path to save the plot.
126-
stacked : bool, optional
126+
stacked : bool
127127
Whether bar plots should be stacked (default is True).
128-
figsize : tuple, optional
128+
figsize : tuple
129129
Automatically computed based on the number of categories unless manually specified.
130-
cmap : str, optional
130+
cmap : str
131131
Custom color palette.
132-
saving_format : str, optional
132+
saving_format : str
133133
File format to save the plot (e.g., 'png', 'pdf').
134-
sortby : str, optional
134+
sortby : str
135135
Column/row to sort before plotting.
136136
137137
Returns
@@ -216,29 +216,29 @@ def histogram(
216216
217217
Parameters
218218
----------
219-
sdata : sd.SpatialData
219+
sdata : spatialdata.SpatialData
220220
The input spatial data object.
221221
x : str
222222
The name of the numeric column to plot on the x-axis.
223-
hue : str, optional
223+
hue : str
224224
The column name used for color grouping (optional).
225-
layer : str, optional
225+
layer : str
226226
The layer in sdata.points to extract data from (default is "transcripts").
227-
group_key : str, optional
227+
group_key : str
228228
If provided, creates subplots by the unique values of this column.
229-
figures_path : str, optional
229+
figures_path : str
230230
Path to save the plot if `save` is True.
231-
save : bool, optional
231+
save : bool
232232
Whether to save the figure as a PDF.
233-
title : str, optional
233+
title : str
234234
Overall title for the plot.
235-
custom_plot_filename : str, optional
235+
custom_plot_filename : str
236236
Custom filename to use when saving the figure.
237-
palette : str, optional
237+
palette : str
238238
Color palette name for seaborn (default is "tab10").
239-
bins : int, optional
239+
bins : int
240240
Number of histogram bins (default is 30).
241-
kde : bool, optional
241+
kde : bool
242242
Whether to overlay a kernel density estimate (default is False).
243243
244244
Returns

src/troutpy/pl/colors.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ def get_palette(name="default", n_colors=None):
99
1010
Parameters
1111
----------
12-
- name (str): Name of the palette ("default", "coolwarm", "viridis", etc.).
13-
- n_colors (int, optional): Number of colors to return. If None, return all.
12+
name: str
13+
Name of the palette ("default", "coolwarm", "viridis", etc.).
14+
n_colors: int
15+
Number of colors to return. If None, return all.
1416
1517
Returns
1618
-------
17-
- list of hex color codes.
19+
palette: str
20+
list of hex color codes.
1821
"""
1922
palettes = {
2023
"30colors": [
@@ -109,11 +112,13 @@ def get_colormap(name="default"):
109112
110113
Parameters
111114
----------
112-
- name (str): Name of the colormap ("default", "coolwarm", "viridis", etc.).
115+
name: str
116+
Name of the colormap ("default", "coolwarm", "viridis", etc.).
113117
114118
Returns
115119
-------
116-
- matplotlib.colors.Colormap object.
120+
list
121+
matplotlib.colors.Colormap object.
117122
"""
118123
colormaps = {
119124
"30colors": mcolors.LinearSegmentedColormap.from_list("custom_cmap", get_palette("30colors")),

src/troutpy/pl/communication.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ def celltype_communication(sdata, kind="heatmap", celltype_key="cell type", vmax
1313
1414
Parameters
1515
----------
16-
sdata : SpatialData object
16+
sdata : spatialdata.SpatialData
1717
The spatial data object containing interaction scores.
18-
kind : str, optional
18+
kind : str
1919
Type of plot, either 'heatmap' or 'chord'. Default is 'heatmap'.
20-
celltype_key : str, optional
20+
celltype_key : str
2121
Key for cell type colors in `sdata['table'].uns`. Default is 'cell type'.
22-
vmax : float, optional
22+
vmax : float
2323
Max value for colormap scaling. Default is None.
24-
vmin : float, optional
24+
vmin : float
2525
Min value for colormap scaling. Default is None.
26-
cmap : str, optional
26+
cmap : str
2727
Colormap for heatmap or chord diagram. Default is 'BuPu'.
28-
**kwargs : dict
28+
kwargs : dict
2929
Additional arguments passed to the plotting functions.
3030
"""
3131
interaction_strength = sdata["source_score"].uns["interaction_strength"]
@@ -63,21 +63,21 @@ def gene_communication(
6363
6464
Parameters
6565
----------
66-
sdata : SpatialData object
66+
sdata : spatialdata.SpatialData
6767
The spatial data object containing interaction scores.
68-
kind : str, optional
68+
kind : str
6969
Type of plot, either 'heatmap' or 'chord'. Default is 'heatmap'.
70-
celltype_key : str, optional
70+
celltype_key : str
7171
Key for cell type colors in `sdata['table'].uns`. Default is 'cell type'.
72-
gene
72+
gene: str
7373
Name of the gene to be plotted
74-
vmax : float, optional
74+
vmax : float
7575
Max value for colormap scaling. Default is None.
76-
vmin : float, optional
76+
vmin : float
7777
Min value for colormap scaling. Default is None.
78-
cmap : str, optional
78+
cmap : str
7979
Colormap for heatmap or chord diagram. Default is 'BuPu'.
80-
**kwargs : dict
80+
kwargs : dict
8181
Additional arguments passed to the plotting functions.
8282
"""
8383
gene_interaction_strength = sdata["source_score"].uns["gene_interaction_strength"]
@@ -124,34 +124,34 @@ def target_score_by_celltype(
124124
title: str | None = "Target Score by Cell Type",
125125
cluster_axis: str = "both",
126126
cmap: str = "coolwarm",
127-
figsize: tuple = (10, 8),
127+
figsize: tuple = None,
128128
) -> None:
129129
"""
130130
Plots a heatmap or clustered heatmap of target scores by cell type.
131131
132132
Parameters
133133
----------
134-
sdata : sd.SpatialData
134+
sdata : spatialdata.SpatialData
135135
A SpatialData object containing `target_score` data.
136-
gene_key : str, default="feature_name"
136+
gene_key : str
137137
The key in `obs` that contains gene names.
138-
min_counts : int, default=100
138+
min_counts : int
139139
Minimum count threshold for genes to be included.
140-
min_value : float, optional
140+
min_value : float
141141
Genes presenting the highest target score below this will be filtered out in visualization
142-
max_value : float, optional
142+
max_value : float
143143
Genes presenting the highest target score above this will be filtered out in visualization
144-
title : str, optional
144+
title : str
145145
Custom title for the plot.
146-
cluster_axis : str, default="both"
146+
cluster_axis : str
147147
Determines clustering:
148148
- "none" (no clustering)
149149
- "x" (cluster columns only)
150150
- "y" (cluster rows only)
151151
- "both" (cluster rows and columns)
152-
cmap : str, default="coolwarm"
152+
cmap : str
153153
Colormap for the heatmap.
154-
figsize : tuple, default=(10, 8)
154+
figsize : tuple
155155
Size of the figure.
156156
157157
Returns
@@ -164,6 +164,8 @@ def target_score_by_celltype(
164164
target_score["gene"] = sdata["target_score"].obs[gene_key]
165165
gene_by_celltype_score = target_score.groupby("gene").mean()
166166

167+
if figsize is None:
168+
figsize = (10, 8)
167169
# Filter genes based on count threshold
168170
genes = sdata["xrna_metadata"].var.index[sdata["xrna_metadata"].var["count"] > min_counts]
169171
filtered_gene_by_celltype_score = gene_by_celltype_score.loc[gene_by_celltype_score.index.isin(genes), :]

0 commit comments

Comments
 (0)