ImportsĀ¶
InĀ [1]:
Copied!
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import coolbox.api as cb
from capcruncher.api.plotting import CCTrack, CCFigure
import pyranges as pr
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import coolbox.api as cb
from capcruncher.api.plotting import CCTrack, CCFigure
import pyranges as pr
Read plotting coordinatesĀ¶
InĀ [2]:
Copied!
viewpoints = pr.read_bed("alpha_tile_mm9.bed")
viewpoints
viewpoints = pr.read_bed("alpha_tile_mm9.bed")
viewpoints
Out[2]:
Chromosome | Start | End | Name | |
---|---|---|---|---|
0 | chr11 | 29902950 | 33226736 | Alpha |
Plot using the CapCruncher APIĀ¶
First create a number of CCTrack
instances supported track types:
- heatmap - a contact matrix heatmap in cool format
- bigwig - a bigwig file containing the number of reads per bin
- bigwig_summary - a collection of bigwig files containing the number of reads per bin
- scale - a scale bar. Does not require a file to be specified
- bed - a bed file
- xaxis - an x-axis of genomic coordinates. Does not require a file to be specified
- genes - a gene track in bed12 format
- spacer - a spacer track. Does not require a file to be specified
InĀ [3]:
Copied!
tracks = [
CCTrack(None, type="scale"),
CCTrack(
"capcruncher_output/results/WT_FL_S3_Replicate1/WT_FL_S3_Replicate1.hdf5",
type="heatmap",
binsize=2000,
title="Alpha Tile",
viewpoint="Alpha",
normalization="ice",
transform="yes",
style="triangular",
),
CCTrack(None, type="spacer"),
CCTrack(None, type="spacer"),
CCTrack(None, type="xaxis"),
]
fig = CCFigure(tracks, auto_spacing=False)
tracks = [
CCTrack(None, type="scale"),
CCTrack(
"capcruncher_output/results/WT_FL_S3_Replicate1/WT_FL_S3_Replicate1.hdf5",
type="heatmap",
binsize=2000,
title="Alpha Tile",
viewpoint="Alpha",
normalization="ice",
transform="yes",
style="triangular",
),
CCTrack(None, type="spacer"),
CCTrack(None, type="spacer"),
CCTrack(None, type="xaxis"),
]
fig = CCFigure(tracks, auto_spacing=False)
Option 2: Create a CCFigure
object and add tracks to itĀ¶
As this would overwrite the previous figure, we will create a new figure and add the tracks to it.
InĀ [4]:
Copied!
fig2 = CCFigure(tracks, auto_spacing=False)
fig2.add_track(CCTrack(None, type="scale"))
fig2 = CCFigure(tracks, auto_spacing=False)
fig2.add_track(CCTrack(None, type="scale"))
Plot the figure (Optional)Ā¶
InĀ [5]:
Copied!
# Plot a specific region if desired
fig.plot("chr11:29902950-33226736")
# Plot a specific region if desired
fig.plot("chr11:29902950-33226736")
Out[5]:
Save the figureĀ¶
Two options:
- Save the figure as a static image using the save method of the
CCFigure
. - Save the
CCFigure
as a TOML file which can be edited and either reloaded into aCCFigure
or used by the command line interface to generate a new figure usingcapcruncher plot make-plot
.
Option 1: Save the figure to a fileĀ¶
InĀ [6]:
Copied!
fig.save("chr11:29902950-33226736", output="test.png")
fig.save("chr11:29902950-33226736", output="test.png")
Option 2: Save the figure as a templateĀ¶
InĀ [7]:
Copied!
fig.to_toml(output="template.toml")
fig.to_toml(output="template.toml")
This will look something like this:
InĀ [21]:
Copied!
!head -n 15 template.toml
!head -n 15 template.toml
["scale 0"] type = "scale" ["spacer 0"] type = "spacer" ["spacer 1"] type = "spacer" ["Alpha Tile"] type = "heatmap" binsize = 2000 title = "Alpha Tile" viewpoint = "Alpha" normalization = "ice"
This template can be re-loaded using the CapCruncher package e.g. using the CCFigure.from_toml
method. You can also add new tracks to the figure and re-plot it.
See this rather contrived example of reloading the figure and adding a new scale bar to it.
InĀ [14]:
Copied!
fig = CCFigure.from_toml("template.toml")
fig.add_track(CCTrack(None, type="scale"))
fig.plot("chr11:29902950-33226736")
fig = CCFigure.from_toml("template.toml")
fig.add_track(CCTrack(None, type="scale"))
fig.plot("chr11:29902950-33226736")
Out[14]:
Alternatively the template can be edited and used on the commandline with capcruncher plot
e.g.
InĀ [18]:
Copied!
%%bash
capcruncher \
plot \
--template template.toml \
--region chr11:29902950-33226736 \
-o test.png
%%bash
capcruncher \
plot \
--template template.toml \
--region chr11:29902950-33226736 \
-o test.png
This will generate the same figure as before: