Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ repos:
hooks:
- id: prettier
- repo: https://github.com/tox-dev/pyproject-fmt
rev: v2.5.0
rev: v2.6.0
hooks:
- id: pyproject-fmt
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.2
rev: v0.12.12
hooks:
- id: ruff
types_or: [python, pyi, jupyter]
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
types_or: [python, pyi, jupyter]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: detect-private-key
- id: check-ast
Expand Down
3 changes: 2 additions & 1 deletion docs/.ipynb_checkpoints/index-checkpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Tools <api/tools.md>
Plotting <api/plotting.md>

```

```{toctree}
:maxdepth: 1
:caption: Tutorials
Expand All @@ -26,4 +27,4 @@ changelog.md
contributing.md
references.md

```
```
21 changes: 7 additions & 14 deletions docs/api/.ipynb_checkpoints/plotting-checkpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

.. autosummary::
:toctree: generated/basic_plots

crosstab
histogram
pie
Expand All @@ -23,7 +23,7 @@
```{eval-rst}
.. autosummary::
:toctree: generated/quantification

gene_metric_heatmap
logfoldratio_over_noise
metric_scatter
Expand All @@ -33,18 +33,15 @@
moranI_histogram
diffusion_results
spatial_inout_expression

```



```

## Source, target and communication

```{eval-rst}
.. autosummary::
:toctree: generated/communication

celltype_communication
gene_communication
global_distribution_from_source
Expand All @@ -54,25 +51,24 @@
target_score_by_celltype
interactions_with_arrows
spatial_interactions

```

## Factor analysis

```{eval-rst}
.. autosummary::
:toctree: generated/factor_analysis

factors_in_cells
rank_factor_genes_loadings
rank_factor_genes_loadings_matrixplot
nmf_factors_exrna_cells_W
nmf_gene_contributions
paired_nmf_factors
apply_exrnaH_to_cellular_to_create_cellularW

```

```

## Colormaps & palettes

Expand All @@ -83,6 +79,3 @@
get_colormap
get_palette
```



1 change: 1 addition & 0 deletions docs/api/.ipynb_checkpoints/preprocessing-checkpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
pp.define_urna
pp.filter_urna
pp.format_adata
```
11 changes: 5 additions & 6 deletions docs/api/.ipynb_checkpoints/tools-checkpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
tl.calculate_target_cells
tl.compute_target_score
tl.define_target_by_celltype
tl.cluster_distribution_from_source
tl.cluster_distribution_from_source
tl.get_gene_interaction_strength
tl.communication_strength
tl.gene_specific_interactions
Expand All @@ -46,7 +46,7 @@
```{eval-rst}
.. autosummary::
:toctree: generated/cell_scores

tl.compute_contribution_score
```

Expand All @@ -55,7 +55,7 @@
```{eval-rst}
.. autosummary::
:toctree: generated/factors

tl.factors_to_cells
tl.latent_factor
```
Expand All @@ -68,15 +68,14 @@

tl.assess_diffusion
tl.compute_js_divergence

```

## Multimodal quantication

```{eval-rst}
.. autosummary::
:toctree: generated/multimodal

tl.image_intensities_per_transcript
```

21 changes: 7 additions & 14 deletions docs/api/plotting.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

.. autosummary::
:toctree: generated/basic_plots

crosstab
histogram
pie
Expand All @@ -23,7 +23,7 @@
```{eval-rst}
.. autosummary::
:toctree: generated/quantification

gene_metric_heatmap
logfoldratio_over_noise
metric_scatter
Expand All @@ -33,18 +33,15 @@
moranI_histogram
diffusion_results
spatial_inout_expression

```



```

## Source, target and communication

```{eval-rst}
.. autosummary::
:toctree: generated/communication

celltype_communication
gene_communication
global_distribution_from_source
Expand All @@ -54,25 +51,24 @@
target_score_by_celltype
interactions_with_arrows
spatial_interactions

```

## Factor analysis

```{eval-rst}
.. autosummary::
:toctree: generated/factor_analysis

factors_in_cells
rank_factor_genes_loadings
rank_factor_genes_loadings_matrixplot
nmf_factors_exrna_cells_W
nmf_gene_contributions
paired_nmf_factors
apply_exrnaH_to_cellular_to_create_cellularW

```

```

## Colormaps & palettes

Expand All @@ -83,6 +79,3 @@
get_colormap
get_palette
```



1 change: 1 addition & 0 deletions docs/api/preprocessing.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
pp.define_urna
pp.filter_urna
pp.format_adata
```
11 changes: 5 additions & 6 deletions docs/api/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
tl.calculate_target_cells
tl.compute_target_score
tl.define_target_by_celltype
tl.cluster_distribution_from_source
tl.cluster_distribution_from_source
tl.get_gene_interaction_strength
tl.communication_strength
tl.gene_specific_interactions
Expand All @@ -46,7 +46,7 @@
```{eval-rst}
.. autosummary::
:toctree: generated/cell_scores

tl.compute_contribution_score
```

Expand All @@ -55,7 +55,7 @@
```{eval-rst}
.. autosummary::
:toctree: generated/factors

tl.factors_to_cells
tl.latent_factor
```
Expand All @@ -68,15 +68,14 @@

tl.assess_diffusion
tl.compute_js_divergence

```

## Multimodal quantication

```{eval-rst}
.. autosummary::
:toctree: generated/multimodal

tl.image_intensities_per_transcript
```

3 changes: 2 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Tools <api/tools.md>
Plotting <api/plotting.md>

```

```{toctree}
:maxdepth: 1
:caption: Tutorials
Expand All @@ -26,4 +27,4 @@ changelog.md
contributing.md
references.md

```
```
29 changes: 5 additions & 24 deletions src/troutpy/pl/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,11 @@
from mpl_chord_diagram import chord_diagram
from spatialdata import SpatialData

def celltype_communication(
sdata,
kind="heatmap",
celltype_key="cell type",
vmax=None,
vmin=None,
cmap="BuPu",
dendrogram_ratio=0.1,
**kwargs
):

def celltype_communication(sdata, kind="heatmap", celltype_key="cell type", vmax=None, vmin=None, cmap="BuPu", dendrogram_ratio=0.1, **kwargs):
"""
Plot cell type-cell type interaction strength as a heatmap or chord diagram.
"""

interaction_strength = sdata["source_score"].uns["interaction_strength"]
source_table = sdata["source_score"]
target_table = sdata["target_score"]
Expand All @@ -30,10 +21,7 @@ def celltype_communication(

# Assign colors to cell types
try:
cols = dict(zip(
np.unique(sdata["table"].obs[celltype_key]),
sdata["table"].uns[celltype_key + "_colors"]
))
cols = dict(zip(np.unique(sdata["table"].obs[celltype_key]), sdata["table"].uns[celltype_key + "_colors"], strict=False))
colors = [cols[c] for c in source_table.var.index]
except KeyError:
colpalette = plt.get_cmap("tab20")
Expand All @@ -50,20 +38,13 @@ def celltype_communication(
col_colors=colors,
dendrogram_ratio=dendrogram_ratio,
cbar_pos=(0.02, 0.8, 0.02, 0.15), # Adjust colorbar position: (x, y, width, height)
**kwargs
**kwargs,
)
g.fig.suptitle("Interaction Strength", y=1.05)
g.ax_heatmap.grid(False) # remove grid from heatmap

elif kind == "chord":
chord_diagram(
celltype_ints,
source_table.var.index,
directed=True,
fontsize=6,
colors=colors,
**kwargs
)
chord_diagram(celltype_ints, source_table.var.index, directed=True, fontsize=6, colors=colors, **kwargs)
plt.title("Interaction Strength", fontweight="bold")
plt.grid(False)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def spatial_variability(
-------
sdata: spatialdata.SpatialData
Sdata containing Moran's I values for each gene, indexed by gene names.

"""
if coord_keys is None:
coord_keys = ["x", "y"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def store_results_in_sdata(sdata, prob_table, closest_table, extracellular_trans
sdata["table"].obs['normalized_urna_source_score'] = adata.obs['urna_source_score'] / cell_expr_sum
except KeyError:
print('Normalized urna source score could not be computed')



def compute_contribution_score(sdata):
Expand Down
Loading