This is a test version of Biostars. For the public version, visit https://www.biostars.org.
BED file: how to split/join into fragments of fixed length that take only portions INSIDE the intervals ?

I have been looking at bedtools and bedops to do the following thing but haven't figured out:

Input bed:

chr1    1000    2000    geneA    0    +
chr1    2100    2500    geneB    0    +
chr1    2800    3200    geneC    0    +
chr1    3700    4600    geneD    0    +

Output by 500 bases fragments inside those BED intervals:

chr1    1000    1500    geneA          0    + # split action
chr1    1500    2000    geneA          0    + # split action
chr1    2100    2900    geneB,geneC    0    + # join action: 400 from 2100 - 2500, and 100 from 2800 - 2900
chr1    2900    3900    geneC,geneD    0    + # join action: 300 from 2900 - 3200, and 200 from 3700 - 3900
chr1    3900    4400    geneD          0    + # split action
chr1    4400    4600    geneD          0    + # split action, take the rest

For simplicity, input bed do not have overlapping intervals.

bed bedops bedtools

I know that this is not the answer you're looking for but maybe you should try to write a little perl/python/awk script to do it.

If there is no quick way, I will have to spend time and do it.

Reading more carefully about --stagger and--chop operation of bedops, they may actually can do what I want.

No, bedops doesn't do what I want:

bedops --chop 500 test.bedops.bed                                                                                                                         
chr1    1000    1500
chr1    1500    2000
chr1    2100    2500 # only take 400 and stops
chr1    2800    3200 # start anew
chr1    3700    4200 # start anew
chr1    4200    4600 # only take 400 and stops

1 answer

As mentioned, you need to write a script to do this, because you are not applying the same operation to all input intervals equally. For instance, some elements get one split operation, other elements get a different split operation. You will likely need to write custom logic to decide how to apply your desired operations.

Log in to answer this question.