I am using bowtie2, and due to the size of the SAM output, I would like to entirely avoid the SAM file, and pipe the results into samtools to convert the output to a BAM file. I am getting a little bit hung up on how to accomplish this.

I have tried a few different options:

The approach here: [http://slhogle.github.io/2014/bowtie-and-samtools/][1]

and here: [http://www.metagenomics.wiki/tools/samtools/breadth-of-coverage][2]

are both giving me an empty BAM file.

I have also tried:

    bowtie2 -x [index] -U [reads] -S ${TMPDIR}/temp.sam | samtools view -bS > out.bam

To see if I would get anything different using the temp directory to store the SAM temporarily.

Edit in response to a comment to add the commands I have tried:

    bowtie2 -x [index] -U [reads] -S - | samtools view -bS > out.bam

And

    bowtie2 -x [index] -U [reads] -S - | samtools view -bS -  > out.bam

I'm sure this has been done before, is there an obvious way to accomplish this task?

Thanks.

  [1]: http://slhogle.github.io/2014/bowtie-and-samtools/
  [2]: http://www.metagenomics.wiki/tools/samtools/breadth-of-coverage
You shouldn't need to use the -S command for the output, just omit this arguement

```
bowtie2 -x genomeindex -U out.fq|samtools view -bS - > out.bam
```

Versions

```
% bowtie2 --version
/usr/bin/bowtie2-align-s version 2.3.4.2
64-bit
% samtools --version
samtools 1.7
Using htslib 1.7-2
Copyright (C) 2018 Genome Research Ltd.
```
