Transcriptome visualisation utilities for PhatnaniLab
Project description
pha-plots
Transcriptome visualisation utilities for PhatnaniLab.
Installation
pip install pha-plots
Install with optional development dependencies:
pip install "pha-plots[dev]"
Usage
Cortical slices
draw_frontal_cortex and draw_motor_cortex each accept a list of per-layer
numeric values (outermost layer first), a colormap, and optional normalization
bounds. Frontal cortex uses 7 layers (I–VI and white matter); motor cortex
uses 6 (no layer IV).
import matplotlib.pyplot as plt
from pha_plots import draw_frontal_cortex, draw_motor_cortex
fig, (ax_f, ax_m) = plt.subplots(1, 2, figsize=(4, 3))
draw_frontal_cortex(
ax_f,
values=[0.1, 0.4, 0.8, 0.3, 0.6, 0.9, 0.5], # 7 layers
cmap="viridis",
vmin=0, vmax=1,
)
draw_motor_cortex(
ax_m,
values=[0.2, 0.5, 0.7, 0.4, 0.8, 0.6], # 6 layers
cmap="viridis",
vmin=0, vmax=1,
)
for ax in (ax_f, ax_m):
ax.set_aspect("equal")
ax.autoscale()
ax.axis("off")
Pass is_sig (a list of booleans, one per layer) to mark significant layers
with an annotation character:
draw_frontal_cortex(
ax, values, "viridis", vmin=0, vmax=1,
is_sig=[False, False, True, False, True, False, False],
sig_annotation_char="*",
)
Spinal cord cross-section
draw_spinal_cord accepts a dictionary mapping anatomical region IDs to
values. Any region absent from the dictionary is filled with nan_color
(default 'lightgray').
Recognized region IDs:
| ID | Anatomy |
|---|---|
Dors_Edge |
Dorsal edge |
Lat_Edge |
Lateral edge (bilateral) |
Vent_Edge |
Ventral edge |
Dors_Med_White |
Dorsal median white matter |
Med_Lat_White |
Medial–lateral white matter (bilateral) |
Vent_Lat_White |
Ventral lateral white matter (bilateral) |
Vent_Med_White |
Ventral median white matter |
Dors_Horn |
Dorsal horn (bilateral) |
Vent_Horn |
Ventral horn (bilateral) |
Med_Grey |
Medial grey matter |
Cent_Can |
Central canal |
from pha_plots import draw_spinal_cord
fig, ax = plt.subplots(figsize=(3, 3))
draw_spinal_cord(
ax,
values={
"Dors_Horn": 0.9,
"Vent_Horn": 0.7,
"Med_Grey": 0.4,
"Dors_Med_White": 0.2,
"Vent_Med_White": 0.3,
},
cmap="plasma",
vmin=0, vmax=1,
)
ax.set_aspect("equal")
ax.autoscale()
ax.axis("off")
Significance annotations use the same is_sig / sig_annotation_char
pattern, but is_sig is a dict[str, bool] keyed by region ID:
draw_spinal_cord(
ax, values, "plasma", vmin=0, vmax=1,
is_sig={"Dors_Horn": True, "Vent_Horn": False},
)
Colorbar
draw_colorbar creates a colorbar inset directly inside an existing axis at a
bounding box given in data coordinates (x0, y0, width, height), so it moves
and scales with the plot.
from pha_plots.utils import draw_colorbar
cbar, cax = draw_colorbar(
ax,
xycoords=(x_max + 0.02, y_min, 0.04, y_max - y_min),
cmap="viridis",
vmin=0, vmax=1,
orientation="vertical",
label="Expression (normalised)",
)
cbar is the matplotlib.colorbar.Colorbar instance; cax is the inset
Axes on which it was drawn. Both are returned so tick positions, labels, and
other properties can be adjusted after the call:
cbar.set_ticks([0, 0.5, 1])
cax.yaxis.set_tick_params(labelsize=6)
Combining all four
import matplotlib.pyplot as plt
from pha_plots import draw_frontal_cortex, draw_motor_cortex, draw_spinal_cord
from pha_plots.utils import draw_colorbar
CMAP, VMIN, VMAX = "viridis", 0.0, 1.0
fig, axes = plt.subplots(1, 3, figsize=(8, 3))
draw_frontal_cortex(
axes[0],
values=[0.1, 0.4, 0.8, 0.3, 0.6, 0.9, 0.5],
cmap=CMAP, vmin=VMIN, vmax=VMAX,
)
draw_motor_cortex(
axes[1],
values=[0.2, 0.5, 0.7, 0.4, 0.8, 0.6],
cmap=CMAP, vmin=VMIN, vmax=VMAX,
)
draw_spinal_cord(
axes[2],
values={"Dors_Horn": 0.9, "Vent_Horn": 0.7, "Med_Grey": 0.4},
cmap=CMAP, vmin=VMIN, vmax=VMAX,
)
for ax in axes:
ax.set_aspect("equal")
ax.autoscale()
ax.axis("off")
# Add a shared colorbar just outside the spinal cord panel.
x0, x1 = axes[2].get_xlim()
y0, y1 = axes[2].get_ylim()
draw_colorbar(
axes[2],
xycoords=(x1 + 0.02 * (x1 - x0), y0, 0.04 * (x1 - x0), y1 - y0),
cmap=CMAP, vmin=VMIN, vmax=VMAX,
label="Expression",
)
plt.tight_layout()
plt.savefig("expression_figure.pdf", bbox_inches="tight")
Development setup
git clone https://github.com/PhatnaniLab/phatnani_transcriptome_plots.git
cd phatnani_transcriptome_plots
pip install -e ".[dev]"
pytest
Releasing
- Create and push a git tag matching
v*(e.g.v0.1.0). - Draft a GitHub Release from that tag.
- The publish workflow builds the distribution, pushes to TestPyPI, then promotes to PyPI automatically.
Trusted publishing — configure an OIDC publisher for
pha-plotson PyPI/TestPyPI (no API tokens needed). See the PyPA guide.
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pha_plots-0.1.0.tar.gz.
File metadata
- Download URL: pha_plots-0.1.0.tar.gz
- Upload date:
- Size: 333.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22519d2570dbebb67fc5c09b5d4ae0c124dd281a594d9c9967ff307e6c02554b
|
|
| MD5 |
69d286afeda3c37867d44f322b808e60
|
|
| BLAKE2b-256 |
8af5186dc9c3f82e998a5d1e191a11fa27690381ed06006124468f2877975f1a
|
Provenance
The following attestation bundles were made for pha_plots-0.1.0.tar.gz:
Publisher:
publish.yml on PhatnaniLab/phatnani_transcriptome_plots
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pha_plots-0.1.0.tar.gz -
Subject digest:
22519d2570dbebb67fc5c09b5d4ae0c124dd281a594d9c9967ff307e6c02554b - Sigstore transparency entry: 1756611505
- Sigstore integration time:
-
Permalink:
PhatnaniLab/phatnani_transcriptome_plots@1a30ea28a40dac8698844620867bb0c9f7b95dc9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/PhatnaniLab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1a30ea28a40dac8698844620867bb0c9f7b95dc9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pha_plots-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pha_plots-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
335cb0fc9769a844a862524655d723a1d7748f5d9e81fc9a1e9e6dd93ada4d81
|
|
| MD5 |
5ee01c46fb820c508ac7ecad3a960183
|
|
| BLAKE2b-256 |
7c4f6de59718c3d777d568cdcc06aa6c20a6ee9661da156c5c3c1c734273f207
|
Provenance
The following attestation bundles were made for pha_plots-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on PhatnaniLab/phatnani_transcriptome_plots
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pha_plots-0.1.0-py3-none-any.whl -
Subject digest:
335cb0fc9769a844a862524655d723a1d7748f5d9e81fc9a1e9e6dd93ada4d81 - Sigstore transparency entry: 1756611683
- Sigstore integration time:
-
Permalink:
PhatnaniLab/phatnani_transcriptome_plots@1a30ea28a40dac8698844620867bb0c9f7b95dc9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/PhatnaniLab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1a30ea28a40dac8698844620867bb0c9f7b95dc9 -
Trigger Event:
release
-
Statement type: