Plotting API¶
Here is an overview of the plot types and functions available in the plotting API.
Index of plot classes¶
|
GenomicFigure composed of one or more plots. |
|
A triangle Hi-C heatmap plot. |
|
Plot Hi-C map as a square matrix. |
|
|
|
Plot data as line. |
|
Plot data from on or more BigWig or Bedgraph files. |
|
Plot genes including exon/intron structure from BED, GTF files or similar. |
|
Plot discrete genomic regions from BED, GTF files or similar. |
alias of |
|
|
Draw Hi-C data as virtual 4C-plot. |
|
Overlay peaks onto Hicplot or HicPlot2D. |
alias of |
|
|
Plot matrix from a |
|
Plot scalar values from one or more |
|
Plot discrete genomic regions from BED, GTF files or similar. |
|
Plot genomic features in layers grouped by name/type.. |
|
Plot data from a table. |
|
Vertical lines or rectangles (shaded regions) which can be positioned at specific genomic coordinates from a BED file and can span multiple panels of the GenomicFigure. |
|
Normalizes data for plotting on a divergent colormap. |
|
Can be used for synchronizing axis limits across multiple plots. |
|
Stack two plots on top of each other, bottom plot inverted. |
|
An distance decay (expected values) plot. |
|
|
|
|
|
Plot the results of a Hi-C PCA analysis from |
Description and examples¶
Provide plotting functions for genomic data types.
Many common data types used in genomics research are supported. Including, but
not limited to, Hi-C
,
bed
,
bigwig
and gene (GTF)
file visualization.
The basic idea is that figures can be composed of multiple panels which are
arranged vertically and share a common x-axis representing genomic coordinates.
Each panel is created separately and then combined into a single figure.
For example, when analyzing Hi-C data it is often interesting to correlate
features in the Hi-C map with ChIP-seq tracks. In that case, one would first
create a HicPlot
object, which visualizes
Hi-C data, and then a BigWigPlot
object, which
can plot bigwig files that are used during ChIP-seq analysis. Finally, the two
objects are used to create a GenomicFigure
.
Example
FAN-C comes with a few example datasets that can be used to explore the basic functionalities of the plotting module. The paths in this example are relative to the top-level fanc directory where the setup.py file is located.
Note
The paths to the example datasets can be accessed easily using the example_data dictionary:
import fanc
print(fanc.example_data)
Yields a dict with the user-specific path to the datasets:
{'chip_bedgraph': '/Users/example/fanc/fanc/test/data/test_plotting/CTCF_ChIP_FE_chr11_77-80Mb_mouse_embryo_fibroblasts.bedgraph.gz',
'chip_bigwig': '/Users/example/fanc/fanc/test/data/test_plotting/CTCF_ChIP_FE_chr11_77-80Mb_mouse_embryo_fibroblasts.bigwig',
'chip_peak_bed': '/Users/example/fanc/fanc/test/data/test_plotting/CTCF_ChIP_FE_chr11_77-80Mb_mouse_embryo_fibroblasts.peaks.bed.gz',
'gene_gtf': '/Users/example/fanc/fanc/test/data/test_plotting/genes_mm10_chr11_77-80Mb.gtf.gz',
'hic': '/Users/example/fanc/fanc/test/data/test_network/rao2014.chr11_77400000_78600000.hic'}
import fanc.plotting as kplot
# Create Hic plot
hplot = kplot.HicPlot("fanc/test/data/test_network/rao2014.chr11_77400000_78600000.hic")
# Create plot showing some CTCF ChIP-seq data from ENCODE
bplot = kplot.BigWigPlot("fanc/test/data/test_plotting/CTCF_ChIP_FE_chr11_77-80Mb_mouse_embryo_fibroblasts.bigwig",
title="CTCF ChIP", ylabel="fold enrichment")
# Create plot of all genes in the region. The squash option in combination
# with the group_by option causes all exons of each gene to be merged.
# This is useful if the number of alternative transcripts is overwhelming
# the plot.
gplot = kplot.GenePlot("fanc/test/data/test_plotting/genes_mm10_chr11_77-80Mb.gtf.gz",
group_by="gene_name", squash=True, show_labels=False,
title="mm10 genes")
# The created plots are used to generate a figure by passing them as a list
# to the GenomicFigure constructor. The order in which they are passed
# determines the order of panels in the figure.
gfig = kplot.GenomicFigure([hplot, bplot, gplot])
# Plot a specific region of the genome
fig, axes = gfig.plot("chr11:77400000-78600000")
# Open plot in an interactive window
fig.show()
Example rendering of the above code saved using
``fig.savefig("example.png", dpi=100)``.
Editing figure and axes¶
The GenomicFigure.plot()
function returns standard matplotlib Figure and a list of Axes instances that
can be further adjusted using standard matplotlib methods. The matplotlib axes
instance associated with each plot is also accesible from the “ax” property of
each plot.
Warning
The Axes instances of the plot should only be edited after
GenomicFigure.plot()
has been called. Otherwise any changes that were made may be overwritten
when the plot() method is called.
For example, to add a bit of annotating text at a specific location in the BigWigPlot, the example above can be edited as follows:
fig, axes = gfig.plot("chr11:77400000-78600000")
bplot.ax.text(77850000, 60, "Interesting peak!")
fig.show()
The coordinates in the Axes are data coordinates, the x-axis is genomic coordinates on the current chromosome and the y-axis in this case the fold-enrichment of the bigwig track.
Basic Plot types and options¶
Note
An explanation of each plot class and the parameters that it supports can be accessed by suffixing a question mark (in Ipython/Jupyter) or calling the help() function:
import fanc.plotting as kplot
kplot.BigWigPlot? # Ipython/Jupyter
help(kplot.BigWigPlot) # standard python
A few basic parameters such as a title and the aspect ratio are available for all plot classes. The aspect ratio parameter is a floating point number between 0 and 1 that determines the height of the plot. A value of 1 results in a square plot, .5 represents a plot that is half as high as it is wide.
The GenomicFigure
provides a few convenience
parameters. Setting ticks_last=True
for example removes tick labels from all
panels but the last one which makes the overall plot more compact.
Independent x-axis and inverting x-axis¶
By default, the x-axis of all plots in a figure are linked, meaning that all plots display exactly the same region. In some situations in can be helpful to plot a multiple regions, such as when features in syntenic regions across multiple species need to be compared. Since syntenic regions can be on the + strand in some species and on the - strande, sometimes the x-axis also needs to be inverted to maintain correct orientation.
In this situation the independent-x
option should be set in the
GenomicFigure
. As a result, the
GenomicFigure.plot()
method
no longer expects a single region as argument, but a list of regions equal to
the number of plots in the figure. We can modify the example above to illustrate
this point:
gfig = kplot.GenomicFigure([hplot, bplot, gplot], independent_x=True)
fig, axes = gfig.plot(["chr11:77400000-78600000", "chr11:77500000-78600000",
"chr11:77200000-78600000"])
fig.show()
Synchronize y-axis limits for multiple datasets¶
Sometimes it can be useful to synchronize y-axis limits across multiple datasets in order to compare their signals. Many plot types support plotting multiple datasets in the same panel, making comparisons easy:
bplot = kplot.BigWigPlot(["dataset1.bigwig", "dataset2.bigwig"])
Alternatively it is possible to synchronize y-axis limits across panels using
LimitGroup
instances. In this example the y-axis limits
are shared between bplot1 and bplot2 and seperately between bplot3 and bplot4:
ygroup = kplot.LimitGroup()
ygroup2 = kplot.LimitGroup(limit=(None, 10))
bplot1 = kplot.BigWigPlot("dataset1.bigwig", ylim=ygroup)
bplot2 = kplot.BigWigPlot("dataset2.bigwig", ylim=ygroup)
bplot3 = kplot.BigWigPlot("dataset3.bigwig", ylim=ygroup2)
bplot4 = kplot.BigWigPlot("dataset4.bigwig", ylim=ygroup2)
It is also possible to constrain the y-axis limits. Passing limit=(None, 10)
to the constructor constrains the upper limit to a maximum of 10 while leaving
the lower limit unconstrained.
Programmatic plotting using loops¶
fanc plotting is ideally suited for programmatic generation of many plots or dynamic assembly of multiple datasets in a single figure. In this example three Hi-C datasets are visualized in a single figure:
import fanc.plotting as kplot
hic_datasets = ["my_data1.hic", "my_data2.hic", my_data3.hic"]
hic_plots = [kplot.HicPlot(h, max_dist=500000) for h in hic_datasets]
gfig = kplot.GenomicFigure(hic_plots)
regions = ["chr11:77400000-78600000", "chr11:1100000-13600000"]
for r in regions:
fig, axes = gfig.plot(r)
fig.savefig("plot_region_{}.png".format(r.replace(":", "_")))
-
fanc.plotting.
example_data
¶ dict with user-specific paths to example data included in fanc.
-
fanc.plotting.
style_ticks_whitegrid
¶ Seaborn style that can be passed to
axes_style
attribute of plots. Draws a grid of lines on the plot.
-
class
fanc.plotting.
TriangularMatrixPlot
(hic_data, max_dist=None, proportional=True, rasterized=True, **kwargs)¶ A triangle Hi-C heatmap plot.
-
__init__
(hic_data, max_dist=None, proportional=True, rasterized=True, **kwargs)¶ - Parameters
max_dist – Only draw interactions up to this distance
proportional – Automatically determine aspect ratio of plot so that x- and y-axis are proportional. Default: True
rasterized – Draw map as image (True) or vector graphic (False). Default: True
hic_data – Path to Hi-C data on disk or
Hic
orRegionMatrix
adjust_range – Draw a slider to adjust vmin/vmax interactively. Default: False
buffering_strategy – A valid buffering strategy for
BufferedMatrix
buffering_arg – Adjust range of buffering for
BufferedMatrix
colormap – Can be the name of a colormap or a Matplotlib colormap instance
norm – Can be “lin”, “log” or any Matplotlib Normalization instance
vmin (float) – Clip interactions below this value
vmax (float) – Clip interactions above this value
show_colorbar (bool) – Draw a colorbar. Default: True
blend_zero (bool) – If True then zero count bins will be drawn using replacement_color
replacement_color (str) – If None use the lowest color in the colormap, otherwise use the specified color. Can be any valid matplotlib color name or specification.
unmappable_color – Draw unmappable bins using this color. Defaults to light gray (“.9”)
illegal_color – Draw non-finite (NaN, +inf, -inf) bins using this color. Defaults to None (no special color).
colorbar_symmetry (float) – Set to enforce that the colorbar is symmetric around this value. Default: None
n_ticks (int) – Number of major x-axis genome coordinate ticks
n_minor_ticks (int) – Number of minor ticks per major tick
title (str) – Title drawn on top of the figure panel.
aspect (float) – Aspect ratio of the plot, height/width. So 0.5 means half as high as wide. Default: Plot type specific sensible value
axes_style – Set styling of the axes, can be anything that seaborn supports. See http://seaborn.pydata.org/tutorial/aesthetics.html#styling-figures-with-axes-style-and-set-style
ylabel (str) – Label for y-axis. Default: None
draw_ticks (bool) – Draw tickmarks. Default: True
draw_major_ticks (bool) – Draw major tickmarks. Default: True
draw_minor_ticks (bool) – Draw minor tickmarks. Default: True
draw_tick_labels (bool) – Draw tick labels. Default: True
draw_x_axis (bool) – If False, remove genome x-axis completely. Default: True
draw_tick_legend (bool) – Draw legend for the tick distances. Default: True
padding (float) – Padding in inches to the next plot. Default: None, automatically calculated.
extra_padding (float) – Add or subtract the specified inches from the automatically calculated padding from this panel to the next.
fix_chromosome (bool) – If True modify chromosome identifiers for this plot, removing or adding ‘chr’ as necessary. Default: False
invert_x (bool) – Invert x-axis. Default=False Caution: This only works reliably when
independent_x=True
in the GenomicFigure instance, since x-axis of all plots are linked otherwise.ax (Axes) – Matplotlib axes instance that the plot will be drawn on. Only necessary if you don’t intend to use a
GenomicFigure
to draw the plot. Default: None
-
-
class
fanc.plotting.
SquareMatrixPlot
(hic_data, flip=False, **kwargs)¶ Plot Hi-C map as a square matrix.
-
__init__
(hic_data, flip=False, **kwargs)¶ - Parameters
flip – Transpose matrix before plotting
hic_data – Path to Hi-C data on disk or
Hic
orRegionMatrix
adjust_range – Draw a slider to adjust vmin/vmax interactively. Default: False
buffering_strategy – A valid buffering strategy for
BufferedMatrix
buffering_arg – Adjust range of buffering for
BufferedMatrix
colormap – Can be the name of a colormap or a Matplotlib colormap instance
norm – Can be “lin”, “log” or any Matplotlib Normalization instance
vmin (float) – Clip interactions below this value
vmax (float) – Clip interactions above this value
show_colorbar (bool) – Draw a colorbar. Default: True
blend_zero (bool) – If True then zero count bins will be drawn using replacement_color
replacement_color (str) – If None use the lowest color in the colormap, otherwise use the specified color. Can be any valid matplotlib color name or specification.
unmappable_color – Draw unmappable bins using this color. Defaults to light gray (“.9”)
illegal_color – Draw non-finite (NaN, +inf, -inf) bins using this color. Defaults to None (no special color).
colorbar_symmetry (float) – Set to enforce that the colorbar is symmetric around this value. Default: None
n_ticks (int) – Number of major ticks
n_minor_ticks (int) – Number of minor ticks per major tick
title (str) – Title drawn on top of the figure panel.
aspect (float) – Aspect ratio of the plot, height/width. So 0.5 means half as high as wide. Default: Plot type specific sensible value
axes_style – Set styling of the axes, can be anything that seaborn supports. See http://seaborn.pydata.org/tutorial/aesthetics.html#styling-figures-with-axes-style-and-set-style
ylabel (str) – Label for y-axis. Default: None
draw_ticks (bool) – Draw tickmarks. Default: True
draw_major_ticks (bool) – Draw major tickmarks. Default: True
draw_minor_ticks (bool) – Draw minor tickmarks. Default: True
draw_tick_labels (bool) – Draw tick labels. Default: True
draw_x_axis (bool) – If False, remove genome x-axis completely. Default: True
draw_tick_legend (bool) – Draw legend for the tick distances. Default: True
padding (float) – Padding in inches to the next plot. Default: None, automatically calculated.
extra_padding (float) – Add or subtract the specified inches from the automatically calculated padding from this panel to the next.
fix_chromosome (bool) – If True modify chromosome identifiers for this plot, removing or adding ‘chr’ as necessary. Default: False
invert_x (bool) – Invert x-axis. Default=False Caution: This only works reliably when
independent_x=True
in the GenomicFigure instance, since x-axis of all plots are linked otherwise.ax (Axes) – Matplotlib axes instance that the plot will be drawn on. Only necessary if you don’t intend to use a
GenomicFigure
to draw the plot. Default: None
-
-
class
fanc.plotting.
SplitMatrixPlot
(hic_top, hic_bottom, scale_matrices=True, weight_field=None, default_value=None, smooth_sigma=None, matrix_norm=True, oe=False, log=False, **kwargs)¶ -
__init__
(hic_top, hic_bottom, scale_matrices=True, weight_field=None, default_value=None, smooth_sigma=None, matrix_norm=True, oe=False, log=False, **kwargs)¶ - Parameters
flip – Transpose matrix before plotting
hic_data – Path to Hi-C data on disk or
Hic
orRegionMatrix
adjust_range – Draw a slider to adjust vmin/vmax interactively. Default: False
buffering_strategy – A valid buffering strategy for
BufferedMatrix
buffering_arg – Adjust range of buffering for
BufferedMatrix
colormap – Can be the name of a colormap or a Matplotlib colormap instance
norm – Can be “lin”, “log” or any Matplotlib Normalization instance
vmin (float) – Clip interactions below this value
vmax (float) – Clip interactions above this value
show_colorbar (bool) – Draw a colorbar. Default: True
blend_zero (bool) – If True then zero count bins will be drawn using replacement_color
replacement_color (str) – If None use the lowest color in the colormap, otherwise use the specified color. Can be any valid matplotlib color name or specification.
unmappable_color – Draw unmappable bins using this color. Defaults to light gray (“.9”)
illegal_color – Draw non-finite (NaN, +inf, -inf) bins using this color. Defaults to None (no special color).
colorbar_symmetry (float) – Set to enforce that the colorbar is symmetric around this value. Default: None
n_ticks (int) – Number of major ticks
n_minor_ticks (int) – Number of minor ticks per major tick
title (str) – Title drawn on top of the figure panel.
aspect (float) – Aspect ratio of the plot, height/width. So 0.5 means half as high as wide. Default: Plot type specific sensible value
axes_style – Set styling of the axes, can be anything that seaborn supports. See http://seaborn.pydata.org/tutorial/aesthetics.html#styling-figures-with-axes-style-and-set-style
ylabel (str) – Label for y-axis. Default: None
draw_ticks (bool) – Draw tickmarks. Default: True
draw_major_ticks (bool) – Draw major tickmarks. Default: True
draw_minor_ticks (bool) – Draw minor tickmarks. Default: True
draw_tick_labels (bool) – Draw tick labels. Default: True
draw_x_axis (bool) – If False, remove genome x-axis completely. Default: True
draw_tick_legend (bool) – Draw legend for the tick distances. Default: True
padding (float) – Padding in inches to the next plot. Default: None, automatically calculated.
extra_padding (float) – Add or subtract the specified inches from the automatically calculated padding from this panel to the next.
fix_chromosome (bool) – If True modify chromosome identifiers for this plot, removing or adding ‘chr’ as necessary. Default: False
invert_x (bool) – Invert x-axis. Default=False Caution: This only works reliably when
independent_x=True
in the GenomicFigure instance, since x-axis of all plots are linked otherwise.ax (Axes) – Matplotlib axes instance that the plot will be drawn on. Only necessary if you don’t intend to use a
GenomicFigure
to draw the plot. Default: None
-
-
fanc.plotting.
HicComparisonPlot2D
¶ alias of
fanc.plotting.hic_plotter.SplitMatrixPlot
-
class
fanc.plotting.
HicSlicePlot
(hic_data, slice_region, names=None, colors=None, fill=None, buffering_strategy='relative', buffering_arg=1, weight_field=None, default_value=None, **kwargs)¶ Draw Hi-C data as virtual 4C-plot. All interactions that involve the slice region are shown.
-
__init__
(hic_data, slice_region, names=None, colors=None, fill=None, buffering_strategy='relative', buffering_arg=1, weight_field=None, default_value=None, **kwargs)¶ - Parameters
hic_data –
Hic
orRegionMatrix
. Can be list of multiple Hi-C datasets.slice_region – String (“2L:1000000-1500000”) or
GenomicRegion
. All interactions involving this region are shown.names – If multiple Hi-C datasets are provided, can pass a list of names. Are used as names in the legend of the plot.
buffering_strategy – A valid buffering strategy for class:~BufferedMatrix
buffering_arg – Adjust range of buffering for class:~BufferedMatrix
style (str) – ‘step’ Draw values in a step-wise manner for each bin ‘mid’ Draw values connecting mid-points of bins
tupleylim – Set y-axis limits as tuple. Can leave upper or lower limit undetermined by setting None, e.g. (2.5, None). Alternatively, a
LimitGroup
instance can be passed to synchronize limits across multiple plots. Default: Automatically determined by data limitsyscale (str) – Scale of y-axis. Is passed to Matplotlib set_yscale, so any valid argument (“linear”, “log”, etc.) works Default: “linear”
condensed (bool) – Only show maximum y-axis tick. Default: False
n_yticks (int) – Number of y-axis ticks. If only the maximum tick should be displayed set condensed to True. Default: 3
n_ticks (int) – Number of major x-axis genome coordinate ticks
n_minor_ticks (int) – Number of minor ticks per major tick
title (str) – Title drawn on top of the figure panel.
aspect (float) – Aspect ratio of the plot, height/width. So 0.5 means half as high as wide. Default: Plot type specific sensible value
axes_style – Set styling of the axes, can be anything that seaborn supports. See http://seaborn.pydata.org/tutorial/aesthetics.html#styling-figures-with-axes-style-and-set-style
ylabel (str) – Label for y-axis. Default: None
draw_ticks (bool) – Draw tickmarks. Default: True
draw_major_ticks (bool) – Draw major tickmarks. Default: True
draw_minor_ticks (bool) – Draw minor tickmarks. Default: True
draw_tick_labels (bool) – Draw tick labels. Default: True
draw_x_axis (bool) – If False, remove genome x-axis completely. Default: True
draw_tick_legend (bool) – Draw legend for the tick distances. Default: True
padding (float) – Padding in inches to the next plot. Default: None, automatically calculated.
extra_padding (float) – Add or subtract the specified inches from the automatically calculated padding from this panel to the next.
fix_chromosome (bool) – If True modify chromosome identifiers for this plot, removing or adding ‘chr’ as necessary. Default: False
invert_x (bool) – Invert x-axis. Default=False Caution: This only works reliably when
independent_x=True
in the GenomicFigure instance, since x-axis of all plots are linked otherwise.ax (Axes) – Matplotlib axes instance that the plot will be drawn on. Only necessary if you don’t intend to use a
GenomicFigure
to draw the plot. Default: None
-
-
class
fanc.plotting.
HicPeakPlot
(peaks, radius=None, circle_props={}, **kwargs)¶ Overlay peaks onto Hicplot or HicPlot2D. Accepts
PeakInfo
. Add to HicPlot or HicPlot2D using add_overlay method.-
__init__
(peaks, radius=None, circle_props={}, **kwargs)¶ - Parameters
peaks – fanc peaks instance
radius – Radius in bp for plotted circles. If not specified (default), use the radius of the peak itself. This is often too small to see, providing a value like 50000 helps. Default: None
circe_props – Dictionary with properties for the plotted circles for the matplotlib.patches.Circle constructor. Default: Black edges, no fill, linewidth 3 pt
-
-
fanc.plotting.
VerticalSplitPlot
¶ alias of
fanc.plotting.plotter.MirrorMatrixPlot
-
class
fanc.plotting.
GenomicVectorArrayPlot
(array, parameters=None, y_coords=None, y_scale='linear', plot_kwargs=None, genomic_format=False, **kwargs)¶ Plot matrix from a
MultiVectorArchitecturalRegionFeature
object.-
__init__
(array, parameters=None, y_coords=None, y_scale='linear', plot_kwargs=None, genomic_format=False, **kwargs)¶ - Parameters
array –
MultiVectorArchitecturalRegionFeature
keys – keys for which vectors to use for array. None indicates all vectors will be used.
y_coords – Matrices in the
GenomicTrack
object are unitless. Can provide the coordinates for the y-direction here. Matrix has shape (X, Y) must have shape Y or Y + 1y_scale – Set scale of the y-axis, is passed to Matplotlib set_yscale, so any valid argument (“linear”, “log”, etc.) works
plot_kwargs – Keyword-arguments passed on to pcolormesh
colormap – Can be the name of a colormap or a Matplotlib colormap instance
norm – Can be “lin”, “log” or any Matplotlib Normalization instance
vmin (float) – Clip interactions below this value
vmax (float) – Clip interactions above this value
show_colorbar (bool) – Draw a colorbar. Default: True
blend_zero (bool) – If True then zero count bins will be drawn using replacement_color
replacement_color (str) – If None use the lowest color in the colormap, otherwise use the specified color. Can be any valid matplotlib color name or specification.
unmappable_color – Draw unmappable bins using this color. Defaults to light gray (“.9”)
illegal_color – Draw non-finite (NaN, +inf, -inf) bins using this color. Defaults to None (no special color).
colorbar_symmetry (float) – Set to enforce that the colorbar is symmetric around this value. Default: None
n_ticks (int) – Number of major x-axis genome coordinate ticks
n_minor_ticks (int) – Number of minor ticks per major tick
title (str) – Title drawn on top of the figure panel.
aspect (float) – Aspect ratio of the plot, height/width. So 0.5 means half as high as wide. Default: Plot type specific sensible value
axes_style – Set styling of the axes, can be anything that seaborn supports. See http://seaborn.pydata.org/tutorial/aesthetics.html#styling-figures-with-axes-style-and-set-style
ylabel (str) – Label for y-axis. Default: None
draw_ticks (bool) – Draw tickmarks. Default: True
draw_major_ticks (bool) – Draw major tickmarks. Default: True
draw_minor_ticks (bool) – Draw minor tickmarks. Default: True
draw_tick_labels (bool) – Draw tick labels. Default: True
draw_x_axis (bool) – If False, remove genome x-axis completely. Default: True
draw_tick_legend (bool) – Draw legend for the tick distances. Default: True
padding (float) – Padding in inches to the next plot. Default: None, automatically calculated.
extra_padding (float) – Add or subtract the specified inches from the automatically calculated padding from this panel to the next.
fix_chromosome (bool) – If True modify chromosome identifiers for this plot, removing or adding ‘chr’ as necessary. Default: False
invert_x (bool) – Invert x-axis. Default=False Caution: This only works reliably when
independent_x=True
in the GenomicFigure instance, since x-axis of all plots are linked otherwise.ax (Axes) – Matplotlib axes instance that the plot will be drawn on. Only necessary if you don’t intend to use a
GenomicFigure
to draw the plot. Default: None
-
-
class
fanc.plotting.
GenomicFeaturePlot
(regions, feature_types=False, label_field='gene_symbol', label_func=None, color='black', **kwargs)¶ Plot discrete genomic regions from BED, GTF files or similar. Just draws a black box where the feature is located.
-
__init__
(regions, feature_types=False, label_field='gene_symbol', label_func=None, color='black', **kwargs)¶ - Parameters
regions – Any input that pybedtools can parse. Can be a path to a GTF/BED file or a list of tuples [(2L, 500, 1000), (3R, 400, 600), …]
feature_types – If the input file is a GTF, only draw certain feature types (3rd column) If False, draw all features on a common track If None, automatically draw different feature types on separate tracks If a list, draw only the feature types in the list on separate tracks, don’t draw the rest.
label_field – Use this field as a label for each feature drawn. Can be an integer to select a specific column or the name of an attribute in the GTF file. If None or False no label is drawn. E.g. 2 for the second column or “score” for the score attribute.
label_func – Alternatively, label can be generated by calling this function which takes pybedtools.Interval als argument and returns label string
n_ticks (int) – Number of major x-axis genome coordinate ticks
n_minor_ticks (int) – Number of minor ticks per major tick
title (str) – Title drawn on top of the figure panel.
aspect (float) – Aspect ratio of the plot, height/width. So 0.5 means half as high as wide. Default: Plot type specific sensible value
axes_style – Set styling of the axes, can be anything that seaborn supports. See http://seaborn.pydata.org/tutorial/aesthetics.html#styling-figures-with-axes-style-and-set-style
ylabel (str) – Label for y-axis. Default: None
draw_ticks (bool) – Draw tickmarks. Default: True
draw_major_ticks (bool) – Draw major tickmarks. Default: True
draw_minor_ticks (bool) – Draw minor tickmarks. Default: True
draw_tick_labels (bool) – Draw tick labels. Default: True
draw_x_axis (bool) – If False, remove genome x-axis completely. Default: True
draw_tick_legend (bool) – Draw legend for the tick distances. Default: True
padding (float) – Padding in inches to the next plot. Default: None, automatically calculated.
extra_padding (float) – Add or subtract the specified inches from the automatically calculated padding from this panel to the next.
fix_chromosome (bool) – If True modify chromosome identifiers for this plot, removing or adding ‘chr’ as necessary. Default: False
invert_x (bool) – Invert x-axis. Default=False Caution: This only works reliably when
independent_x=True
in the GenomicFigure instance, since x-axis of all plots are linked otherwise.ax (Axes) – Matplotlib axes instance that the plot will be drawn on. Only necessary if you don’t intend to use a
GenomicFigure
to draw the plot. Default: None
-
-
class
fanc.plotting.
GenomicRegionsPlot
(regions, attributes=None, names=None, colors=None, linestyles=None, legend=True, **kwargs)¶ Plot scalar values from one or more
GenomicRegions
objects-
__init__
(regions, attributes=None, names=None, colors=None, linestyles=None, legend=True, **kwargs)¶ - Parameters
regions –
GenomicRegions
attributes – Only draw attributes from the track objects which match this description. Should be a list of names. Supports wildcard matching and regex.
names – Supply list of names for each track.
legend – Draw legend. Default: True
style (str) – ‘step’ Draw values in a step-wise manner for each bin ‘mid’ Draw values connecting mid-points of bins
tupleylim – Set y-axis limits as tuple. Can leave upper or lower limit undetermined by setting None, e.g. (2.5, None). Alternatively, a
LimitGroup
instance can be passed to synchronize limits across multiple plots. Default: Automatically determined by data limitsyscale (str) – Scale of y-axis. Is passed to Matplotlib set_yscale, so any valid argument (“linear”, “log”, etc.) works Default: “linear”
condensed (bool) – Only show maximum y-axis tick. Default: False
n_yticks (int) – Number of y-axis ticks. If only the maximum tick should be displayed set condensed to True. Default: 3
n_ticks (int) – Number of major x-axis genome coordinate ticks
n_minor_ticks (int) – Number of minor ticks per major tick
title (str) – Title drawn on top of the figure panel.
aspect (float) – Aspect ratio of the plot, height/width. So 0.5 means half as high as wide. Default: Plot type specific sensible value
axes_style – Set styling of the axes, can be anything that seaborn supports. See http://seaborn.pydata.org/tutorial/aesthetics.html#styling-figures-with-axes-style-and-set-style
ylabel (str) – Label for y-axis. Default: None
draw_ticks (bool) – Draw tickmarks. Default: True
draw_major_ticks (bool) – Draw major tickmarks. Default: True
draw_minor_ticks (bool) – Draw minor tickmarks. Default: True
draw_tick_labels (bool) – Draw tick labels. Default: True
draw_x_axis (bool) – If False, remove genome x-axis completely. Default: True
draw_tick_legend (bool) – Draw legend for the tick distances. Default: True
padding (float) – Padding in inches to the next plot. Default: None, automatically calculated.
extra_padding (float) – Add or subtract the specified inches from the automatically calculated padding from this panel to the next.
fix_chromosome (bool) – If True modify chromosome identifiers for this plot, removing or adding ‘chr’ as necessary. Default: False
invert_x (bool) – Invert x-axis. Default=False Caution: This only works reliably when
independent_x=True
in the GenomicFigure instance, since x-axis of all plots are linked otherwise.ax (Axes) – Matplotlib axes instance that the plot will be drawn on. Only necessary if you don’t intend to use a
GenomicFigure
to draw the plot. Default: None
-
-
class
fanc.plotting.
GenomicFeatureScorePlot
(regions, attribute='score', feature_types=None, color_neutral='grey', color_forward='red', color_reverse='blue', annotation_field=None, ylim=None, **kwargs)¶ Plot discrete genomic regions from BED, GTF files or similar.
Regions will be plotted as bars with the height equal to the score provided in the file.
-
__init__
(regions, attribute='score', feature_types=None, color_neutral='grey', color_forward='red', color_reverse='blue', annotation_field=None, ylim=None, **kwargs)¶ - Parameters
regions – Any input that pybedtools can parse. Can be a path to a GTF/BED file or a list of tuples [(2L, 500, 1000), (3R, 400, 600), …]
attribute – Field in the fiel which is plotted as score. Can be integer or attribute name (if it is a GTF/GFF file)
feature_types – If the input file is a GTF, only draw certain feature types (3rd column) If False, draw all features on a common track If None, automatically draw different feature types on separate tracks If a list, draw only the feature types in the list on separate tracks, don’t draw the rest.
n_ticks (int) – Number of major x-axis genome coordinate ticks
n_minor_ticks (int) – Number of minor ticks per major tick
title (str) – Title drawn on top of the figure panel.
aspect (float) – Aspect ratio of the plot, height/width. So 0.5 means half as high as wide. Default: Plot type specific sensible value
axes_style – Set styling of the axes, can be anything that seaborn supports. See http://seaborn.pydata.org/tutorial/aesthetics.html#styling-figures-with-axes-style-and-set-style
ylabel (str) – Label for y-axis. Default: None
draw_ticks (bool) – Draw tickmarks. Default: True
draw_major_ticks (bool) – Draw major tickmarks. Default: True
draw_minor_ticks (bool) – Draw minor tickmarks. Default: True
draw_tick_labels (bool) – Draw tick labels. Default: True
draw_x_axis (bool) – If False, remove genome x-axis completely. Default: True
draw_tick_legend (bool) – Draw legend for the tick distances. Default: True
padding (float) – Padding in inches to the next plot. Default: None, automatically calculated.
extra_padding (float) – Add or subtract the specified inches from the automatically calculated padding from this panel to the next.
fix_chromosome (bool) – If True modify chromosome identifiers for this plot, removing or adding ‘chr’ as necessary. Default: False
invert_x (bool) – Invert x-axis. Default=False Caution: This only works reliably when
independent_x=True
in the GenomicFigure instance, since x-axis of all plots are linked otherwise.ax (Axes) – Matplotlib axes instance that the plot will be drawn on. Only necessary if you don’t intend to use a
GenomicFigure
to draw the plot. Default: None
-
-
class
fanc.plotting.
GenomicFigure
(plots, width=4.0, ticks_last=False, invert_x=False, cax_padding=0.3, cax_width=0.3, fig_padding=(0.5, 0.5, 1.0, 1.0), independent_x=False)¶ GenomicFigure composed of one or more plots. All plots are arranged in a single column, their genomic coordinates aligned.
-
__init__
(plots, width=4.0, ticks_last=False, invert_x=False, cax_padding=0.3, cax_width=0.3, fig_padding=(0.5, 0.5, 1.0, 1.0), independent_x=False)¶ - Parameters
plots (list) – List of plot instances each will form a separate panel in the figure. Should inherit from
BasePlotter
orBaseAnnotation
width (float) – Width of the plots in inches. Height is automatically determined from the specified aspect ratios of the Plots. Default: 5.
ticks_last (bool) – Only draw genomic coordinate tick labels on last (bottom) plot
invert_x (bool) – Invert x-axis for on all plots. Default: False
cax_padding (float) – Distance between plots and the colorbar in inches. Default: 0.3
cax_width (float) – Width of colorbar in inches. Default: 0.5
fig_padding (tuple(float, float, float, float)) – Distance between the edges of the plots and the figure borders in inches (bottom, top, left, right). Default: (.5, .5, .5, .5)
independent_x (bool) – When plotting, supply separate coordinates for each plot in the figure. Default: False
-
plot
(region)¶ Make a plot of the specified region.
- Parameters
region (string or GenomicRegion) – A string describing a region “2L:10000000-12000000” or a
GenomicRegion
. Ifindependent_x
was set, a list of regions equal to the length of plots + the length of annotations (if present) must be supplied. The order of the regions here must be the same as the order in which the plots were supplied to the GenomicFigure constructor.- Returns
A matplotlib Figure instance and a list of figure axes
-
-
class
fanc.plotting.
BigWigPlot
(bigwigs, names=None, bin_size=None, fill=True, plot_kwargs=None, **kwargs)¶ Plot data from on or more BigWig or Bedgraph files. Deprecated, use LinePlot instead.
-
__init__
(bigwigs, names=None, bin_size=None, fill=True, plot_kwargs=None, **kwargs)¶ - Parameters
bigwigs – Path or list of paths to bigwig or bedgraph files
names – List of names for each bigwig. Used as label in the legend.
bin_size – Bin BigWig values using fixed size bins of the given size. If None, will plot values as they are in the BigWig file
fill – Fill space between x-axis and data line. Default: True
plot_kwargs – Dictionary of additional keyword arguments passed to the plot function
style (str) – ‘step’ Draw values in a step-wise manner for each bin ‘mid’ Draw values connecting mid-points of bins
tupleylim – Set y-axis limits as tuple. Can leave upper or lower limit undetermined by setting None, e.g. (2.5, None). Alternatively, a
LimitGroup
instance can be passed to synchronize limits across multiple plots. Default: Automatically determined by data limitsyscale (str) – Scale of y-axis. Is passed to Matplotlib set_yscale, so any valid argument (“linear”, “log”, etc.) works Default: “linear”
condensed (bool) – Only show maximum y-axis tick. Default: False
n_yticks (int) – Number of y-axis ticks. If only the maximum tick should be displayed set condensed to True. Default: 3
n_ticks (int) – Number of major x-axis genome coordinate ticks
n_minor_ticks (int) – Number of minor ticks per major tick
title (str) – Title drawn on top of the figure panel.
aspect (float) – Aspect ratio of the plot, height/width. So 0.5 means half as high as wide. Default: Plot type specific sensible value
axes_style – Set styling of the axes, can be anything that seaborn supports. See http://seaborn.pydata.org/tutorial/aesthetics.html#styling-figures-with-axes-style-and-set-style
ylabel (str) – Label for y-axis. Default: None
draw_ticks (bool) – Draw tickmarks. Default: True
draw_major_ticks (bool) – Draw major tickmarks. Default: True
draw_minor_ticks (bool) – Draw minor tickmarks. Default: True
draw_tick_labels (bool) – Draw tick labels. Default: True
draw_x_axis (bool) – If False, remove genome x-axis completely. Default: True
draw_tick_legend (bool) – Draw legend for the tick distances. Default: True
padding (float) – Padding in inches to the next plot. Default: None, automatically calculated.
extra_padding (float) – Add or subtract the specified inches from the automatically calculated padding from this panel to the next.
fix_chromosome (bool) – If True modify chromosome identifiers for this plot, removing or adding ‘chr’ as necessary. Default: False
invert_x (bool) – Invert x-axis. Default=False Caution: This only works reliably when
independent_x=True
in the GenomicFigure instance, since x-axis of all plots are linked otherwise.ax (Axes) – Matplotlib axes instance that the plot will be drawn on. Only necessary if you don’t intend to use a
GenomicFigure
to draw the plot. Default: None
-
-
class
fanc.plotting.
LinePlot
(data, bin_size=None, fill=True, attribute='score', colors=None, show_legend=None, legend_location='best', **kwargs)¶ Plot data as line. Data must be
RegionBased
-
__init__
(data, bin_size=None, fill=True, attribute='score', colors=None, show_legend=None, legend_location='best', **kwargs)¶ - Parameters
data – Data or list of data. Or dictionary, where keys represent data labels. Data can be paths to files on the disk or anything that pybedtools can parse [(chr, start, end, score), …]. If a list of data or dict is provided multiple lines are drawn. Examples: data=[“x.bigwig”, [(“chr11”, 40, 50, 1.8), (“chr11”, 50, 70, 4.3)]] data=[“y.bedgraph”, “z.bigwig”] data={“x_chip”: “x.bedgraph”, “y_chip”: “y.bigwig”}
labels – List of labels for each data file. Used as label in the legend. Ignored if labels are specified in data dictionary.
bin_size – Bin values using fixed size bins of the given size. If None, will plot values as they are in the data.
fill – Fill space between x-axis and data line. Default: True
plot_kwargs – Dictionary of additional keyword arguments passed to the plot function
data – Data or list of data. Or dictionary, where keys represent data labels. Data can be paths to files on the disk or anthing that pybedtools can parse [(chr, start, end, score), …]. If a list of data or dict is provided multiple lines are drawn. Examples: data=[“x.bigwig”, [(“chr11”, 40, 50, 1.8), (“chr11”, 50, 70, 4.3)]] data=[“y.bedgraph”, “z.bigwig”] data={“x_chip”: “x.bedgraph”, “y_chip”: “y.bigwig”}
labels – List of labels for each data file. Used as label in the legend. Ignored if labels are specified in data dictionary.
bin_size – Bin values using fixed size bins of the given size. If None, will plot values as they are in the data.
fill – Fill space between x-axis and data line. Default: True
plot_kwargs – Dictionary of additional keyword arguments passed to the plot function
style (str) – ‘step’ Draw values in a step-wise manner for each bin ‘mid’ Draw values connecting mid-points of bins
tupleylim – Set y-axis limits as tuple. Can leave upper or lower limit undetermined by setting None, e.g. (2.5, None). Alternatively, a
LimitGroup
instance can be passed to synchronize limits across multiple plots. Default: Automatically determined by data limitsyscale (str) – Scale of y-axis. Is passed to Matplotlib set_yscale, so any valid argument (“linear”, “log”, etc.) works Default: “linear”
condensed (bool) – Only show maximum y-axis tick. Default: False
n_yticks (int) – Number of y-axis ticks. If only the maximum tick should be displayed set condensed to True. Default: 3
n_ticks (int) – Number of major x-axis genome coordinate ticks
n_minor_ticks (int) – Number of minor ticks per major tick
title (str) – Title drawn on top of the figure panel.
aspect (float) – Aspect ratio of the plot, height/width. So 0.5 means half as high as wide. Default: Plot type specific sensible value
axes_style – Set styling of the axes, can be anything that seaborn supports. See http://seaborn.pydata.org/tutorial/aesthetics.html#styling-figures-with-axes-style-and-set-style
ylabel (str) – Label for y-axis. Default: None
draw_ticks (bool) – Draw tickmarks. Default: True
draw_major_ticks (bool) – Draw major tickmarks. Default: True
draw_minor_ticks (bool) – Draw minor tickmarks. Default: True
draw_tick_labels (bool) – Draw tick labels. Default: True
draw_x_axis (bool) – If False, remove genome x-axis completely. Default: True
draw_tick_legend (bool) – Draw legend for the tick distances. Default: True
padding (float) – Padding in inches to the next plot. Default: None, automatically calculated.
extra_padding (float) – Add or subtract the specified inches from the automatically calculated padding from this panel to the next.
fix_chromosome (bool) – If True modify chromosome identifiers for this plot, removing or adding ‘chr’ as necessary. Default: False
invert_x (bool) – Invert x-axis. Default=False Caution: This only works reliably when
independent_x=True
in the GenomicFigure instance, since x-axis of all plots are linked otherwise.ax (Axes) – Matplotlib axes instance that the plot will be drawn on. Only necessary if you don’t intend to use a
GenomicFigure
to draw the plot. Default: None
-
-
class
fanc.plotting.
GenePlot
(genes, feature_types=('exon', ), color_neutral='gray', color_forward='orangered', color_reverse='darkturquoise', color_score=False, box_height=0.1, show_labels=True, label_field='name', font_size=9, arrow_size=8, show_arrows=True, line_width=1, group_by='transcript_id', collapse=False, squash=False, min_gene_size=None, lookahead=2000000, score_colormap='RdBu', relative_text_offset=0.01, relative_marker_step=0.03, no_labels_outside_plot=False, include=None, exclude=None, **kwargs)¶ Plot genes including exon/intron structure from BED, GTF files or similar.
-
__init__
(genes, feature_types=('exon', ), color_neutral='gray', color_forward='orangered', color_reverse='darkturquoise', color_score=False, box_height=0.1, show_labels=True, label_field='name', font_size=9, arrow_size=8, show_arrows=True, line_width=1, group_by='transcript_id', collapse=False, squash=False, min_gene_size=None, lookahead=2000000, score_colormap='RdBu', relative_text_offset=0.01, relative_marker_step=0.03, no_labels_outside_plot=False, include=None, exclude=None, **kwargs)¶ - Parameters
genes – Any input that pybedtools can parse. Can be a path to a GTF/BED file
feature_types – If the input file is a GTF, only draw certain feature types (3rd column) If False, draw all features on a common track If None, automatically draw different feature types on separate tracks If a list, draw only the feature types in the list on separate tracks, don’t draw the rest.
label_field – Field of input file for labelling transcripts/genes. Default: name
collapse – Draw all transcripts on a single row. Everything will overlap. Default: False
squash – Squash all exons belonging to a single grouping unit (merging overlapping exons). Useful especially when setting group_by=”gene_id” or “gene_symbol”. Genes will still draw on separate rows, if necessary. Default: False
n_ticks (int) – Number of major x-axis genome coordinate ticks
n_minor_ticks (int) – Number of minor ticks per major tick
title (str) – Title drawn on top of the figure panel.
aspect (float) – Aspect ratio of the plot, height/width. So 0.5 means half as high as wide. Default: Plot type specific sensible value
axes_style – Set styling of the axes, can be anything that seaborn supports. See http://seaborn.pydata.org/tutorial/aesthetics.html#styling-figures-with-axes-style-and-set-style
ylabel (str) – Label for y-axis. Default: None
draw_ticks (bool) – Draw tickmarks. Default: True
draw_major_ticks (bool) – Draw major tickmarks. Default: True
draw_minor_ticks (bool) – Draw minor tickmarks. Default: True
draw_tick_labels (bool) – Draw tick labels. Default: True
draw_x_axis (bool) – If False, remove genome x-axis completely. Default: True
draw_tick_legend (bool) – Draw legend for the tick distances. Default: True
padding (float) – Padding in inches to the next plot. Default: None, automatically calculated.
extra_padding (float) – Add or subtract the specified inches from the automatically calculated padding from this panel to the next.
fix_chromosome (bool) – If True modify chromosome identifiers for this plot, removing or adding ‘chr’ as necessary. Default: False
invert_x (bool) – Invert x-axis. Default=False Caution: This only works reliably when
independent_x=True
in the GenomicFigure instance, since x-axis of all plots are linked otherwise.ax (Axes) – Matplotlib axes instance that the plot will be drawn on. Only necessary if you don’t intend to use a
GenomicFigure
to draw the plot. Default: None
-
-
class
fanc.plotting.
FeatureLayerPlot
(features, gff_grouping_attribute=None, element_height=0.8, include=None, exclude=None, color_by='strand', colors=((1, 'orangered'), (-1, 'darkturquoise')), shadow=True, shadow_width=0.005, collapse=False, **kwargs)¶ Plot genomic features in layers grouped by name/type.:
B1 - - - B2 - - - - - L1 --- --- -- _____________________ 0 10 20 30
-
__init__
(features, gff_grouping_attribute=None, element_height=0.8, include=None, exclude=None, color_by='strand', colors=((1, 'orangered'), (-1, 'darkturquoise')), shadow=True, shadow_width=0.005, collapse=False, **kwargs)¶ - Parameters
features – Any input that pybedtools can parse. Can be a path to a GTF/BED file. If BED, elements will be grouped by name, if GFF will be grouped by feature type
gff_grouping_attribute – By default, GFF entries are grouped by feature type, change this to any attribute using this parameter
element_height – Height of an individual element in the plot. A row’s height is 1.0, so you should choose a value smaller than that.
color_by – element attribute to color the element by. Currently, only categorical values are supported.
colors – List of (attribute, color) pairs to color elements according to some attribute
shadow – Draws a translucent box under each element the is min_element_width wide. Useful if the size of elements is very small compared to plotting region
shadow_width – Width of the shadow of an element in fraction of plotting region. Some very small features won’t be visible in this plot unless you increase this parameter
collapse – Collapse all rows onto a single one (ignore grouping)
n_ticks (int) – Number of major x-axis genome coordinate ticks
n_minor_ticks (int) – Number of minor ticks per major tick
title (str) – Title drawn on top of the figure panel.
aspect (float) – Aspect ratio of the plot, height/width. So 0.5 means half as high as wide. Default: Plot type specific sensible value
axes_style – Set styling of the axes, can be anything that seaborn supports. See http://seaborn.pydata.org/tutorial/aesthetics.html#styling-figures-with-axes-style-and-set-style
ylabel (str) – Label for y-axis. Default: None
draw_ticks (bool) – Draw tickmarks. Default: True
draw_major_ticks (bool) – Draw major tickmarks. Default: True
draw_minor_ticks (bool) – Draw minor tickmarks. Default: True
draw_tick_labels (bool) – Draw tick labels. Default: True
draw_x_axis (bool) – If False, remove genome x-axis completely. Default: True
draw_tick_legend (bool) – Draw legend for the tick distances. Default: True
padding (float) – Padding in inches to the next plot. Default: None, automatically calculated.
extra_padding (float) – Add or subtract the specified inches from the automatically calculated padding from this panel to the next.
fix_chromosome (bool) – If True modify chromosome identifiers for this plot, removing or adding ‘chr’ as necessary. Default: False
invert_x (bool) – Invert x-axis. Default=False Caution: This only works reliably when
independent_x=True
in the GenomicFigure instance, since x-axis of all plots are linked otherwise.ax (Axes) – Matplotlib axes instance that the plot will be drawn on. Only necessary if you don’t intend to use a
GenomicFigure
to draw the plot. Default: None
-
-
class
fanc.plotting.
GenomicDataFramePlot
(genomic_data_frame, names=None, plot_kwargs=None, **kwargs)¶ Plot data from a table.
-
__init__
(genomic_data_frame, names=None, plot_kwargs=None, **kwargs)¶ - Parameters
genomic_data_frame –
GenomicDataFrame
names – List of column names to plot (on the same axis)
plot_kwargs – Dictionary of additional keyword arguments passed to the plot function
style (str) – ‘step’ Draw values in a step-wise manner for each bin ‘mid’ Draw values connecting mid-points of bins
tupleylim – Set y-axis limits as tuple. Can leave upper or lower limit undetermined by setting None, e.g. (2.5, None). Alternatively, a
LimitGroup
instance can be passed to synchronize limits across multiple plots. Default: Automatically determined by data limitsyscale (str) – Scale of y-axis. Is passed to Matplotlib set_yscale, so any valid argument (“linear”, “log”, etc.) works Default: “linear”
condensed (bool) – Only show maximum y-axis tick. Default: False
n_yticks (int) – Number of y-axis ticks. If only the maximum tick should be displayed set condensed to True. Default: 3
n_ticks (int) – Number of major x-axis genome coordinate ticks
n_minor_ticks (int) – Number of minor ticks per major tick
title (str) – Title drawn on top of the figure panel.
aspect (float) – Aspect ratio of the plot, height/width. So 0.5 means half as high as wide. Default: Plot type specific sensible value
axes_style – Set styling of the axes, can be anything that seaborn supports. See http://seaborn.pydata.org/tutorial/aesthetics.html#styling-figures-with-axes-style-and-set-style
ylabel (str) – Label for y-axis. Default: None
draw_ticks (bool) – Draw tickmarks. Default: True
draw_major_ticks (bool) – Draw major tickmarks. Default: True
draw_minor_ticks (bool) – Draw minor tickmarks. Default: True
draw_tick_labels (bool) – Draw tick labels. Default: True
draw_x_axis (bool) – If False, remove genome x-axis completely. Default: True
draw_tick_legend (bool) – Draw legend for the tick distances. Default: True
padding (float) – Padding in inches to the next plot. Default: None, automatically calculated.
extra_padding (float) – Add or subtract the specified inches from the automatically calculated padding from this panel to the next.
fix_chromosome (bool) – If True modify chromosome identifiers for this plot, removing or adding ‘chr’ as necessary. Default: False
invert_x (bool) – Invert x-axis. Default=False Caution: This only works reliably when
independent_x=True
in the GenomicFigure instance, since x-axis of all plots are linked otherwise.ax (Axes) – Matplotlib axes instance that the plot will be drawn on. Only necessary if you don’t intend to use a
GenomicFigure
to draw the plot. Default: None
-
-
class
fanc.plotting.
HighlightAnnotation
(bed, plot1=None, plot2=None, plot_kwargs=None, **kwargs)¶ Vertical lines or rectangles (shaded regions) which can be positioned at specific genomic coordinates from a BED file and can span multiple panels of the GenomicFigure.
Useful for highlighting specific regions across multiple panels of figures.
-
__init__
(bed, plot1=None, plot2=None, plot_kwargs=None, **kwargs)¶ - Parameters
bed (string or pybedtool.BedTool) – Anything pybedtools can parse. Path to BED-file GTF-file, or a list of tuples [(chr, start, end), …] If features are 1bp long, lines are drawn. If they are > 1bp rectangles are drawn. Their appearance can be controlled using the plot_kwargs.
plot1 – First plot where line should start. Default: First
plot2 – Second plot where line should end. Default: Last
plot_kwargs – Dictionary of properties which are passed to matplotlib.lines.Line2D or matplotlib.patches.Rectangle constructor
fix_chromosome (bool) – If True modify chromosome identifiers for this plot, removing or adding ‘chr’ as necessary. Default: False
-
-
class
fanc.plotting.
SymmetricNorm
(vmin=None, vmax=None, percentile=None)¶ Normalizes data for plotting on a divergent colormap. Automatically chooses vmin and vmax so that the colormap is centered at zero.
-
__init__
(vmin=None, vmax=None, percentile=None)¶ - Parameters
vmin – Choose vmin manually
vmax – Choose vmax manually
percentile – Instead of taking the minmum or maximum to automatically determine vmin/vmax, take the percentile. eg. with 5, vmin is 5%-ile, vmax 95%-ile
-
autoscale
(A)¶ Set vmin, vmax to min, max of A.
-
autoscale_None
(A)¶ If vmin or vmax are not set, use the min/max of A to set them.
-
-
class
fanc.plotting.
LimitGroup
(limit=None, sig=2)¶ Can be used for synchronizing axis limits across multiple plots. Pass the same instance of this class to all plots that should have synchronized axis limits.
-
__init__
(limit=None, sig=2)¶ - Parameters
limit – tuple (vmin, vmax) to set absolute limits for axis. Final limits will be chosen within this absolute limit. Pass None for vmin or vmax to set no limit. Default: (None, None)
sig – Round limits to sig significant digits. If None, don’t round. Default: 2
-
-
class
fanc.plotting.
MirrorMatrixPlot
(top_plot, bottom_plot, gap=0, cax_gap=0.05, **kwargs)¶ Stack two plots on top of each other, bottom plot inverted. Especially suited to stacking two Hic plots (triangles) on top of each other.
-
__init__
(top_plot, bottom_plot, gap=0, cax_gap=0.05, **kwargs)¶ - Parameters
top_plot – Plot instance on top
bottom_plot – Plot instance on bottom
gap – Gap between plots in inches
cax_gap – Gap between colorbars in inches
n_ticks (int) – Number of major x-axis genome coordinate ticks
n_minor_ticks (int) – Number of minor ticks per major tick
title (str) – Title drawn on top of the figure panel.
aspect (float) – Aspect ratio of the plot, height/width. So 0.5 means half as high as wide. Default: Plot type specific sensible value
axes_style – Set styling of the axes, can be anything that seaborn supports. See http://seaborn.pydata.org/tutorial/aesthetics.html#styling-figures-with-axes-style-and-set-style
ylabel (str) – Label for y-axis. Default: None
draw_ticks (bool) – Draw tickmarks. Default: True
draw_major_ticks (bool) – Draw major tickmarks. Default: True
draw_minor_ticks (bool) – Draw minor tickmarks. Default: True
draw_tick_labels (bool) – Draw tick labels. Default: True
draw_x_axis (bool) – If False, remove genome x-axis completely. Default: True
draw_tick_legend (bool) – Draw legend for the tick distances. Default: True
padding (float) – Padding in inches to the next plot. Default: None, automatically calculated.
extra_padding (float) – Add or subtract the specified inches from the automatically calculated padding from this panel to the next.
fix_chromosome (bool) – If True modify chromosome identifiers for this plot, removing or adding ‘chr’ as necessary. Default: False
invert_x (bool) – Invert x-axis. Default=False Caution: This only works reliably when
independent_x=True
in the GenomicFigure instance, since x-axis of all plots are linked otherwise.ax (Axes) – Matplotlib axes instance that the plot will be drawn on. Only necessary if you don’t intend to use a
GenomicFigure
to draw the plot. Default: None
-
-
fanc.plotting.
distance_decay_plot
(*matrices, ax=None, chromosome=None, labels=None, tight=True, norm=True, **kwargs)¶ An distance decay (expected values) plot.
- Parameters
matrices – Hi-C objects to be plotted
ax – Optional matplotlib ax object for the plot. If not specified, will use
plt.gca()
chromosome – Optional, but recommended for the default chromosome-normalised matrices. The name of a chromosome to plot
labels – Optional labels when providing multiple objects. Will replace default labels in the legend. Must be the same number as matrix objects
tight – If True, uses tight figure layout. Disable for grid-based plotting.
kwargs – Parameters passed on to
ax.plot
- Returns
ax
-
fanc.plotting.
pca_plot
(pca_res, variance=None, eigenvectors=(0, 1), markers=None, colors=None, names=None, ax=None)¶ Plot the results of a Hi-C PCA analysis from
hic_pca()
.- Parameters
pca_res – The PCA result from
hic_pca()
variance – A vector specifying the explained variance of each EV in the PCA or the PCA object from
hic_pca()
. Optional, used to display the explained variance along the axes.eigenvectors – Tuple of length two specifying which eigenvectors (EVs) to plot. 0-based, (0, 1) by default for the first to EVs.
markers – List of marker definitions from matplotlib (e.g. [“o”, “*”, “s”]). Must be same length as number of samples in PCA.
colors – List of colour definitions from matplotlib. Must be same length as number of samples in PCA.
names – Sample names for plot legend. Must be same length as number of samples in PCA.
ax – Optional matplotlib axes object to plot into. Otherwise uses
plt.gca()
- Returns
figure, ax