text: user9521: From the bedtools intersect man (for version 2.30.0):
  -a BAM/BED/GFF/VCF file “A”. Each feature in A is compared to B in search of overlaps. 
     Use “stdin” if passing A with a UNIX pipe.
  
  The stdin part, however, does not apply to version 2.27.1. The help on this version gives no advice for piping.
  bam mem ref fq1.fastq fq2.fastq | samtools view -b | bedtools intersect -a stdin -b blacklist.bed -v > align_black.sam
  Error: unable to open file or unable to determine types for file stdin
  
  - Please ensure that your file is TAB delimited (e.g., cat -t FILE).
  - Also ensure that your file has integer chromosome coordinates in the
    expected columns (e.g., cols 2 and 3 for BED).
  
  I also tried:
  (map to bam) | bedtools intersect -a "stdin" -b blacklist.bed -v > align_black.sam
  (map to bam) | bedtools intersect -a -b blacklist.bed -v > align_black.sam
  (map to bam) | bedtools intersect -b blacklist.bed -v > align_black.sam
  
  But these don't work either, either for the same or a different reason. Here is a site that tells me to use the above syntax: https://bedtools.readthedocs.io/en/latest/content/example-usage.html
  What is the solution to this if I want to pipe everything together for my users?
  
  user776: Here's a way to skip conversion to BAM and pipe between tools, which performs the same set operations:
  $ bam mem ref fq1.fastq fq2.fastq | sam2bed - | bedops -e 1 - blacklist.bed > blacklisted_reads.bed
  
  With this toolkit, the hyphen (-) follows a Unix convention of serving as a placeholder for stdin.
  
  user9521: While I have chosen ATpoint as the official answer, another possible syntax to use is
  bedtools intersect -a stdin -b blacklist.bed -v < `(map to bam)` > align_black.bam
  
  The main issue with this syntax is that it obfuscates the direction of flow for the pipeline, piping step 2 after step 1 is better in the official answer.
  
  user-1: With v2.27.1 (or any version I ever used) instead of stdin use -
  (...) | bedtools intersect -a - -b blacklist.bed -v > out.bam
  
  Be aware that the output of this is a BAM, not SAM file. It would be easier though to simply make a list of regions you want to keep, e.g. the complement of the backlist file with the entire genome (bedtools complement), and then use samtools view -L option to only keep overlapping reads. That saves you the run through bedtools.
  
original_text: 9521: <p>From the bedtools intersect man (for version 2.30.0):</p>
  <pre><code>-a BAM/BED/GFF/VCF file “A”. Each feature in A is compared to B in search of overlaps. 
     Use “stdin” if passing A with a UNIX pipe.
  </code></pre>
  <p>The stdin part, however, does not apply to version 2.27.1. The help on this version gives no advice for piping.</p>
  <pre><code>bam mem ref fq1.fastq fq2.fastq | samtools view -b | bedtools intersect -a stdin -b blacklist.bed -v &gt; align_black.sam
  Error: unable to open file or unable to determine types for file stdin
  
  - Please ensure that your file is TAB delimited (e.g., cat -t FILE).
  - Also ensure that your file has integer chromosome coordinates in the
    expected columns (e.g., cols 2 and 3 for BED).
  </code></pre>
  <p>I also tried:</p>
  <pre><code>(map to bam) | bedtools intersect -a &quot;stdin&quot; -b blacklist.bed -v &gt; align_black.sam
  (map to bam) | bedtools intersect -a -b blacklist.bed -v &gt; align_black.sam
  (map to bam) | bedtools intersect -b blacklist.bed -v &gt; align_black.sam
  </code></pre>
  <p>But these don't work either, either for the same or a different reason. Here is a site that tells me to use the above syntax: <a href="https://bedtools.readthedocs.io/en/latest/content/example-usage.html" rel="nofollow noreferrer">https://bedtools.readthedocs.io/en/latest/content/example-usage.html</a></p>
  <p>What is the solution to this if I want to pipe everything together for my users?</p>
   776: <p>Here's a way to skip conversion to BAM and pipe between tools, which performs the same set operations:</p>
  <pre><code>$ bam mem ref fq1.fastq fq2.fastq | sam2bed - | bedops -e 1 - blacklist.bed &gt; blacklisted_reads.bed
  </code></pre>
  <p>With this toolkit, the hyphen (<code>-</code>) follows a Unix convention of serving as a placeholder for stdin.</p>
   9521: <p>While I have chosen ATpoint as the official answer, another possible syntax to use is</p>
  <pre><code>bedtools intersect -a stdin -b blacklist.bed -v &lt; `(map to bam)` &gt; align_black.bam
  </code></pre>
  <p>The main issue with this syntax is that it obfuscates the direction of flow for the pipeline, piping step 2 after step 1 is better in the official answer.</p>
   -1: <p>With v2.27.1 (or any version I ever used) instead of <code>stdin</code> use <code>-</code></p>
  <pre><code>(...) | bedtools intersect -a - -b blacklist.bed -v &gt; out.bam
  </code></pre>
  <p>Be aware that the output of this is a BAM, not SAM file. It would be easier though to simply make a list of regions you want to keep, e.g. the complement of the backlist file with the entire genome (bedtools complement), and then use <code>samtools view -L</code> option to only keep overlapping reads. That saves you the run through <code>bedtools</code>.</p>
  