Answers.Body: <p><code>bedtools intersect</code> with multiple files after <code>-b</code> performs pairwise intersections between <code>-a</code> and each file in <code>-b</code>.
  It does not intersect all files simultaneously.
  See here, from the <a href="https://bedtools.readthedocs.io/en/latest/content/tools/intersect.html" rel="nofollow noreferrer">Bedtools documentation</a>. The green section only contains intervals from <code>-a</code> that also intersect at least one interval in any <code>-b</code> file.
  <a href="https://i.sstatic.net/5Z8CE.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/5Z8CE.png" alt="Bedtools intersect"></a></p>
  
  <p>What I think you're looking for is <code>bedtools multiinter</code> (documentation <a href="https://bedtools.readthedocs.io/en/latest/content/tools/multiinter.html" rel="nofollow noreferrer">here</a> is unfortunately blank).
  <code>bedtools multiinter -i input [input...]</code> will produce a BED file that covers every position listed in your input files, followed by how many and which of your input samples overlap that given position.</p>
  
  <p>You can use this BED file and create something like an <a href="https://cran.r-project.org/web/packages/UpSetR/vignettes/basic.usage.html" rel="nofollow noreferrer">UpSet plot</a> to visualize how many bases/peaks are shared between any combination of your samples.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-10T17:46:07.927Z
Answers.Text: Thank you very much. Do you think is it ok do intersection one by one? I did it one by one. First intersecting the first two and generating the intersected file and then intersected file is again intersected with the third one. I got less peaks in this manner. Is it ok to do that?
Answers.UserDisplayName: MudithMMBc
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-11T17:01:02.677Z
Answers.Text: It's not wrong to do it this way, no. But it is more difficult, takes longer, and you lose a lot of information in the process. If you use `multiinter`, you can later select that regions supported by all samples with `awk '{if ($4 == x) print}'` where `x` is the number of samples (5 in your case). And you haven't gotten rid of the sites that are supported by 3 or 4 samples, say.
Answers.UserDisplayName: James Hawley
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-11T20:35:56.500Z
Answers.Text: Oh. I'll try that way. Thank you very much.
Answers.UserDisplayName: MudithMMBc
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-10T16:25:39.120Z
Answers.LastActivityDate: 2020-03-10T16:25:39.120Z
Answers.UserDisplayName: James Hawley
Body: <p>I have following 5 narrow peak files after peak calling.</p>
  
  <pre><code>K14_peaks.narrowPeak
  K15_peaks.narrowPeak
  K16_peaks.narrowPeak
  K3_peaks.narrowPeak
  K8_peaks.narrowPeak
  </code></pre>
  
  <p>I need to get the intersection of peaks into a new file (The peaks that represent all these files). I used following code but I got higher number of peaks not a lower number.</p>
  
  <pre><code>bedtools intersect -a K14_peaks.narrowPeak -b K15_peaks.narrowPeak K16_peaks.narrowPeak K3_peaks.narrowPeak K8_peaks.narrowPeak -wo &gt; intersected.bed
  </code></pre>
  
  <p>Can someone help me?
  Thank you.</p>
  
Tags: <ngs><bedtools><chip-seq><peak-calling><macs2>
Title: How to get the intersection of peaks after peak calling using MACS2?
ThreadText: # How to get the intersection of peaks after peak calling using MACS2?
  
  (Asked by: username_0 on 2020-03-10)
  
  I have following 5 narrow peak files after peak calling.
  
  ```
  K14_peaks.narrowPeak
  K15_peaks.narrowPeak
  K16_peaks.narrowPeak
  K3_peaks.narrowPeak
  K8_peaks.narrowPeak
  
  ```
  
  I need to get the intersection of peaks into a new file (The peaks that represent all these files). I used following code but I got higher number of peaks not a lower number.
  
  ```
  bedtools intersect -a K14_peaks.narrowPeak -b K15_peaks.narrowPeak K16_peaks.narrowPeak K3_peaks.narrowPeak K8_peaks.narrowPeak -wo > intersected.bed
  
  ```
  
  Can someone help me?
  Thank you.
  
  **Tags:** ngs, bedtools, chip-seq, peak-calling, macs2
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-03-10. Score: 1 | Accepted answer
  
  `bedtools intersect` with multiple files after `-b` performs pairwise intersections between `-a` and each file in `-b`.
  It does not intersect all files simultaneously.
  See here, from the [Bedtools documentation](https://bedtools.readthedocs.io/en/latest/content/tools/intersect.html). The green section only contains intervals from `-a` that also intersect at least one interval in any `-b` file.
  [![Bedtools intersect](https://i.sstatic.net/5Z8CE.png)](https://i.sstatic.net/5Z8CE.png)
  
  What I think you're looking for is `bedtools multiinter` (documentation [here](https://bedtools.readthedocs.io/en/latest/content/tools/multiinter.html) is unfortunately blank).
  `bedtools multiinter -i input [input...]` will produce a BED file that covers every position listed in your input files, followed by how many and which of your input samples overlap that given position.
  
  You can use this BED file and create something like an [UpSet plot](https://cran.r-project.org/web/packages/UpSetR/vignettes/basic.usage.html) to visualize how many bases/peaks are shared between any combination of your samples.
  
  > **Comments:**
  > **username_0**: Thank you very much. Do you think is it ok do intersection one by one? I did it one by one. First intersecting the first two and generating the intersected file and then intersected file is again intersected with the third one. I got less peaks in this manner. Is it ok to do that?  
  > **username_1**: It's not wrong to do it this way, no. But it is more difficult, takes longer, and you lose a lot of information in the process. If you use `multiinter`, you can later select that regions supported by all samples with `awk '{if ($4 == x) print}'` where `x` is the number of samples (5 in your case). And you haven't gotten rid of the sites that are supported by 3 or 4 samples, say.  
  > **username_0**: Oh. I'll try that way. Thank you very much.  
  
  ---
  
  