Basic Example (New API)¶
A quick walkthrough for plotting multiple BigWig tracks with the current PlotNado API.
Imports¶
from plotnado import GenomicFigure, LabelConfig
Define the BigWig files that we want to plot¶
Note: The BigWig files are not included in the dataset, as it is possible to just use remote URLs to plot the data I'm going to use data stored on the CCB Oxford HPC.
To make life easier I'm going to make a dictionary of the BigWig files that I want to plot. You could just add these one by one to the plot if you wanted to.
bigwigs = {
'MV4;11 0nM EPZ H3K79me2': 'https://userweb.molbiol.ox.ac.uk/public/project/milne_group/cchahrou/orlando_chip/hg38_dm6/MV4110nMH3K79me2_bigWig.bigWig',
'MV4;11 0.5nM EPZ H3K79me2': 'https://userweb.molbiol.ox.ac.uk/public/project/milne_group/cchahrou/orlando_chip/hg38_dm6/MV41105nMH3K79me2_bigWig.bigWig',
'MV4;11 2nM EPZ H3K79me2': 'https://userweb.molbiol.ox.ac.uk/public/project/milne_group/cchahrou/orlando_chip/hg38_dm6/MV4112nMH3K79me2_bigWig.bigWig',
'MV4;11 5nM EPZ H3K79me2': 'https://userweb.molbiol.ox.ac.uk/public/project/milne_group/cchahrou/orlando_chip/hg38_dm6/MV4115nMH3K79me2_bigWig.bigWig',
}
Generate the plot¶
This example builds a figure with:
- scale bar
- gene annotations
- 4 BigWig tracks
- genomic coordinate axis
figure = Figure().autocolor()
figure.add_track("scalebar")
figure.add_track(
"genes",
genome="hg38",
minimum_gene_length=100_000,
height=0.5,
display="collapsed",
)
for name, url in bigwigs.items():
figure.add_track(
"bigwig",
data=url,
title=name,
style="fill",
autoscale_group="H3K79me2",
min_value=0,
label=LabelConfig(plot_title=True, plot_scale=True),
)
figure.add_track("axis")
Display the plot¶
You've got multiple options for displaying the plot:
- Display it in a Jupyter notebook
- Save it to a file
- Save it as a template for later use or plotting using the CLI
Define the region to plot¶
There are two ways to define the region to plot:
- Use a set of genomic coordinates
- Use a gene name (this must be from a genome that is supported by the package)
region_to_plot = 'chr9:77,620,642-78,119,542' # Define the region to plot, this is a region around the GNAQ gene
gene_to_plot = 'GNAQ' # Define the gene to plot, this is the GNAQ gene
Perform the plotting¶
By Region¶
figure.plot(region_to_plot) # Plot the region
By Gene¶
figure.plot_gene(gene_to_plot)
Save the plot¶
figure.save(
path="GNAQ_H3K79me2.png",
region=region_to_plot,
dpi=300,
)
Examine the saved plot¶

Save the plot as a template¶
This is useful if you want to use the same plot settings for multiple plots, it also allows you to edit the plot settings with standard text editors and then you can either use the PlotNado CLI to generate the plot or you can read in the template and plot it again using the API.
try:
import tomli_w # noqa: F401
except ImportError:
import subprocess
import sys
subprocess.check_call([sys.executable, "-m", "pip", "install", "tomli-w"])
figure.to_toml("H3K79me2.toml")
Examine the template¶
The TOML template stores figure and track settings that can be reloaded with Figure.from_toml(...).
Re-load the template and plot it¶
Figure.from_toml(...) reconstructs the figure and tracks.
If you want auto colors again, call .autocolor() on the loaded figure.
new_figure = Figure.from_toml("H3K79me2.toml").autocolor()
new_figure.plot(region_to_plot)
CLI replotting¶
You can regenerate a figure from a template with the CLI:
plotnado plot --template H3K79me2.toml --region chr9:77620642-78119542 --output GNAQ_H3K79me2_cli.png
Customizing the plot¶
A few common customizations with the new API:
- Changing track colors
- Changing label/scale presentation
- Switching BigWig rendering styles
figure = Figure()
figure.add_track("scalebar")
figure.add_track(
"genes",
genome="hg38",
minimum_gene_length=100_000,
height=0.5,
display="collapsed",
)
bigwig_colours = {
"MV4;11 0nM EPZ H3K79me2": "red",
"MV4;11 0.5nM EPZ H3K79me2": "blue",
"MV4;11 2nM EPZ H3K79me2": "green",
"MV4;11 5nM EPZ H3K79me2": "purple",
}
for name, url in bigwigs.items():
figure.add_track(
"bigwig",
data=url,
title=name,
style="fill",
color=bigwig_colours[name],
autoscale_group="H3K79me2",
min_value=0,
label=LabelConfig(
plot_title=True,
plot_scale=True,
data_range_style="text",
label_box_enabled=True,
label_box_alpha=0.8,
),
)
figure.add_track("axis")
figure.plot_gene("GNAQ")
Changing BigWig styles¶
Supported styles include line, fill, fragment, and scatter.
figure = Figure()
figure.add_track("scalebar")
figure.add_track(
"genes",
genome="hg38",
minimum_gene_length=100_000,
height=0.5,
display="collapsed",
)
bigwig_colours = {
"MV4;11 0nM EPZ H3K79me2": "red",
"MV4;11 0.5nM EPZ H3K79me2": "blue",
"MV4;11 2nM EPZ H3K79me2": "green",
"MV4;11 5nM EPZ H3K79me2": "purple",
}
styles = ["line", "fill", "fragment", "scatter"]
for i, (name, url) in enumerate(bigwigs.items()):
style = styles[i]
figure.add_track(
"bigwig",
data=url,
title=f"{name} ({style})",
style=style,
color=bigwig_colours[name],
autoscale_group="H3K79me2",
min_value=0,
label=LabelConfig(plot_title=True, plot_scale=True, data_range_style="text"),
)
figure.add_track("axis")
figure.plot_gene("GNAQ")
Changing line width and alpha¶
Instead of changing unsupported bin settings, adjust visual emphasis with linewidth and alpha.
figure = Figure()
figure.add_track("scalebar")
figure.add_track(
"genes",
genome="hg38",
minimum_gene_length=100_000,
height=0.5,
display="collapsed",
)
settings = [
(0.4, 0.8),
(0.8, 0.8),
(1.2, 0.7),
(1.8, 0.6),
]
for linewidth, alpha in settings:
figure.add_track(
"bigwig",
data="https://userweb.molbiol.ox.ac.uk/public/project/milne_group/cchahrou/orlando_chip/hg38_dm6/MV4110nMH3K79me2_bigWig.bigWig",
title=f"linewidth={linewidth}, alpha={alpha}",
style="line",
color="red",
autoscale_group="H3K79me2",
min_value=0,
linewidth=linewidth,
alpha=alpha,
label=LabelConfig(plot_title=True, plot_scale=True, data_range_style="text"),
)
figure.add_track("axis")
figure.plot_gene("GNAQ")