pybedtools.bedtool.BedTool.complement

BedTool.complement(*args, **kwargs)[source]

Wraps bedtools complement. Example usage:

>>> a = pybedtools.example_bedtool('a.bed')
>>> a.complement(genome='hg19').head(5) 
chr1    0       1
chr1    500     900
chr1    950     249250621
chr2    0       243199373
chr3    0       198022430

For convenience, the file or stream this BedTool points to is implicitly passed as the -i argument to complementBed

There are two alternatives for supplying a genome. Use g="genome.filename" if you have a genome’s chrom sizes saved as a file. This is the what BEDTools expects when using it from the command line. Alternatively, use the genome="assembly.name" (for example, genome="hg19") to use chrom sizes for that assembly without having to manage a separate file. The genome argument triggers a call pybedtools.chromsizes, so see that method for more details.

Original BEDTools help::

Tool:    bedtools complement (aka complementBed)
Version: v2.31.1
Summary: Returns the base pair complement of a feature file.

Usage:   bedtools complement [OPTIONS] -i <bed/gff/vcf> -g <genome>

Options: 
        -L      Limit output to solely the chromosomes with records in the input file.

Notes: 
        (1)  The genome file should tab delimited and structured as follows:
             <chromName><TAB><chromSize>

        For example, Human (hg19):
        chr1    249250621
        chr2    243199373
        ...
        chr18**gl000207**random 4262

Tip 1. Use samtools faidx to create a genome file from a FASTA: 
        One can the samtools faidx command to index a FASTA file.
        The resulting .fai index is suitable as a genome file, 
        as bedtools will only look at the first two, relevant columns
        of the .fai file.

        For example:
        samtools faidx GRCh38.fa
        bedtools complement -i my.bed -g GRCh38.fa.fai

Tip 2. Use UCSC Table Browser to create a genome file: 
        One can use the UCSC Genome Browser's MySQL database to extract
        chromosome sizes. For example, H. sapiens:

        mysql --user=genome --host=genome-mysql.cse.ucsc.edu -A -e \
        "select chrom, size from hg19.chromInfo"  > hg19.genome