Question: Count total base pairs in bedfile B that overlap bedfile A
0
gravatar for QVINTVS_FABIVS_MAXIMVS
3.5 years ago by
USA SoCal
QVINTVS_FABIVS_MAXIMVS2.2k 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.2k views
ADD COMMENTlink modified 3.5 years ago by Alex Reynolds28k • written 3.5 years ago by QVINTVS_FABIVS_MAXIMVS2.2k
2
gravatar for Alex Reynolds
3.5 years ago by
Alex Reynolds28k
Seattle, WA USA
Alex Reynolds28k 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 3.5 years ago • written 3.5 years ago by Alex Reynolds28k

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 3.5 years ago by QVINTVS_FABIVS_MAXIMVS2.2k

You could use the subprocess module: https://docs.python.org/2/library/subprocess.html

ADD REPLYlink written 3.5 years ago by Alex Reynolds28k
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: 791 users visited in the last hour