pybedtools
Reference¶
The following tables summarize the methods and functions; click on a method or function name to see the complete documentation.
BedTool
creation¶
The main BedTool
documentation, with a list of all methods in
alphabetical order at the bottom. For more details, please see Creating a BedTool.
|
BEDTools
wrappers¶
These methods wrap BEDTools
programs for easy use with Python; you can then
use the other pybedtools
functionality for further manipulation and
analysis.
The documentation of each of these methods starts with
pybedtools
-specific documentation, possibly followed by an example.
Finally, the BEDTools
help is copied verbatim from whatever version was
installed when generating these docs.
In general the BEDTool
wrapper methods adhere to the Design principles:
|
Wraps |
|
Wraps |
|
Wraps |
|
Wraps |
|
Wraps |
Wraps |
|
|
Wraps |
|
Wraps |
|
Wraps |
|
Wraps |
|
Wraps |
|
Wraps |
|
Wraps |
|
Wraps |
|
Wraps |
|
Wraps |
Wraps |
|
Wraps |
|
Wraps |
|
Wraps |
|
|
Wraps |
|
Wraps |
Wraps |
|
|
Wraps |
Wraps |
|
|
Wraps |
|
Wraps |
Wraps |
|
Wraps |
|
|
Wraps |
|
Returns a dictionary with keys (intersection, union, jaccard). |
|
If detail=False, then return a dictionary with keys (reldist, count, |
|
Wraps |
|
Wraps |
|
Wraps |
Wraps |
|
|
Wraps |
|
Wraps |
Other BedTool
methods¶
These methods are some of the ways in which pybedtools
extend the
BEDTools suite.
Feature-by-feature operations¶
Methods that operate on a feature-by-feature basis to modify or filter features on the fly.
|
Modify each feature with a user-defined function. |
|
Filter features by user-defined function. |
|
Split each feature using a user-defined function. |
Ensure all features fall within chromosome limits. |
|
Remove invalid features that may break BEDTools programs. |
The pybedtools.featurefuncs
module contains some commonly-used functions
that can be passed to BedTool.each()
:
|
Returns the 3'-most coordinate, plus |
|
Returns the 5'-most coordinate, plus |
|
Alias for five_prime. |
|
Pads the fields of the feature with "." to a total length of |
|
Return the width bp from the center of a feature. |
|
Specialized version of |
Normalizes the value at feature[idx] to the feature's length, in kb. |
|
|
Forces a rename of all features, e.g., for renaming everything in a file 'exon' |
|
Return True if feature length > size |
|
Return True if feature length < size |
Normalizes the value at feature[idx] to the feature's length, in kb. |
|
|
Forces a rename of all features, e.g., for renaming everything in a file 'exon' |
|
Signature: |
|
Signature: |
|
Signature: |
Searching for features¶
These methods take a single interval as input and return the intervals of the BedTool that overlap.
This can be useful when searching across many BED files for a particular coordinate range – for example, they can be used identify all binding sites, stored in many different BED files, that fall within a gene’s coordinates.
|
Return all intervals that overlap |
|
Return whether or not any intervals overlap |
|
Return the number of intervals that overlap |
Retrieve all intervals within coordinates from a "tabixed" BedTool. |
|
|
Prepare a BedTool for use with Tabix. |
|
Helper function for more control over "tabixed" BedTools. |
BedTool
introspection¶
These methods provide information on the BedTool
object.
If using BedTool.head()
, don’t forget that you can index into
BedTool
objects, too.
|
Prints the first n lines or returns them if as_string is True |
Count the number features in this BedTool. |
|
Number of fields in each line of this BedTool (checks |
|
Return the type of the current file. |
Randomization helpers¶
Helper methods useful for assessing empirical instersection distributions between interval files.
Generalized method for applying a function in parallel. |
|
Dictionary of results from many randomly shuffled intersections. |
|
Perform |
|
Like randomintersection, but return the bp overlap instead of the number of intersecting intervals. |
|
Return a BedTool containing a random subset. |
|
Computes the naive Jaccard statistic (intersection divided by union). |
|
|
For backwards compatibility; see BedTool.parallel_apply instead. |
Managing BedTool
objects on disk¶
These methods are used to specify where to save results from BedTool
operations.
|
Make a copy of the BedTool. |
|
Move to a new filename (can be much quicker than BedTool.saveas()) |
Misc operations¶
Methods that can’t quite be categorized into the above sections.
|
Concatenate interval files together. |
Returns a new BedTool with only intervals at lines |
|
Returns an iterator of the absolute distances between features in self and other. |
|
|
Analagous to unix |
Return the total number of bases covered by this interval file. |
|
|
Helper method for adding attributes in the middle of a pipeline. |
Returns an IntervalFile of this BedTool for low-level interface. |
|
|
Create intron features (requires specific input format). |
Prepare BedTool for operations that require chromosome coords. |
|
Print the sequence that was retrieved by BedTool.sequence. |
|
Save sequences, after calling BedTool.sequence. |
|
|
Return just the sequence from a region string or a single location >>> fn = pybedtools.example_filename('test.fa') >>> BedTool.seq('chr1:2-10', fn) 'GATGAGTCT' >>> BedTool.seq(('chr1', 1, 10), fn) 'GATGAGTCT' |
|
Returns a new BedTool of the liftedOver features, saving the unmapped ones as |
Returns a normalization instance for use by featurefuncs.add_color(). |
|
Returns an iterator of relative distances between features in self and other. |
Module-level functions¶
Working with example files¶
pybedtools
comes with many example files. Here are some useful
functions for accessing them.
Return a bedtool using a bed file from the pybedtools examples directory. |
|
Returns a list of files in the examples dir. |
|
Return a bed file from the pybedtools examples directory. |
Creating Interval
objects from scratch¶
Interval
objects are the core object in pybedtools
to represent
a genomic interval, written in Cython for speed.
Class to represent a genomic interval. |
|
Create an Interval object from a list of strings. |
pybedtools
setup and config¶
Use these functions right after importing in order to use custom paths or to clean up the temp directory.
Explicitly set path to |
|
Gets the current tempdir for the module. |
|
|
Set the directory for temp files. |
|
Deletes all temp files from the current session (or optionally all sessions) |
Enable debug mode. |
Working with “chromsizes” or assembly coordinate files¶
Many BEDTools
programs need “genome files” or “chromsizes” files so as to
remain within the coordinates of the assembly you’re working on. These
functions help manage these files.
Download chrom size info for genome from UCSC and returns the dictionary. |
|
|
Looks for a genome already included in the genome registry; if not found it first tries to look it up via genomepy. |
|
Converts a chromsizes dictionary to a file. |
Performing operations in parallel (multiprocessing)¶
|
Call an arbitrary BedTool method many times in parallel. |
pybedtools.contrib
¶
The pybedtools.contrib
module contains higher-level code that leverages
BedTool
objects for common analyses.
Plotting¶
Plotting results from BEDTools/pybedtools operations is very useful for exploring and understanding the tools as well as for teaching purposes.
|
|
Plots a "binary heatmap", showing the results of a multi-intersection. |
|
Convenience function useful printing the results from binary_heatmap(). |
|
Working with bigWig files¶
At this time, pybedtools
does not support reading bigWig files, only
creating them via UCSC utilities.
|
Given a BAM file |
|
Working with bigBed files¶
|
Converts a BedTool object to a bigBed format and returns the new filename. |
IntersectionMatrix
¶
The IntersectionMatrix
class makes it easy to intersect a large number
of interval files with each other.
|
Class to handle many pairwise comparisons of interval files |
contrib.venn_maker
¶
The venn_maker
module helps you make Venn diagrams using the R package
VennDiagram.
Note that Venn diagrams are not good for when you have nested intersections.
See the docs for pybedtools.contrib.venn_maker.cleaned_intersect()
and
its source for more details.
Interface between pybedtools and the R package VennDiagram. |
|
Given a list of interval files, write an R script to create a Venn diagram of overlaps (and optionally run it). |
|
Perform interval intersections such that the end products have identical features for overlapping intervals. |
contrib.long_range_interaction
¶
Tag each end of a BEDPE with a set of (possibly many) query BED files. |
|
|
Converts the output from |