pybedtools.contrib.plotting.Track

class pybedtools.contrib.plotting.Track(features, chrom=None, ybase=0, yheight=1, visibility='dense', stranded=True, **kwargs)[source]
__init__(features, chrom=None, ybase=0, yheight=1, visibility='dense', stranded=True, **kwargs)[source]

Subclass of matplotlib’s PolyCollection that can be added to an Axes.

Parameters:
  • features – Can be an existing BedTool, or anything than can be used to create a BedTool (e.g., a filename or a generator of Interval objects)
  • ybase – y-coord of the bottom edge of the track (in data coordinates)
  • yheight – How high each feature will be, in data coordinates
  • visibility

    Mimics the settings in the UCSC Genome Browser:

    • ”dense” is the default; overlapping features can be seen if you set alpha < 1.
    • ”squish” prevents adjacent features from overlapping. This keeps yheight for all features, so if you have a lot of features piling up, the track will be a lot higher on the y-axis than yheight.
  • stranded

    If boolean and True, will draw arrrow-shaped features to indicate direction (where the point is 10% of the total gene length)

    If a dictionary, map strands to colors, e.g., {‘+’: ‘r’, ‘-‘: ‘b’}.

  • kwargs – Additional keyword args are passed to matplotlib.collections.PolyCollection.

Notes:

After creating a track, use the ymax attribute to get the max y-value used in the track – useful if you’ve created a “squish” track but would like to stack another track on top, and need to calculate what the new Track’s ybase should be.

The returned PolyCollection will have the features attribute, which contains the BedTool it was created from – so you can write callback functions for event handling, e.g.:

def callback(event):
    '''
    prints the feature's line when clicked in the plot
    '''
    coll = event.artist
    for i in event.ind:
        print coll.features[i]

fig.canvas.mpl_connect('on_pick', callback)
>>> a = pybedtools.example_bedtool('a.bed')
>>> track = pybedtools.contrib.plotting.Track(a, alpha=0.5, picker=5)
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> ax.add_collection(track) 
<pybedtools.contrib.plotting.Track object at 0x...>
>>> limits = ax.axis('tight')

Methods

__init__(features[, chrom, ybase, yheight, …]) Subclass of matplotlib’s PolyCollection that can be added to an Axes.
add_callback(func) Adds a callback function that will be called whenever one of the Artist’s properties changes.
add_checker(checker) Add an entry to a dictionary of boolean flags that are set to True when the mappable is changed.
autoscale() Autoscale the scalar limits on the norm instance using the current array
autoscale_None() Autoscale the scalar limits on the norm instance using the current array, changing only limits that are None
changed() Call this whenever the mappable is changed to notify all the callbackSM listeners to the ‘changed’ signal
check_update(checker) If mappable has changed since the last check, return True; else return False
contains(mouseevent) Test whether the mouse event occurred in the collection.
convert_xunits(x) For artists in an axes, if the xaxis has units support, convert x using xaxis unit type
convert_yunits(y) For artists in an axes, if the yaxis has units support, convert y using yaxis unit type
draw(renderer) Derived classes drawing method
findobj([match, include_self]) Find artist objects.
format_cursor_data(data) Return cursor data string formatted.
get_agg_filter() Return filter function to be used for agg filter.
get_alpha() Return the alpha value used for blending - not supported on all backends
get_animated() Return the artist’s animated state
get_array() Return the array
get_capstyle()
get_children() Return a list of the child Artist`s this :class:`Artist contains.
get_clim() return the min, max of the color limits for image scaling
get_clip_box() Return artist clipbox
get_clip_on() Return whether artist uses clipping
get_clip_path() Return artist clip path
get_cmap() return the colormap
get_contains() Return the _contains test used by the artist, or None for default.
get_cursor_data(event) Get the cursor data for a given event.
get_dashes(*args, **kwargs) alias for get_linestyle
get_datalim(transData)
get_edgecolor()
get_edgecolors(*args, **kwargs) alias for get_edgecolor
get_facecolor()
get_facecolors(*args, **kwargs) alias for get_facecolor
get_figure() Return the .Figure instance the artist belongs to.
get_fill() return whether fill is set
get_gid() Returns the group id.
get_hatch() Return the current hatching pattern.
get_in_layout() Return boolean flag, True if artist is included in layout calculations.
get_joinstyle()
get_label() Get the label used for this artist in the legend.
get_linestyle()
get_linestyles(*args, **kwargs) alias for get_linestyle
get_linewidth()
get_linewidths(*args, **kwargs) alias for get_linewidth
get_lw(*args, **kwargs) alias for get_linewidth
get_offset_position() Returns how offsets are applied for the collection.
get_offset_transform()
get_offsets() Return the offsets for the collection.
get_path_effects()
get_paths()
get_picker() Return the picker object used by this artist.
get_pickradius()
get_rasterized() Return whether the artist is to be rasterized.
get_sizes() Returns the sizes of the elements in the collection.
get_sketch_params() Returns the sketch parameters for the artist.
get_snap() Returns the snap setting which may be:
get_tightbbox(renderer) Like Artist.get_window_extent, but includes any clipping.
get_transform() Return the Transform instance used by this artist.
get_transformed_clip_path_and_affine() Return the clip path with the non-affine part of its transformation applied, and the remaining affine part of its transformation.
get_transforms()
get_url() Returns the url.
get_urls()
get_visible() Return the artist’s visiblity
get_window_extent(renderer) Get the axes bounding box in display space.
get_xlims(ax) Needs ax to convert to transData coords
get_zorder() Return the artist’s zorder.
have_units() Return True if units are set on the x or y axes
hitlist(event)

Deprecated since version 2.2.

is_figure_set()

Deprecated since version 2.2.

is_transform_set() Returns True if Artist has a transform explicitly set.
pchanged() Fire an event when property changed, calling all of the registered callbacks.
pick(mouseevent) Process pick event
pickable() Return True if Artist is pickable.
properties() return a dictionary mapping property name -> value for all Artist props
remove() Remove the artist from the figure if possible.
remove_callback(oid) Remove a callback based on its id.
set(**kwargs) A property batch setter.
set_agg_filter(filter_func) Set the agg filter.
set_alpha(alpha) Set the alpha tranparencies of the collection.
set_animated(b) Set the artist’s animation state.
set_antialiased(aa) Set the antialiasing state for rendering.
set_antialiaseds(*args, **kwargs) alias for set_antialiased
set_array(A) Set the image array from numpy array A.
set_capstyle(cs) Set the capstyle for the collection.
set_clim([vmin, vmax]) set the norm limits for image scaling; if vmin is a length2 sequence, interpret it as (vmin, vmax) which is used to support setp
set_clip_box(clipbox) Set the artist’s clip .Bbox.
set_clip_on(b) Set whether artist uses clipping.
set_clip_path(path[, transform]) Set the artist’s clip path, which may be:
set_cmap(cmap) set the colormap for luminance data
set_color(c) Set both the edgecolor and the facecolor.
set_contains(picker) Replace the contains test used by this artist.
set_dashes(*args, **kwargs) alias for set_linestyle
set_edgecolor(c) Set the edgecolor(s) of the collection.
set_edgecolors(*args, **kwargs) alias for set_edgecolor
set_facecolor(c) Set the facecolor(s) of the collection.
set_facecolors(*args, **kwargs) alias for set_facecolor
set_figure(fig) Set the .Figure instance the artist belongs to.
set_gid(gid) Sets the (group) id for the artist.
set_hatch(hatch) Set the hatching pattern
set_in_layout(in_layout) Set if artist is to be included in layout calculations, E.g.
set_joinstyle(js) Set the joinstyle for the collection.
set_label(s) Set the label to s for auto legend.
set_linestyle(ls) Set the linestyle(s) for the collection.
set_linestyles(*args, **kwargs) alias for set_linestyle
set_linewidth(lw) Set the linewidth(s) for the collection.
set_linewidths(*args, **kwargs) alias for set_linewidth
set_lw(*args, **kwargs) alias for set_linewidth
set_norm(norm) Set the normalization instance.
set_offset_position(offset_position) Set how offsets are applied.
set_offsets(offsets) Set the offsets for the collection.
set_path_effects(path_effects) Set the path effects.
set_paths(verts[, closed]) This allows one to delay initialization of the vertices.
set_picker(picker) Set the epsilon for picking used by this artist
set_pickradius(pr) Set the pick radius used for containment tests.
set_rasterized(rasterized) Force rasterized (bitmap) drawing in vector backend output.
set_sizes(sizes[, dpi]) Set the sizes of each member of the collection.
set_sketch_params([scale, length, randomness]) Sets the sketch parameters.
set_snap(snap) Sets the snap setting which may be:
set_transform(t) Set the artist transform.
set_url(url) Sets the url for the artist.
set_urls(urls)
Parameters:
set_verts(verts[, closed]) This allows one to delay initialization of the vertices.
set_verts_and_codes(verts, codes) This allows one to initialize vertices with path codes.
set_visible(b) Set the artist’s visibility.
set_zorder(level) Set the zorder for the artist.
to_rgba(x[, alpha, bytes, norm]) Return a normalized rgba array corresponding to x.
update(props) Update this artist’s properties from the dictionary prop.
update_from(other) copy properties from other to self
update_scalarmappable() If the scalar mappable array is not none, update colors from scalar data

Attributes

aname
axes The Axes instance the artist resides in, or None.
midpoint
mouseover
stale If the artist is ‘stale’ and needs to be re-drawn for the output to match the internal state of the artist.
sticky_edges x and y sticky edge lists.
zorder