, printed on 04/18/2021
bamtofastq is a tool for converting 10x BAMs produced by cellranger, cellranger-atac, cellranger-arc, cellranger-dna, spaceranger or longranger back into FASTQ files that can be used as inputs to re-run analysis. The FASTQs will be emitted into a directory structure that is compatible with the directories created by the mkfastq tool.
Special tags included by 10x pipelines are required to reconstruct the original FASTQ sequences correctly. If your BAM file lacks the appropriate headers, you will get an error message: WARNING: no @RG (read group) headers found in BAM file.
A common problem is using an 'edited' BAM file from SRA, which are missing tags produced by Cell Ranger.
You need the BAM file from the section labelled 'Original Format' on the SRA downloads page. Here is an example of a SRA dataset with the 'Original Format' BAM available
Only the 'Original Format' BAM files have the necessary BAM tags preserved to work correctly with bamtofastq.
We created bamtofastq to help users who want to reanalyze 10x data and only have access to 10x BAM files. (e.g. Some customers want to store BAM files only. Others might have downloaded our BAM data from NCBI SRA). 10x pipelines require sequencer FASTQs (with embedded barcodes) as input. The location of the 10x barcode varies depending on product and reagent version. bamtofastq determines the appropriate way to construct the original read sequence from the sequences and tags in the BAM file.
bamtofastq is available for Linux and is compatible with RedHat/CentOS 5.2 or later, and Ubuntu 8.04 or later.
We recommend upgrading to bamtofastq 1.3.2—it is now multi-threaded and is compatible with Cell Ranger ATAC BAM files.
bamtofastq is a single executable that can be run directly and requires no compilation or installation. Place the executable file in a directory that is on your
PATH, and make sure to
chmod 700 to make it executable.
Note, MacOS versions of bamtofastq are available on the Github Page for bamtofastq
10x BAMs produced by Cell Ranger v1.2+, Cell Ranger ATAC v1.0+, Cell Ranger DNA v1.0+, and Long Ranger v2.1+ contain header fields that permit automatic conversion to the correct FASTQ sequences. BAMs produced by older 10x pipelines may require special arguments or have some caveats, see below for details. Run times for full-coverage WGS BAMs may be several hours.
The FASTQ files emitted by bamtofastq contain the same set of sequences that were input to the original pipeline run, although the original order will not be preserved. 10x pipelines are generally insensitive to the order of the input data, so you can expect nearly identical results when re-running with bamtofastq outputs.
The latest versions of cellranger, cellranger-atac, cellranger-dna and longranger generate BAM files that automatically reconstruct complete FASTQ files representing all input reads. BAMs produced by older versions of cellranger and longranger have some caveats, listed below:
|Package||Version||Pipelines||Extra Arguments||Complete FASTQs|
|Cell Ranger||1.2||count||none||Reads without a valid barcode will be absent from FASTQ. (These reads are ignored by Cell Ranger)|
|Cell Ranger||1.0-1.1||count||--cr11||Reads without a valid barcode will be absent from FASTQ. (These reads are ignored by Cell Ranger)|
|Cell Ranger ATAC||1.0.0+||count||none||Yes|
|Cell Ranger DNA||1.0.0+||cnv||none||Yes|
|Long Ranger||2.1.3+||wgs, targeted, align, basic||none||Yes|
|Long Ranger||2.1.0 - 2.1.2||wgs, targeted||none||Yes|
|Long Ranger||2.0||wgs, targeted||--lr20||Yes|
|Long Ranger||2.0.0 - 2.1.2||align, basic||Not Supported||N/A|
|Long Ranger||1.3 (GemCode)||wgs, targeted||--gemcode||Reads without a valid barcode will be absent from FASTQ. This will result in a ~5-10% loss of coverage.|