Question: bedtools complement error
0
gravatar for bk11
9 months ago by
bk1130
bk1130 wrote:

Hi I have an error from bedtools. What might be happening? I have two bed files:

cat A.bed
chr1  100  200
chr1  400  500
chr1  500  800

cat my.genome
chr1  1000
chr2  800

when I run this:

bedtools complement -i A.bed -g your.genome

It gives

Error: The genome file your.genome has no valid entries. Exiting.
bedtools • 559 views
ADD COMMENTlink modified 9 months ago by Alex Reynolds28k • written 9 months ago by bk1130
0
gravatar for ATpoint
9 months ago by
ATpoint23k
Germany
ATpoint23k wrote:

your.genome must be tab-delimited.

ADD COMMENTlink written 9 months ago by ATpoint23k

I changed it into tab-delimited and still does not work.

sed 's/ /\t/g' my.genome >my.genome1
cat my.genome1

chr1        1000
chr2        800
ADD REPLYlink written 9 months ago by bk1130

If your files were tab-delimited, it would work. You probably substituted the wrong delimiter in your sedcommand. Probably it is a double-whitespace or something, and after your command you now have a hybrid tab-whitespace delimiter.

enter image description here

ADD REPLYlink modified 9 months ago • written 9 months ago by ATpoint23k

Could you please show your command lines who you generated bed files? I am still having problem.

ADD REPLYlink written 9 months ago by bk1130

In this case I simply did it manually by tiping it in a text editor. What organism are you working on? There are genome.sizes files available for download for most species.

ADD REPLYlink modified 9 months ago • written 9 months ago by ATpoint23k

Try replacing all [[:space:]]+ with \t. That should work.

ADD REPLYlink written 9 months ago by RamRS24k
0
gravatar for Alex Reynolds
9 months ago by
Alex Reynolds28k
Seattle, WA USA
Alex Reynolds28k wrote:

Here's a one-liner that should work:

$ bedops --complement <( sort-bed A.bed ) <( awk -v OFS="\t" '{ print $1, "0", $2 }' my.genome | sort-bed - )  > answer.bed

This part is called a process substitution in the bash shell:

... <( awk -v OFS="\t" '{ print $1, "0", $2 }' my.genome | sort-bed - ) ...

It uses awk to turn the file my.genome into a sorted BED file, on which you can do set operations with bedops. Basically, everything within <( ... ) returns operational intervals that are fed to the bedops process as a standard input stream.

Here's what the one-liner looks like when broken down into separate commands:

$ sort-bed A.bed > A.sorted.bed
$ awk -v OFS="\t" '{ print $1, "0", $2 }' my.genome | sort-bed - > my.genome.sorted.bed
$ bedops --complement A.sorted.bed my.genome.sorted.bed > answer.bed
$ rm A.sorted.bed my.genome.sorted.bed

Process substitutions might look a little odd, at first, but they help avoid creating intermediate files, which slow down operations on whole-genome scale work. Intermediate files also require disk space and need cleaning up. It's useful to avoid intermediate files, when possible.

ADD COMMENTlink modified 9 months ago by ATpoint23k • written 9 months ago by Alex Reynolds28k

I added a whitespace between all awk -v and OFS=. Hope you don't mind :)

ADD REPLYlink written 9 months ago by ATpoint23k

Hi @Alex Reynolds,

I was just exploring the bedpos --complement option instead of bedtools complement option to get coordinates which are present in genome.bed but not in target.bed, I found --difference is more suitable to get the result.bed, instead of --complement.

Do correct me if my understanding of the tool is wrong.

Thanks!

ADD REPLYlink modified 3 months ago by RamRS24k • written 3 months ago by bioinfo8940
1

The manual states:

The --complement operation calculates the genomic regions in the gaps between the contiguous per-chromosome ranges defined by one or more inputs.

 

The --difference operation calculates the genomic regions found within the first (reference) input file, excluding regions in all other input files

Clearly, an operation of the sort A.bed minus B.bed requires the use of --difference as --complement works on a completely different problem.

ADD REPLYlink modified 3 months ago • written 3 months ago by RamRS24k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1842 users visited in the last hour