### Install Bedtools using Apt-Get (Debian/Ubuntu) Source: https://bedtools.readthedocs.io/en/latest/_sources/content/installation This command installs the Bedtools package using the 'apt-get' package manager, prevalent in Debian, Ubuntu, and their derivatives. Administrator privileges may be required. ```bash apt-get install bedtools ``` -------------------------------- ### Install Bedtools Binary on Linux Source: https://bedtools.readthedocs.io/en/latest/_sources/content/installation This snippet demonstrates how to download and make executable a pre-compiled static binary of Bedtools on Linux systems. It assumes the user has wget or curl available and read access to the GitHub releases page. ```bash mv bedtools.static.binary bedtools chmod a+x bedtools ``` -------------------------------- ### Compile Bedtools from Source (GitHub) Source: https://bedtools.readthedocs.io/en/latest/content/installation Instructions for downloading the bedtools source code from GitHub, extracting it, and compiling it using `make`. This method is intended for UNIX or OS X and requires the GCC compiler. The compiled binaries will be available in the `./bin/` directory. ```bash $ wget https://github.com/arq5x/bedtools2/releases/download/v2.29.1/bedtools-2.29.1.tar.gz $ tar -zxvf bedtools-2.29.1.tar.gz $ cd bedtools2 $ make ``` -------------------------------- ### Install Bedtools using Homebrew (OSX) Source: https://bedtools.readthedocs.io/en/latest/_sources/content/installation This sequence of commands installs Bedtools on macOS using the Homebrew package manager. It first taps the 'science' repository and then installs the bedtools package. Administrator privileges are typically not required for user-level installations. ```bash brew tap homebrew/science brew install bedtools ``` -------------------------------- ### Install bedtools using curl and make Source: https://bedtools.readthedocs.io/en/latest/_sources/content/quick-start This snippet shows how to download, extract, compile, and install bedtools from a tarball using curl and the make command. It assumes you have the necessary build tools installed. ```bash curl http://bedtools.googlecode.com/files/BEDTools..tar.gz > BEDTools.tar.gz tar -zxvf BEDTools.tar.gz cd BEDTools make sudo cp bin/* /usr/local/bin/ ``` -------------------------------- ### Sorting BED File Example Source: https://bedtools.readthedocs.io/en/latest/_sources/content/tools/fisher An example of how to sort a BED file by start position, which is a common preprocessing step for genomic interval analysis tools like bedtools. ```bash sort -k1,1 -k2,2n in.bed > in.sorted.bed ``` -------------------------------- ### Compile Bedtools from Source via GitHub Source: https://bedtools.readthedocs.io/en/latest/_sources/content/installation This code block shows the steps to download, extract, and compile Bedtools from its source code available on GitHub. It requires wget for downloading the tarball, tar for extraction, and make for compilation. The GCC compiler is assumed to be available. ```bash wget https://github.com/arq5x/bedtools2/releases/download/v2.29.1/bedtools-2.29.1.tar.gz tar -zxvf bedtools-2.29.1.tar.gz cd bedtools2 make ``` -------------------------------- ### Install Bedtools using MacPorts (OSX) Source: https://bedtools.readthedocs.io/en/latest/_sources/content/installation This command installs Bedtools on macOS using the MacPorts package management system. Administrator privileges may be required. ```bash port install bedtools ``` -------------------------------- ### Install Bedtools using Yum (Fedora/CentOS) Source: https://bedtools.readthedocs.io/en/latest/_sources/content/installation This command installs the Bedtools package using the 'yum' package manager, commonly found on Fedora, CentOS, and related Linux distributions. Administrator privileges may be required. ```bash yum install BEDTools ``` -------------------------------- ### Clone Bedtools Development Version from GitHub Source: https://bedtools.readthedocs.io/en/latest/_sources/content/installation This command clones the Bedtools development repository from GitHub using Git. This allows users to access the latest bug fixes and features before they are officially released. The cloned repository can then be compiled using the source compilation instructions. ```bash git clone https://github.com/arq5x/bedtools2.git ``` -------------------------------- ### GFF File Example Source: https://bedtools.readthedocs.io/en/latest/content/general-usage An example entry demonstrating the required nine columns for the GFF file format, including seqname, source, feature, start, end, score, strand, frame, and attribute. ```gff seq1 blASTX similarity 101 235 87.1 + 0 Target "HBA_HUMAN" 11 55 ; E_value 0.0003 dJ102G20 GD_mRNA coding_exon 7105 7201 . - 2 Sequence "dJ102G20.C1.1" ``` -------------------------------- ### bedtools closest Usage Example Source: https://bedtools.readthedocs.io/en/latest/_sources/content/tools/closest This example demonstrates the basic command structure for bedtools closest, specifying input files for the query (-a) and database (-b) features. It's crucial that both input files are presorted by chromosome and start position for correct operation. ```bash bedtools closest [OPTIONS] -a \ -b ``` ```bash closestBed [OPTIONS] -a \ -b ``` -------------------------------- ### BEDTools overlap example with windowBed Source: https://bedtools.readthedocs.io/en/latest/content/tools/overlap This example demonstrates piping the output of 'bedtools window' into the 'overlap' command. It specifies the relevant columns for start and end coordinates from the piped input to calculate overlap or distance. ```bash bedtools window -a A.bed -b B.bed -w 10 | overlap -i stdin -cols 2,3,6,7 chr1 10 20 A chr1 15 25 B 5 chr1 10 20 C chr1 25 35 D -5 ``` -------------------------------- ### BEDTools Main Command Usage Source: https://bedtools.readthedocs.io/en/latest/_sources/content/bedtools-suite Demonstrates the general syntax for invoking BEDTools sub-commands. Requires BEDTools to be installed and in the system's PATH. ```bash bedtools [sub-command] [options] ``` -------------------------------- ### Install zlib Development Libraries on Ubuntu Source: https://bedtools.readthedocs.io/en/latest/_sources/content/faq These commands are used to install the zlib development libraries on Ubuntu systems, which are required for compiling tools like bedtools that depend on zlib functionality. Ensure you have sudo privileges to run these commands. ```bash sudo apt-get install zlib1g-dev sudo apt-get install zlib ``` -------------------------------- ### linksBed Usage Example Source: https://bedtools.readthedocs.io/en/latest/_sources/content/tools/links Demonstrates the basic usage of linksBed to create an HTML file from a BED/GFF/VCF input file. The output is redirected to an HTML file for viewing in a web browser. ```bash linksBed -i genes.bed > genes.html ``` -------------------------------- ### BED file format example Source: https://bedtools.readthedocs.io/en/latest/content/overview Illustrates a single basepair feature in BED format. BED format uses 0-based start and 1-based end coordinates. ```plaintext chr1 0 1 first_base ``` -------------------------------- ### bed12ToBed6 Input and Output Example Source: https://bedtools.readthedocs.io/en/latest/content/tools/bed12tobed6 Illustrates the transformation of BED12 data to BED6 format using bed12ToBed6 with piped input. The example shows how a single BED12 entry with multiple blocks (exons) is converted into several distinct BED6 entries, each representing one block. ```bash head data/knownGene.hg18.chr21.bed | tail -n 3 | bed12ToBed6 -i stdin chr21 10079666 10080194 uc002yiv.1 0 - chr21 10081596 10081687 uc002yiv.1 0 - chr21 10119416 10119517 uc002yiv.1 0 - chr21 10120593 10120808 uc002yiv.1 0 - chr21 10080031 10080231 uc002yiw.1 0 - chr21 10081596 10081687 uc002yiw.1 0 - chr21 10081660 10081687 uc002yix.2 0 - chr21 10119416 10119517 uc002yix.2 0 - chr21 10120573 10120796 uc002yix.2 0 - ``` -------------------------------- ### bedtools multiinter -empty usage example Source: https://bedtools.readthedocs.io/en/latest/content/tools/multiinter Demonstrates the command-line usage of bedtools multiinter with the -header, -names, -empty, and -g options, including sample input files and the resulting output. ```bash $ bedtools multiinter -header -names A B C -i a.bed b.bed c.bed -empty -g sizes.txt ``` -------------------------------- ### Bedtools groupby: Default Behavior Example (Bash) Source: https://bedtools.readthedocs.io/en/latest/_sources/content/tools/groupby Illustrates the default behavior of bedtools groupby by showing how to prepare input data for analysis. The example uses a 'cat' command to display the contents of a hypothetical 'variants.bed' file, which would typically be pre-processed before being piped to bedtools groupby. ```bash cat variants.bed ``` -------------------------------- ### Bedmap Command Examples for Comparison Source: https://bedtools.readthedocs.io/en/latest/_sources/index Provides examples of using the 'bedmap' command for comparison with bedtools intersect. It shows commands both with and without the '--ec' option for error checking, illustrating different modes of operation. ```bash # bedmap (without error checking) $ bedmap --echo --count --bp-ovr 1 \ ccds.exons.bed aln.bam.bed ``` ```bash # bedmap (no error checking) $ bedmap --ec --echo --count --bp-ovr 1 \ ccds.exons.bed aln.bam.bed ``` -------------------------------- ### bedtools coverage with sorted input for memory efficiency Source: https://bedtools.readthedocs.io/en/latest/_sources/content/tools/coverage This example shows how to use the '-sorted' option when input files are presorted by chromosome and start position. This option invokes a memory-efficient algorithm suitable for processing very large files. ```bash sort -k1,1 -k2,2n input.bed > input.sorted.bed bedtools coverage -a input.sorted.bed -b others.bed -sorted ``` -------------------------------- ### BED5 Format Example Source: https://bedtools.readthedocs.io/en/latest/_sources/content/general-usage Example of a BED5 file format, which includes chromosome, start, end, name, and score for a genomic feature. ```plaintext chr1 11873 14409 uc001aaa.3 0 ``` -------------------------------- ### BED3 Format Example Source: https://bedtools.readthedocs.io/en/latest/content/general-usage Demonstrates the minimal BED file format (BED3) which requires only chromosome, start, and end positions. ```bed chr1 11873 14409 ``` -------------------------------- ### GFF File Example Source: https://bedtools.readthedocs.io/en/latest/_sources/content/general-usage An example entry from a GFF (General Feature Format) file, illustrating the structure for storing sequence annotation features. This format includes fields for sequence ID, source, type, start, end, score, strand, frame, and attributes. ```plaintext seq1 BLASTX similarity 101 235 87.1 + 0 Target "HBA_HUMAN" 11 55 ; E_value 0.0003 dJ102G20 GD_mRNA coding_exon 7105 7201 . - 2 Sequence "dJ102G20.C1.1" ``` -------------------------------- ### Genome File Format Example Source: https://bedtools.readthedocs.io/en/latest/content/general-usage An example of a tab-delimited genome file, listing chromosome names and their sizes in basepairs, used by bedtools for genomic coordinate calculations. ```genome chrI 15072421 chrII 15279323 ... chrX 17718854 chrM 13794 ``` -------------------------------- ### Example Input BED File Source: https://bedtools.readthedocs.io/en/latest/_sources/content/tools/links A sample input file in BED format, containing genomic interval information. This file is used as input for the linksBed tool. ```bed chr21 9928613 10012791 uc002yip.1 0 - chr21 9928613 10012791 uc002yiq.1 0 - chr21 9928613 10012791 uc002yir.1 0 - chr21 9928613 10012791 uc010gkv.1 0 - chr21 9928613 10061300 uc002yis.1 0 - chr21 10042683 10120796 uc002yit.1 0 - chr21 10042683 10120808 uc002yiu.1 0 - chr21 10079666 10120808 uc002yiv.1 0 - chr21 10080031 10081687 uc002yiw.1 0 - chr21 10081660 10120796 uc002yix.2 0 - ``` -------------------------------- ### Install zlib Development Libraries for Bedtools (Fedora/CentOS) Source: https://bedtools.readthedocs.io/en/latest/_sources/content/faq For Fedora or CentOS systems, install the 'zlib' and 'zlib1g-dev' packages using the yum package manager to address zlib-related compilation errors for Bedtools. These are essential for handling gzipped files. ```bash yum install zlib yum install zlib1g-dev ``` -------------------------------- ### BEDTools Intersect Example Source: https://bedtools.readthedocs.io/en/latest/content/bedtools-suite Provides a practical example of using the 'intersect' sub-command to find overlapping intervals between two BED files. This highlights a common use case for BEDTools. ```bash bedtools intersect -a a.bed -b b.bed ``` -------------------------------- ### bedtools flank Percentage Resizing Example (Shell) Source: https://bedtools.readthedocs.io/en/latest/content/tools/flank Shows how to use the -pct option with bedtools flank to create flanking intervals based on a fraction of the original interval's length. ```shell $ cat A.bed chr1 100 200 chr1 500 700 ################################################################ # note the flanking intervals from the second record in A.bed # are 20bp whereas the flanking intervals from the first record # are only 10bp ################################################################ $ bedtools flank -i A.bed -g my.genome -b 0.1 -pct chr1 90 100 chr1 200 210 chr1 480 500 chr1 700 720 ``` -------------------------------- ### bedtools maskfasta Soft-Masking Example Source: https://bedtools.readthedocs.io/en/latest/_sources/content/tools/maskfasta Illustrates how to use the '-soft' option with bedtools maskfasta to perform soft-masking, converting specified intervals to lower-case bases. ```bash $ cat test.fa >chr1 AAAAAAAACCCCCCCCCCCCCGCTACTGGGGGGGGGGGGGGGGGG $ cat test.bed chr1 5 10 $ bedtools maskfasta -fi test.fa -bed test.bed -fo test.fa.out -soft $ cat test.fa.out >chr1 AAAAAaaaccCCCCCCCCCCGCTACTGGGGGGGGGGGGGGGGGG ``` -------------------------------- ### Compute Coverage with bedtools coverage Source: https://bedtools.readthedocs.io/en/latest/_sources/content/example-usage Computes the coverage of aligned sequences on specified windows. It can output raw counts or percentages and can generate BEDGRAPH files for visualization. ```bash bedtools coverage -a reads.bed -b windows10kb.bed | head ``` ```bash bedtools coverage -a reads.bed -b windows10kb.bed | cut -f 1-4 > windows10kb.cov.bedg ``` ```bash bedtools coverage -a reads.bed -b windows10kb.bed | \ awk '{OFS="\t"; print $1,$2,$3,$6}' \ > windows10kb.pctcov.bedg ``` -------------------------------- ### Bedtools groupby: Summarize data by group (Bash Example) Source: https://bedtools.readthedocs.io/en/latest/_sources/content/tools/groupby This example demonstrates how to use bedtools groupby to summarize data. It requires the input file to be sorted by the grouping columns, specified with the -g option. The -c option specifies the column to summarize, and -o specifies the operation to perform. Input can be from a file or standard input. ```bash sort -k1,1 -k2,2 -k3,3 data.txt | bedtools groupby -g 1,2,3 -c 4 -o mean ``` -------------------------------- ### bedtools bamtobed: Convert BAM to BED format Source: https://bedtools.readthedocs.io/en/latest/content/example-usage This basic command converts a BAM file ('reads.bam') into BED format, writing the output to 'reads.bed'. ```bash bedtools bamtobed -i reads.bam > reads.bed ``` -------------------------------- ### bed12ToBed6 Usage Example Source: https://bedtools.readthedocs.io/en/latest/content/tools/bed12tobed6 Demonstrates the command-line usage of bed12ToBed6, specifying the input BED12 file or 'stdin' for piped data. This tool is designed to convert multi-part BED features into single-part BED features. ```bash bed12ToBed6 [OPTIONS] -i ``` -------------------------------- ### Find Complement Intervals with bedtools complement Source: https://bedtools.readthedocs.io/en/latest/_sources/content/example-usage Reports all intervals in a specified genome that are not covered by the input intervals. Requires an input interval file and a genome file. ```bash bedtools complement -i repeatMasker.bed -g hg18.genome ``` -------------------------------- ### bedtools jaccard Minimum Overlap Fraction (No Match) Example Source: https://bedtools.readthedocs.io/en/latest/content/tools/jaccard Demonstrates the effect of the -f option in bedtools jaccard when the minimum overlap fraction is not met. This example requires 60% overlap and shows the resulting output. ```bash cat a.bed chr1 10 20 chr1 30 40 cat b.bed chr1 15 20 bedtools jaccard -a a.bed -b b.bed -f 0.6 ``` -------------------------------- ### Genome File Format Example Source: https://bedtools.readthedocs.io/en/latest/_sources/content/general-usage An example of a tab-delimited Genome file format used by bedtools to specify chromosome names and their sizes in basepairs. This is crucial for operations that require knowledge of genome structure. ```plaintext chrI 15072421 chrII 15279323 ... chrX 17718854 chrM 13794 ``` -------------------------------- ### bedtools multicov Single BAM Example Source: https://bedtools.readthedocs.io/en/latest/content/tools/multicov Shows how `bedtools multicov` can be used with a single BAM file, demonstrating the output format with one count column per interval. ```bash $ bedtools multicov -bams aln1.bam -bed ivls-of-interest.bed chr1 0 10000 ivl1 100 chr1 10000 20000 ivl2 123 chr1 20000 30000 ivl3 213 chr1 30000 40000 ivl4 335 ``` -------------------------------- ### bedtools bamtobed: Convert BAM to BEDPE format Source: https://bedtools.readthedocs.io/en/latest/content/example-usage This command converts BAM alignments into BEDPE format, which represents paired-end reads, saving the output to 'reads.bedpe'. ```bash bedtools bamtobed -i reads.bam -bedpe > reads.bedpe ``` -------------------------------- ### Install zlib Development Libraries for Bedtools (Debian/Ubuntu) Source: https://bedtools.readthedocs.io/en/latest/_sources/content/faq To resolve zlib errors during Bedtools compilation on Debian or Ubuntu systems, install the 'zlib' and 'zlib1g-dev' packages using the apt-get package manager. These libraries are required for decompressing gzipped files. ```bash apt-get install zlib apt-get install zlib1g-dev ``` -------------------------------- ### bedtools maskfasta Default Behavior Example Source: https://bedtools.readthedocs.io/en/latest/_sources/content/tools/maskfasta Demonstrates the default hard-masking behavior of bedtools maskfasta, where specified intervals in the FASTA file are replaced with 'N's. ```bash $ cat test.fa >chr1 AAAAAAAACCCCCCCCCCCCCGCTACTGGGGGGGGGGGGGGGGGG $ cat test.bed chr1 5 10 $ bedtools maskfasta -fi test.fa -bed test.bed -fo test.fa.out $ cat test.fa.out >chr1 AAAAANNNNNCCCCCCCCCCGCTACTGGGGGGGGGGGGGGGGGG ``` -------------------------------- ### BEDPE Format Example Source: https://bedtools.readthedocs.io/en/latest/_sources/content/general-usage Illustrates a standard BEDPE file entry, which defines pairwise genomic features. ```plaintext chr1 100 200 chr5 5000 5100 bedpe_example1 30 + - chr9 1000 5000 chr9 3000 3800 bedpe_example2 100 + - ``` -------------------------------- ### bedtools multicov Default Behavior Example Source: https://bedtools.readthedocs.io/en/latest/content/tools/multicov Illustrates the default behavior of `bedtools multicov` by showing input BED file content and the corresponding output when counting overlaps from three BAM files. ```bash $ cat ivls-of-interest.bed chr1 0 10000 ivl1 chr1 10000 20000 ivl2 chr1 20000 30000 ivl3 chr1 30000 40000 ivl4 $ bedtools multicov -bams aln1.bam aln2.bam aln3.bam -bed ivls-of-interest.bed chr1 0 10000 ivl1 100 2234 0 chr1 10000 20000 ivl2 123 3245 1000 chr1 20000 30000 ivl3 213 2332 2034 chr1 30000 40000 ivl4 335 7654 0 ``` -------------------------------- ### BED3 Format Example Source: https://bedtools.readthedocs.io/en/latest/_sources/content/general-usage Example of a BED3 file format, which includes the chromosome, start, and end positions of a genomic feature. ```plaintext chr1 11873 14409 ``` -------------------------------- ### BEDPE Format with Custom Fields Example Source: https://bedtools.readthedocs.io/en/latest/_sources/content/general-usage Demonstrates a BEDPE file entry that includes additional user-defined fields for extra annotation. ```plaintext chr1 10 20 chr5 50 60 a1 30 + - 0 1 chr9 30 40 chr9 80 90 a2 100 + - 2 1 ``` -------------------------------- ### bedtools multicov Usage Example Source: https://bedtools.readthedocs.io/en/latest/content/tools/multicov Demonstrates the basic command-line usage of `bedtools multicov` to count overlapping alignments from multiple BAM files against a BED file. ```bash bedtools multicov [OPTIONS] -bams BAM1 BAM2 BAM3 ... BAMn -bed ``` ```bash multiBamCov [OPTIONS] -bams BAM1 BAM2 BAM3 ... BAMn -bed ``` -------------------------------- ### Display Bedtools Top-Level Help Menu Source: https://bedtools.readthedocs.io/en/latest/_sources/content/faq Access a high-level overview of available Bedtools sub-commands and their general usage by running the 'bedtools -h' command. This helps in navigating the various tools offered by Bedtools. ```bash $ bedtools -h bedtools: flexible tools for genome arithmetic and DNA sequence analysis. usage: bedtools [options] ... ``` -------------------------------- ### bedtools getfasta: Default FASTA output Source: https://bedtools.readthedocs.io/en/latest/content/tools/getfasta Demonstrates the default behavior of `bedtools getfasta` where sequences are extracted and output in FASTA format with headers like ':-'. ```bash cat test.fa >chr1 AAAAAAAACCCCCCCCCCCCCGCTACTGGGGGGGGGGGGGGGGGG cat test.bed chr1 5 10 bedtools getfasta -fi test.fa -bed test.bed >chr1:5-10 AAACC ``` -------------------------------- ### pairToPair Command Line Usage Source: https://bedtools.readthedocs.io/en/latest/_sources/content/tools/pairtopair The basic command-line usage for the pairToPair tool, specifying the input BEDPE files and options. ```bash pairToPair [OPTIONS] -a -b ``` -------------------------------- ### Comparing flankBed and slopBed output Source: https://bedtools.readthedocs.io/en/latest/_sources/content/history This example contrasts the output of flankBed and slopBed when creating flanking regions. SlopBed includes the original feature in its output, while flankBed only outputs the flanking regions. ```bash bin/flankBed -i a.bed -b 10 -g genomes/human.hg18.genome chr1 90 100 chr1 200 210 ``` ```bash bin/slopBed -i a.bed -b 10 -g genomes/human.hg18.genome chr1 90 210 ``` -------------------------------- ### View BAM File Contents (Example) Source: https://bedtools.readthedocs.io/en/latest/content/tools/bedtobam Demonstrates how to view the contents of a generated BAM file using samtools view and pipe the output to head to see the first few alignments. This is useful for verifying the output format. ```bash samtools view rmsk.hg18.chr21.bam | head -5 ``` ```bash samtools view knownGene.bam | head -2 ``` -------------------------------- ### bedtools maskfasta Usage Summary Source: https://bedtools.readthedocs.io/en/latest/_sources/content/tools/maskfasta Provides the basic command-line syntax for using bedtools maskfasta, specifying input FASTA, feature file, and output FASTA. ```bash $ bedtools maskfasta [OPTIONS] -fi -bed -fo (or): $ maskFastaFromBed [OPTIONS] -fi -bed -fo ``` -------------------------------- ### bedtools jaccard Default Usage Example Source: https://bedtools.readthedocs.io/en/latest/content/tools/jaccard Demonstrates the default behavior of bedtools jaccard, calculating intersection, union, Jaccard statistic, and number of intersections between two BED files. ```bash cat a.bed chr1 10 20 chr1 30 40 cat b.bed chr1 15 20 bedtools jaccard -a a.bed -b b.bed ``` -------------------------------- ### Identify Uncovered Genome Intervals with bedtools complement Source: https://bedtools.readthedocs.io/en/latest/content/example-usage Reports genomic intervals not covered by specified input intervals. Requires an input BED file and a genome file to define the reference genome. ```bash bedtools complement -i repeatMasker.bed -g hg18.genome ``` -------------------------------- ### Bedtools: Valid Header Lines Source: https://bedtools.readthedocs.io/en/latest/_sources/content/overview Provides examples of valid header lines that bedtools will ignore in BED and GFF files. These lines typically start with '#', 'track', or 'browser'. ```plaintext track name=aligned_read description="Illumina aligned reads" chr5 100000 500000 read1 50 + chr5 2380000 2386000 read2 60 - #This is a fascinating dataset chr5 100000 500000 read1 50 + chr5 2380000 2386000 read2 60 - browser position chr22:1-20000 chr5 100000 500000 read1 50 + chr5 2380000 2386000 read2 60 - ``` -------------------------------- ### bedtools merge: Merge overlapping repetitive elements Source: https://bedtools.readthedocs.io/en/latest/content/example-usage This command merges overlapping features in 'repeatMasker.bed' into single, consolidated entries. The input file must be sorted by chromosome and then by start coordinate. ```bash bedtools merge -i repeatMasker.bed ``` -------------------------------- ### bedtools bamtobed: Convert BAM to BEDPE format Source: https://bedtools.readthedocs.io/en/latest/_sources/content/example-usage Converts BAM alignment data into BEDPE format, which is suitable for paired-end reads. BEDPE represents the start and end of both reads in a pair. ```bash bedtools bamtobed -i reads.bam -bedpe > reads.bedpe ``` -------------------------------- ### Creating a Genome File with samtools faidx Source: https://bedtools.readthedocs.io/en/latest/_sources/content/general-usage Demonstrates the process of creating a genome file suitable for bedtools using `samtools faidx`. This involves downloading a FASTA reference genome, indexing it with `samtools faidx`, and then using the resulting .fai file as the genome file for bedtools operations. ```bash # download GRCh38 wget ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/technical/reference/GRCh38_reference_genome/GRCh38_full_analysis_set_plus_decoy_hla.fa # create an index of it samtools faidx GRCh38_full_analysis_set_plus_decoy_hla.fa # use the .fai index as a genome file with bedtools bedtools complement my.grch38.bed -g GRCh38_full_analysis_set_plus_decoy_hla.fa.fai ``` -------------------------------- ### Display Help for a Specific Bedtools Tool Source: https://bedtools.readthedocs.io/en/latest/content/faq Shows detailed help and options for a specific bedtools sub-command, such as 'bedtools merge'. ```bash $ bedtools merge -h Tool: bedtools merge (aka mergeBed) Version: v2.17.0 Summary: Merges overlapping BED/GFF/VCF entries into a single interval. Usage: bedtools merge [OPTIONS] -i Options: -s Force strandedness. ... ``` -------------------------------- ### BEDTools Valid Header Examples Source: https://bedtools.readthedocs.io/en/latest/content/overview Illustrates valid header lines that bedtools will ignore at the beginning of BED and GFF files. Headers starting with '#', 'track', or 'browser' are recognized and skipped, ensuring correct data parsing. ```plaintext track name=aligned_read description="Illumina aligned reads” chr5 100000 500000 read1 50 + chr5 2380000 2386000 read2 60 - #This is a fascinating dataset chr5 100000 500000 read1 50 + chr5 2380000 2386000 read2 60 - browser position chr22:1-20000 chr5 100000 500000 read1 50 + chr5 2380000 2386000 read2 60 - ``` -------------------------------- ### Annotate BED file with coverage from other files (bedtools) Source: https://bedtools.readthedocs.io/en/latest/content/tools/annotate This example demonstrates the default behavior of `bedtools annotate`, where it calculates the fraction of each feature in the input file (`-i`) covered by features in the provided annotation files (`-files`). The output includes the original feature information followed by the calculated coverage fractions. ```bash cat variants.bed chr1 100 200 nasty 1 - chr2 500 1000 ugly 2 + chr3 1000 5000 big 3 - cat genes.bed chr1 150 200 geneA 1 + chr1 175 250 geneB 2 + chr3 0 10000 geneC 3 - cat conserve.bed chr1 0 10000 cons1 1 + chr2 700 10000 cons2 2 - chr3 4000 10000 cons3 3 + cat known_var.bed chr1 0 120 known1 - chr1 150 160 known2 - chr2 0 10000 known3 + bedtools annotate -i variants.bed -files genes.bed conserve.bed known_var.bed chr1 100 200 nasty 1 - 0.500000 1.000000 0.300000 chr2 500 1000 ugly 2 + 0.000000 0.600000 1.000000 chr3 1000 5000 big 3 - 1.000000 0.250000 0.000000 ``` -------------------------------- ### bedtools complement Usage Example Source: https://bedtools.readthedocs.io/en/latest/content/tools/complement Demonstrates the basic usage of 'bedtools complement' to find genomic regions not covered by input intervals. Requires an input BED/GFF/VCF file and a genome file. ```bash bedtools complement -i -g ``` ```bash complementBed -i -g ``` ```bash $ cat A.bed chr1 100 200 chr1 400 500 chr1 500 800 $ cat my.genome chr1 1000 chr2 800 $ bedtools complement -i A.bed -g my.genome chr1 0 100 chr1 200 400 chr1 800 1000 chr2 0 800 ``` -------------------------------- ### bedtools genomecov Usage Example Source: https://bedtools.readthedocs.io/en/latest/content/tools/genomecov Shows the basic usage pattern for bedtools genomecov, including options for input files (-i, -ibam) and genome file (-g). It demonstrates alternative command names like 'genomeCoverageBed'. ```bash bedtools genomecov [OPTIONS] [-i|-ibam] -g (iff. -i and not -ibam) ``` ```bash genomeCoverageBed [OPTIONS] [-i|-ibam] -g (iff. -i and not -ibam) ``` -------------------------------- ### Merge Overlapping Intervals with bedtools merge Source: https://bedtools.readthedocs.io/en/latest/_sources/content/example-usage Merges overlapping repetitive elements into a single entry. The input must be sorted by chromosome and then by start coordinate. For BED files, pre-sorting is required using 'sort -k1,1 -k2,2n'. ```bash bedtools merge -i repeatMasker.bed ``` ```bash bedtools merge -i repeatMasker.bed -n ``` ```bash bedtools merge -i repeatMasker.bed -d 1000 ``` -------------------------------- ### bedtools getfasta Usage Example Source: https://bedtools.readthedocs.io/en/latest/_sources/content/tools/getfasta This snippet shows the basic command-line usage of bedtools getfasta, specifying the input FASTA file (-fi) and the BED/GFF/VCF file (-bed). Output can be directed to stdout or a specified output file (-fo). ```bash $ bedtools getfasta [OPTIONS] -fi -bed ``` ```bash $ getFastaFromBed [OPTIONS] -fi -bed ``` -------------------------------- ### bedtools coverage with sorted input for large files Source: https://bedtools.readthedocs.io/en/latest/content/tools/coverage This example shows how to use the '-sorted' option with bedtools coverage for processing very large files. It requires the input files to be pre-sorted by chromosome and start position to enable a memory-efficient algorithm. ```bash sort -k1,1 -k2,2n in.bed > in.sorted.bed bedtools coverage -a input.bed -b large_coverage.bed -sorted ``` -------------------------------- ### Merge Overlapping Intervals with bedtools Source: https://bedtools.readthedocs.io/en/latest/_sources/content/tools/merge This example demonstrates the default behavior of bedtools merge, combining overlapping and book-ended intervals in a BED file into a single, larger interval. The input file must be presorted by chromosome and start position. ```bash cat A.bed chr1 100 200 chr1 180 250 chr1 250 500 chr1 501 1000 bedtools merge -i A.bed chr1 100 500 chr1 501 1000 ``` -------------------------------- ### BEDTools General Command Structure Source: https://bedtools.readthedocs.io/en/latest/content/bedtools-suite Demonstrates the basic command-line syntax for invoking BEDTools and its sub-commands. This is the fundamental way to interact with the suite. ```bash bedtools [sub-command] [options] ``` -------------------------------- ### BEDTools overlap: Compute overlap from windowBed output Source: https://bedtools.readthedocs.io/en/latest/_sources/content/tools/overlap This example demonstrates how to pipe the output of 'bedtools window' into the 'overlap' command to calculate the overlap between features. The '-i stdin' option is used to read from the pipe, and '-cols 2,3,6,7' specifies the columns containing the start and end coordinates from the piped input. ```bash bedtools window -a A.bed -b B.bed -w 10 | overlap -i stdin -cols 2,3,6,7 ``` -------------------------------- ### GFF Format Example Source: https://bedtools.readthedocs.io/en/latest/_sources/content/general-usage Provides an example of a typical GFF file entry, used for annotating genomic features. ```plaintext # GFF entries would typically look like this, though not explicitly provided in the text. ``` -------------------------------- ### bedtools getfasta: Output to file Source: https://bedtools.readthedocs.io/en/latest/content/tools/getfasta Shows how to redirect the output of `bedtools getfasta` to a specified output file using the -fo option. ```bash bedtools getfasta -fi test.fa -bed test.bed -fo test.fa.out cat test.fa.out >chr1:5-10 AAACC ``` -------------------------------- ### BED4 Format Example Source: https://bedtools.readthedocs.io/en/latest/_sources/content/general-usage Example of a BED4 file format, extending BED3 by adding a name for the genomic feature. ```plaintext chr1 11873 14409 uc001aaa.3 ``` -------------------------------- ### Filter and Convert BAM to BED with samtools and bedtools Source: https://bedtools.readthedocs.io/en/latest/content/tools/bamtobed This example demonstrates piping the output of samtools view to bedtools bamtobed to convert only properly-paired reads (FLAG == 0x2) into BED format. The input is specified as stdin, and the output is piped to head for preview. ```bash $ samtools view -bf 0x2 reads.bam | bedtools bamtobed -i stdin | head chr7 118970079 118970129 TUPAC_0001:3:1:0:1452#0/1 37 - chr7 118965072 118965122 TUPAC_0001:3:1:0:1452#0/2 37 + chr11 46769934 46769984 TUPAC_0001:3:1:0:1472#0/1 37 - chr11 46765606 46765656 TUPAC_0001:3:1:0:1472#0/2 37 + chr20 54704674 54704724 TUPAC_0001:3:1:1:1833#0/1 37 + chr20 54708987 54709037 TUPAC_0001:3:1:1:1833#0/2 37 - chrX 9380413 9380463 TUPAC_0001:3:1:1:285#0/1 0 - chrX 9375861 9375911 TUPAC_0001:3:1:1:285#0/2 0 + chrX 131756978 131757028 TUPAC_0001:3:1:2:523#0/1 37 + chrX 131761790 131761840 TUPAC_0001:3:1:2:523#0/2 37 - ``` -------------------------------- ### BED6 Format Example Source: https://bedtools.readthedocs.io/en/latest/_sources/content/general-usage Example of a BED6 file format, adding strand information to the BED5 format for genomic features. ```plaintext chr1 11873 14409 uc001aaa.3 0 + ``` -------------------------------- ### Check Bedtools Version Source: https://bedtools.readthedocs.io/en/latest/_sources/content/faq To determine the installed version of Bedtools, use the '--version' command-line option. This is useful for verifying installation and compatibility. ```bash $ bedtools --version bedtools v2.17.0 ``` -------------------------------- ### bedtools bamtobed Usage Summary Source: https://bedtools.readthedocs.io/en/latest/content/tools/bamtobed This shows the basic command structure for bedtools bamtobed, indicating the required input file and the alternative command name 'bamToBed'. ```bash bedtools bamtobed [OPTIONS] -i bamToBed [OPTIONS] -i ``` -------------------------------- ### BED12 Format Example Source: https://bedtools.readthedocs.io/en/latest/_sources/content/general-usage Example of a BED12 file format, representing a genomic feature with all twelve possible columns, including block information. ```plaintext chr1 11873 14409 uc001aaa.3 0 + 11873 11873 0 3 354,109,1189, 0,739,1347, ``` -------------------------------- ### bedtools jaccard Usage Summary Source: https://bedtools.readthedocs.io/en/latest/content/tools/jaccard Provides the basic usage syntax for the bedtools jaccard command, including required input files and available options. ```bash bedtools jaccard [OPTIONS] -a -b ``` -------------------------------- ### bedtools intersect: BAM to BED conversion with overlap filtering Source: https://bedtools.readthedocs.io/en/latest/content/example-usage This example converts BAM alignments to BED format and filters them to retain only those overlapping 'exons.bed', outputting the result to 'reads.touchingExons.bam'. ```bash bedtools intersect -abam reads.bam -b exons.bed > reads.touchingExons.bam ``` -------------------------------- ### flank: Prevent Flanks Before Chromosome Start Source: https://bedtools.readthedocs.io/en/latest/_sources/content/history Ensures that 'bedtools flank' no longer attempts to calculate flanks prior to the start of a chromosome. This corrects off-by-one errors and invalid coordinate issues. ```shell # Example: Calculating flanks, respecting chromosome boundaries bedtools flank -i intervals.bed -g chromsizes.txt -l 100 -r 100 ``` -------------------------------- ### bedtools window - BAM Input (-abam) and BED Output (-bed) Source: https://bedtools.readthedocs.io/en/latest/_sources/content/tools/window Demonstrates using a BAM file as input for file A with the -abam option and specifying BED format for the output with the -bed option. This is useful for processing alignment data. ```bash bedtools window -abam reads.bam -b genes.bed -bed ``` -------------------------------- ### linksBed with Custom UCSC Mirror, Organism, and Build Source: https://bedtools.readthedocs.io/en/latest/_sources/content/tools/links Illustrates advanced usage of linksBed, allowing customization of the UCSC Genome Browser mirror, organism, and genome build. This provides granular control over the generated links. ```bash linksBed -i genes.bed -base http://mirror.uni.edu -org mouse -db mm9 > genes.html ``` -------------------------------- ### bedtools flank: Prevent Flanking Before Chromosome Start Source: https://bedtools.readthedocs.io/en/latest/content/history The 'bedtools flank' tool has been fixed to no longer attempt to take flanks prior to the start of a chromosome. This prevents erroneous output and ensures biologically meaningful results. ```bash # Example usage of bedtools flank bedtools flank -i intervals.bed -g genome.txt -l 100 -r 100 ``` -------------------------------- ### bedtools multiinter with Header Option Source: https://bedtools.readthedocs.io/en/latest/_sources/content/tools/multiinter Example of using the -header option with bedtools multiinter to include column names in the output. This enhances readability by labeling the 'num' and 'list' columns, as well as the input files. ```bash bedtools multiinter -header -i a.bed b.bed c.bed chrom start end num list a.bed b.bed c.bed chr1 6 8 1 1 1 0 0 chr1 8 12 2 1,3 1 0 1 chr1 12 15 3 1,2,3 1 1 1 chr1 15 20 2 1,2 1 1 0 chr1 20 22 1 2 0 1 0 chr1 22 30 2 1,2 1 1 0 chr1 30 32 1 2 0 1 0 chr1 32 34 1 3 0 0 1 ``` -------------------------------- ### Bedtools Subtract Basic Usage Example Source: https://bedtools.readthedocs.io/en/latest/content/tools/subtract Demonstrates the default behavior of bedtools subtract where overlapping portions of intervals in B are removed from A. If B completely overlaps A, the A feature is removed. This example shows a case where a portion of A remains. ```bash cat A.bed chr1 10 20 chr1 100 200 cat B.bed chr1 0 30 chr1 180 300 bedtools subtract -a A.bed -b B.bed chr1 100 180 ``` -------------------------------- ### Compute BAM Alignment Coverage on Exons with Bedtools Source: https://bedtools.readthedocs.io/en/latest/content/advanced-usage This example demonstrates computing coverage of BAM alignments on exons using bedtools bamtobed and coverage. It converts BAM reads to BED format and then calculates coverage against exon intervals. Dependencies include samtools and bedtools. ```bash bedtools bamtobed -i reads.bam | \ bedtools coverage -a exons.bed -b - \ > exons.bed.coverage ``` -------------------------------- ### bedtools jaccard Minimum Overlap Fraction Example Source: https://bedtools.readthedocs.io/en/latest/content/tools/jaccard Illustrates how to use the -f option in bedtools jaccard to require a minimum overlap fraction with respect to intervals in file A. This example shows the output when requiring 10% overlap. ```bash cat a.bed chr1 10 20 chr1 30 40 cat b.bed chr1 15 20 bedtools jaccard -a a.bed -b b.bed -f 0.1 ``` -------------------------------- ### View Header of Genome File with bedtools Source: https://bedtools.readthedocs.io/en/latest/content/tools/summary This snippet displays the first few lines of the prepared genome file using the `head` command. This helps in confirming the correct format and content for use with `bedtools summary`. ```shell head grch38.genome.txt ```