Category

Sam/Bam Manipulation


Usage

bedtools bamtofastq [OPTIONS] -i <BAM> -fq <FASTQ>


Manual

This tool is part of the bedtools suite.

Required Arguments

  • -i <BAM>: input bam file
  • -fq <FASTQ>: output fastq file. For paired-end libraries, this should be the name for end/read 1.

Options

  • -fq2: FASTQ for second end/mate. Used if BAM contains paired-end data. BAM should be sorted by query name (with samtools sort) is creating paired FASTQ.
  • -tags: Create FASTQ based on the mate info in the BAM R2 and Q2 tags.

Note: The two commands bedtools bamtofastq and bamToFastq are identical.

Examples

Convert a paired-end bam library to fastq files

If your BAM alignments are from paired-end sequence data, one can use the -fq2 option to create two distinct FASTQ output files: one for end/read 1 and one for end/read 2.

$ bedtools bamtofastq -i x.bam -fq read1.fq -fq2 read2.fq
Convert a paired-end bam library to one fastq file

If you want to create a single, interleaved FASTQ file for paired-end data, you can just write both to /dev/stdout:

$ bedtools bamtofastq -i x.bam -fq /dev/stdout -fq2 /dev/stdout > x.ilv.fq

Also, the samtools fastq command has more fucntionality and is a useful alternative.

File formats this tool works with
BAM

Share your experience or ask a question