The hyphen "-" character is commonly used as a placeholder in Unix commands to represent the standard input (stdin) or standard output (stdout) streams. From the POSIX specification:
Guideline 13:
For utilities that use operands to represent files to be opened for
either reading or writing, the '-' operand should be used to mean only
standard input (or standard output when it is clear from context that
an output file is being specified) or a file named -.
In your pipeline, the hyphen after the index file name indicates that the output of the bwa mem
command should be piped to samtools view
, which will then read it from the standard input stream. The hyphen after the samtools sort
command, is not strictly necessary since an input SAM/BAM/CRAM is entirely optional. Note that recent versions of samtools
let you coordinate sort the SAM and write a sorted BAM, so you can do away with the call to samtools view
entirely. For example:
set -euo pipefail
bwa mem \
../01.data/GCF_000146045.2_R64_genomic.fna \
"../01.data/${sra}_1.fastq.gz" \
"../01.data/${sra}_2.fastq.gz" |
samtools sort \
-o "${sra}.sorted.bam"
samtools index \
"${sra}.sorted.bam"
If you wanted to, you could replace the hyphens with the /dev/stdin
special file, which represents the standard input streams. Sometimes this can make more complex commands a bit more readable, but note that not all Unix systems support the /dev/stdin
and /dev/stdout
special files. Most modern Unix systems do however.
The above uses set -eo pipefail
to ensure pipeline errors are not masked. This exits immediately if any command in the pipeline exits with a non-zero status.