This pipeline converts (un)mapped .bam files into fq.gz files. Initially, it auto-detects, whether the input file contains single-end or paired-end reads. Following this step, the reads are sorted using samtools collate and extracted with samtools fastq. Furthermore, for mapped bam files it is possible to only convert reads mapping to a specific region or chromosome. The obtained FastQ files can then be used to further process with other pipelines.

The pipeline is built using Nextflow, a workflow tool to run tasks across multiple compute infrastructures in a very portable manner. It comes with docker containers making installation trivial and results highly reproducible.

Quick Start

i. Install nextflow

ii. Install one of docker, singularity or conda

iii. Download the pipeline and test it on a minimal dataset with a single command

nextflow run qbic-pipelines/bamtofastq -profile test,<docker/singularity/conda>

iv. Start running your own analysis!

nextflow run qbic-pipelines/bamtofastq -profile <docker/singularity/conda> --input '*.bam'

See usage docs for all of the available options when running the pipeline.


The qbic-pipelines/bamtofastq pipeline comes with documentation about the pipeline, found in the docs/ directory:

  1. Installation
  2. Pipeline configuration
  3. Running the pipeline
  4. Output and how to interpret the results
  5. Troubleshooting


qbic-pipelines/bamtofastq was originally written by Friederike Hanssen.

This pipeline was created using the nf-core framework and still uses some of its underlying infrastructure. For more information see

Helpful contributors:


The individual steps of this pipeline are based of on the following tutorials and resources:

  1. Extracting paired FASTQ read data from a BAM mapping file
  2. Check if BAM is derived from pair-end or single-end reads

Contributions and Support

If you would like to contribute to this pipeline, please see the contributing guidelines.

For further information or help, don’t hesitate to get in touch by opening an issue.


If you use qbic-pipelines/bamtofastq for your analysis, please cite it using the following doi: 10.5281/zenodo.4022137