Need help with pybedtools?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

daler
218 Stars 83 Forks Other 1.7K Commits 14 Opened issues

Description

Python wrapper -- and more -- for Aaron Quinlan's BEDTools (bioinformatics tools)

Services available

!
?

Need anything else?

Contributors list

# 80,952
Shell
C
conda
Perl
1397 commits
# 81,124
Nim
vcf
Shell
nim-lan...
84 commits
# 64,918
HTML
R
cran
Homebre...
12 commits
# 604,538
TeX
C++
Shell
10 commits
# 410,002
R
Shell
MATLAB
lesson
6 commits
# 249,448
Shell
genome-...
Amazon ...
cython
5 commits
# 302,320
Shell
C++
HTML
5 commits
# 381,106
C++
Shell
TeX
google-...
4 commits
# 190,251
Markdow...
genome
Shell
conda
3 commits
# 536,665
Emacs
colorsc...
doom-em...
C++
3 commits
# 730,478
C++
Shell
HTML
3 commits
# 300,368
C
Shell
C++
phyloge...
2 commits
# 112,733
gsoc
Jekyll
jupyter
R
2 commits
# 237,028
C++
Shell
TeX
surviva...
2 commits
# 30,522
R
Flask
gui-fra...
jupyter
1 commit
# 767,659
C++
Shell
HTML
1 commit
# 743,776
C++
Shell
C
1 commit
# 98,372
debian
nix
data-va...
Bootstr...
1 commit
# 293,359
HTML
Shell
C++
Docker
1 commit
# 74,811
C++
R
Qt
Linux
1 commit

Overview

.. image:: https://travis-ci.org/daler/pybedtools.png?branch=master :target: https://travis-ci.org/daler/pybedtools

.. image:: https://badge.fury.io/py/pybedtools.svg?style=flat :target: http://badge.fury.io/py/pybedtools

.. image:: https://img.shields.io/badge/install%20with-bioconda-brightgreen.svg :target: http://bioconda.github.io

The

BEDTools suite of programs 
_ is widely used for genomic interval manipulation or "genome algebra".
pybedtools
wraps and extends BEDTools and offers feature-level manipulations from within Python.

See full online documentation, including installation instructions, at http://daler.github.io/pybedtools/.

Why
pybedtools
?

Here is an example to get the names of genes that are <5 kb away from intergenic SNPs:

.. code-block:: python

from pybedtools import BedTool

snps = BedTool('snps.bed.gz') # [1] genes = BedTool('hg19.gff') # [1]

intergenic_snps = snps.subtract(genes) # [2] nearby = genes.closest(intergenic_snps, d=True, stream=True) # [2, 3]

for gene in nearby: # [4] if int(gene[-1]) < 5000: # [4] print gene.name # [4]

Useful features shown here include:

  • [1]
    support for all BEDTools-supported formats (here gzipped BED and GFF)
  • [2]
    wrapping of all BEDTools programs and arguments (here,
    subtract
    and
    closest
    and passing the
    -d
    flag to
    closest
    );
  • [3]
    streaming results (like Unix pipes, here specified by
    stream=True
    )
  • [4]
    iterating over results while accessing feature data by index or by attribute access (here
    [-1]
    and
    .name
    ).

In contrast, here is the same analysis using shell scripting. Note that this requires knowledge in Perl, bash, and awk. The run time is identical to the

pybedtools
version above:

.. code-block:: bash

snps=snps.bed.gz
genes=hg19.gff
intergenic_snps=/tmp/intergenic_snps

snp_fields=zcat $snps | awk '(NR == 2){print NF; exit;}' gene_fields=9 distance_field=$(($gene_fields + $snp_fields + 1))

intersectBed -a $snps -b $genes -v > $intergenic_snps

closestBed -a $genes -b $intergenic_snps -d
| awk '($'$distance_field' < 5000){print $9;}'
| perl -ne 'm/[ID|Name|gene_id]=(.*?);/; print "$1\n"'

rm $intergenic_snps

See the

Shell script comparison 
_ in the docs for more details on this comparison, or keep reading the full documentation at http://daler.github.io/pybedtools.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.