Question: Count total base pairs in bedfile B that overlap bedfile A
0
gravatar for QVINTVS_FABIVS_MAXIMVS
4.3 years ago by
USA SoCal
QVINTVS_FABIVS_MAXIMVS2.3k wrote:

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.

bed cnv bedfile bedtools • 1.4k views
ADD COMMENTlink modified 4.3 years ago by Alex Reynolds29k • written 4.3 years ago by QVINTVS_FABIVS_MAXIMVS2.3k
2
gravatar for Alex Reynolds
4.3 years ago by
Alex Reynolds29k
Seattle, WA USA
Alex Reynolds29k wrote:

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 COMMENTlink modified 9 weeks ago by RamRS25k • written 4.3 years ago by Alex Reynolds29k

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 REPLYlink written 4.3 years ago by QVINTVS_FABIVS_MAXIMVS2.3k

You could use the subprocess module.

ADD REPLYlink modified 9 weeks ago by RamRS25k • written 4.3 years ago by Alex Reynolds29k
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: 737 users visited in the last hour