<p>You can run <code>--chop</code> with <code>-x</code> to excise the last piece, adding the <code>--stagger</code> to size the chopped pieces as needed, e.g.:</p>
<pre><code>$ echo -e 'chr1\t0\t10' | bedops --chop 3 --stagger 2 -x -
chr1    0       3
chr1    2       5
chr1    4       7
chr1    6       9
</code></pre>
<p>Adjust parameters to taste.</p>
<p><a href="https://bedops.readthedocs.io/en/latest/content/reference/set-operations/bedops.html#chop-w-chop" rel="nofollow noreferrer">https://bedops.readthedocs.io/en/latest/content/reference/set-operations/bedops.html#chop-w-chop</a></p>
<p><a href="https://bedops.readthedocs.io/en/latest/content/reference/set-operations/bedops.html#stagger-stagger" rel="nofollow noreferrer">https://bedops.readthedocs.io/en/latest/content/reference/set-operations/bedops.html#stagger-stagger</a></p>
<p><a href="https://bedops.readthedocs.io/en/latest/content/reference/set-operations/bedops.html#exclude-x" rel="nofollow noreferrer">https://bedops.readthedocs.io/en/latest/content/reference/set-operations/bedops.html#exclude-x</a></p>

CC BY-SA 4.0
2022-09-19T17:33:06.230Z
Thank you @alex - the specific issue with bedops --stagger option is that I have not been able to feed it a negative number, that's what would allow for "overlaps" which is critical!
Zebra Fish
CC BY-SA 4.0
2022-09-19T18:49:37.107Z
As shown in the example above, `--stagger` can give you overlapping elements. However, you also can pipe results to `bedops --everything --range N` to extend edges by N bases, e.g. `... | bedops --chop X -x - | bedops --everything --range Y - > answer.bed`. You'd probably need to use coordinates from `fetchChromSizes` or similar to trim edge-of-chromosome windows, but that is easy to do via piping to `awk` or the like.
Alex Reynolds
CC BY-SA 4.0
2022-09-19T16:58:53.990Z
2022-09-19T16:58:53.990Z
Alex Reynolds
<p>I am trying to split my <em>.bed/</em>.fa file genomic segments into arbitrary smaller overlapping intervals:</p>
<p>Consider a typical line/row in my *.bed file as follows:</p>
<p>chrom. <span class="math-container">$\ \ \ \ \ $</span>  start <span class="math-container">$\ \ \ \ \ \ \ \ \ \ \ \ $</span> end</p>
<p>chr7 <span class="math-container">$\ \ \ $</span>   127471196 <span class="math-container">$\ \ \ $</span>    127472363<span class="math-container">$\ \ \ $</span>      ...</p>
<p>The start and end genomic positions include 1167 base pairs for this line. I need to extend this line, for example, into multiple lines where each line covers exactly 500bp like below:</p>
<p>chr7 <span class="math-container">$\ \ \ $</span>    127471196 <span class="math-container">$\ \ \ $</span>    127471696 <span class="math-container">$\ \ \ $</span>       ...</p>
<p>chr7 <span class="math-container">$\ \ \ $</span>    127471863  <span class="math-container">$\ \ \ $</span>   127472363 <span class="math-container">$\ \ \ $</span>       ...</p>
<p><a href="https://i.sstatic.net/Ws3ts.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Ws3ts.png" alt="![enter image description here" /></a></p>
<p>While each line covers 500pb, between the two new lines they both include the same &quot;range&quot; of genomic positions as the original line including some overlap which is fine (and desired)</p>
<p>Is there an existing tool (perhaps part of bedtools?) that can do something like this?</p>
<p>I know there is the <strong>bedops</strong> tool that does ALMOST this using the --chop option, where it takes the original segment x1:x2 and chops the original segment into specified fixed bp length intervals, however, if there is any left over towards the end is creates a new non-standard length segment (i.e. x1:x2=10bp and chop length=3, it will give you 4 segments that are length 3, 3, 3 and 1 - what I am looking for is something that adjusts for the last remainder and outputs segments of length 3,3,3 and 3 where the last length 3 segment is right adjusted, while the first three segments are left adjusted or better yet it gives the user the choice of precise redefinition of segment coordinates y1,y2,y3 and y4).  Thank you.</p>

<python><fasta><phylogenetics><chip-seq><bedtools>
How to chop fasta / bed /peak file genomic segments into smaller fixed or custom genomic intervals
# How to chop fasta / bed /peak file genomic segments into smaller fixed or custom genomic intervals

(Asked by: username_0 on 2022-09-10)

I am trying to split my *.bed/*.fa file genomic segments into arbitrary smaller overlapping intervals:

Consider a typical line/row in my \*.bed file as follows:

chrom. $\ \ \ \ \ $ start $\ \ \ \ \ \ \ \ \ \ \ \ $ end

chr7 $\ \ \ $ 127471196 $\ \ \ $ 127472363$\ \ \ $ ...

The start and end genomic positions include 1167 base pairs for this line. I need to extend this line, for example, into multiple lines where each line covers exactly 500bp like below:

chr7 $\ \ \ $ 127471196 $\ \ \ $ 127471696 $\ \ \ $ ...

chr7 $\ \ \ $ 127471863 $\ \ \ $ 127472363 $\ \ \ $ ...

[![![enter image description here](https://i.sstatic.net/Ws3ts.png)](https://i.sstatic.net/Ws3ts.png)

While each line covers 500pb, between the two new lines they both include the same "range" of genomic positions as the original line including some overlap which is fine (and desired)

Is there an existing tool (perhaps part of bedtools?) that can do something like this?

I know there is the **bedops** tool that does ALMOST this using the --chop option, where it takes the original segment x1:x2 and chops the original segment into specified fixed bp length intervals, however, if there is any left over towards the end is creates a new non-standard length segment (i.e. x1:x2=10bp and chop length=3, it will give you 4 segments that are length 3, 3, 3 and 1 - what I am looking for is something that adjusts for the last remainder and outputs segments of length 3,3,3 and 3 where the last length 3 segment is right adjusted, while the first three segments are left adjusted or better yet it gives the user the choice of precise redefinition of segment coordinates y1,y2,y3 and y4). Thank you.

**Tags:** python, fasta, phylogenetics, chip-seq, bedtools

---

## 1 answers

### Answer by username_1 on 2022-09-19. Score: 2

You can run --chop with -x to excise the last piece, adding the --stagger to size the chopped pieces as needed, e.g.:
$ echo -e 'chr1\t0\t10' | bedops --chop 3 --stagger 2 -x -
chr1    0       3
chr1    2       5
chr1    4       7
chr1    6       9

Adjust parameters to taste.
https://bedops.readthedocs.io/en/latest/content/reference/set-operations/bedops.html#chop-w-chop
https://bedops.readthedocs.io/en/latest/content/reference/set-operations/bedops.html#stagger-stagger
https://bedops.readthedocs.io/en/latest/content/reference/set-operations/bedops.html#exclude-x

> **Comments:**
> **username_0**: Thank you @alex - the specific issue with bedops --stagger option is that I have not been able to feed it a negative number, that's what would allow for "overlaps" which is critical!  
> **username_1**: As shown in the example above, `--stagger` can give you overlapping elements. However, you also can pipe results to `bedops --everything --range N` to extend edges by N bases, e.g. `... | bedops --chop X -x - | bedops --everything --range Y - > answer.bed`. You'd probably need to use coordinates from `fetchChromSizes` or similar to trim edge-of-chromosome windows, but that is easy to do via piping to `awk` or the like.  

---

