Count total base pairs in bedfile B that overlap bedfile A
1
0
Entering edit mode
9.1 years ago

I want to count the base pairs of CNVs in bedfile B that overlap bedfile A preferably in bedtools in one line.

bedfile A:

chr1    100    500

bedfile B:

chr1    50    99
chr1   250    299

Result:

chr1    100    500    100

Thanks

cnv bedtools • 2.7k views
ADD COMMENT
2
Entering edit mode
9.1 years ago

Via BEDOPS bedmap --bases:

$ bedmap --echo --bases --delim '\t' A.bed B.bed > answer.bed

Make sure your inputs are sorted per BEDOPS sort-bed. Not sure what happens with other tools and sort-bed is the faster of the options, anyway.

Note that the base count is not unique, if elements in B overlap amongst themselves. You could pre-process the B set with bedops --merge to get a unique base count. Here's a one-liner to demo that use case:

``` $ bedops --merge B.bed \ | bedmap --echo --bases --delim '\t' A.bed - \

> unique_answer.bed

Or you could do process substitution, if you use bash:

$ bedmap --echo --bases --delim '\t' A.bed <(bedops --merge B.bed) > unique_answer.bed
ADD COMMENT
0
Entering edit mode

Cool this is exactly what I want. I do already sort and merged file B to make things easier.

Is there a BEDOPS python api?

ADD REPLY
0
Entering edit mode

You could use the subprocess module.

ADD REPLY

Login before adding your answer.

Traffic: 2394 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6