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?