Reference Code backup Executable files
Combines multiple BedGraph files into a single file, allowing coverage comparisons between them. It assumes that each BedGraph file is sorted by chrom/start and that the intervals in each are non-overlapping.
bedtools unionbedg [OPTIONS] -i FILE1 FILE2 .. FILEn
This tool is part of the bedtools
suite, and it's also known as unionBedGraphs
.
-g FILE
parameter.Input files:
$ cat 1.bg chr1 1000 1500 10 chr1 2000 2100 20 $ cat 2.bg chr1 900 1600 60 chr1 1700 2050 50 $ cat 3.bg chr1 1980 2070 80 chr1 2090 2100 20 $ cat sizes.txt chr1 5000
Union/combine the files:
$ unionBedGraphs -i 1.bg 2.bg 3.bg
chr1 900 1000 0 60 0
chr1 1000 1500 10 60 0
chr1 1500 1600 0 60 0
chr1 1700 1980 0 50 0
chr1 1980 2000 0 50 80
chr1 2000 2050 20 50 80
chr1 2050 2070 20 0 80
chr1 2070 2090 20 0 0
chr1 2090 2100 20 0 20
Union/combine the files, with a header line (titles are the file names):
$ unionBedGraphs -header -i 1.bg 2.bg 3.bg
chrom start end 1 2 3
chr1 900 1000 0 60 0
chr1 1000 1500 10 60 0
chr1 1500 1600 0 60 0
chr1 1700 1980 0 50 0
chr1 1980 2000 0 50 80
chr1 2000 2050 20 50 80
chr1 2050 2070 20 0 80
chr1 2070 2090 20 0 0
chr1 2090 2100 20 0 20
Union/combine the files, with a header line and custom names:
$ unionBedGraphs -header-i 1.bg 2.bg 3.bg
-names WT-1 WT-2 KO-1
chrom start end WT-1 WT-2 KO-1 chr1 900 1000 0 60 0 chr1 1000 1500 10 60 0 chr1 1500 1600 0 60 0 chr1 1700 1980 0 50 0 chr1 1980 2000 0 50 80 chr1 2000 2050 20 50 80 chr1 2050 2070 20 0 80 chr1 2070 2090 20 0 0 chr1 2090 2100 20 0 20
Union/combine, showing empty regions (note, requires -g):
$ unionBedGraphs -header -empty-g sizes.txt
-i 1.bg 2.bg 3.bg
chrom start end 1 2 3 chr1 0 900 0 0 0 chr1 900 1000 0 60 0 chr1 1000 1500 10 60 0 chr1 1500 1600 0 60 0 chr1 1600 1700 0 0 0 chr1 1700 1980 0 50 0 chr1 1980 2000 0 50 80 chr1 2000 2050 20 50 80 chr1 2050 2070 20 0 80 chr1 2070 2090 20 0 0 chr1 2090 2100 20 0 20 chr1 2100 5000 0 0 0