Showing tool doc from version 4.6.2.0 | The latest version is
4.6.2.0

SamToFastq (Picard)

Converts a SAM/BAM/CRAM file to FASTQ.Extracts read sequences and qualities from the input SAM/BAM/CRAM file and writes them into the output file in Sanger FASTQ format. See MAQ FASTQ specification for details. This tool can be used by way of a pipe to run BWA MEM on unmapped BAM (uBAM) files efficiently.

In the RC mode (default is True), if the read is aligned and the alignment is to the reverse strand on the genome, the read's sequence from input SAM file will be reverse-complemented prior to writing it to FASTQ in order restore correctly the original read sequence as it was generated by the sequencer.

Note: This tool works with both coordinate-sorted and name-sorted inputs. Although mates come with the same order in both FASTQ files, the behavior is different between coordinate-sorted versus name-sorted BAM files. Name-sorted BAM files will produce the very same FASTQs generated from the sequencer, whereas coordinate-sorted BAMs will result in a scrambled FASTQ file where mates match but the reads are not sorted by name. This may result in slightly different outcomes when used with non-deterministic mappers such as BWA.


Usage example:

java -jar picard.jar SamToFastq 
I=input.bam
FASTQ=output.fastq

Category Read Data Manipulation


Overview

Extracts read sequences and qualities from the input SAM/BAM file and writes them into the output file in Sanger FASTQ format. See MAQ FASTQ specification for details. This tool can be used by way of a pipe to run BWA MEM on unmapped BAM (uBAM) files efficiently.

In the RC mode (default is True), if the read is aligned and the alignment is to the reverse strand on the genome, the read's sequence from input SAM file will be reverse-complemented prior to writing it to FASTQ in order restore correctly the original read sequence as it was generated by the sequencer.

Note: This tool works with both coordinate-sorted and name-sorted inputs. Although mates come with the same order in both FASTQ files, the behavior is different between coordinate-sorted versus name-sorted BAM files. Name-sorted BAM files will produce the very same FASTQs generated from the sequencer, whereas coordinate-sorted BAMs will result in a scrambled FASTQ file where mates match but the reads are not sorted by name. This may result in slightly different outcomes when used with non-deterministic mappers such as BWA.

Usage example:

 java -jar picard.jar SamToFastq \
     I=input.bam \
     FASTQ=output.fastq
 

SamToFastq (Picard) specific arguments

This table summarizes the command-line arguments that are specific to this tool. For more details on each argument, see the list further down below the table or click on an argument name to jump directly to that entry in the list.

Argument name(s) Default value Summary
Required Arguments
--FASTQ
 -F
Output FASTQ file (single-end fastq or, if paired, first end of the pair FASTQ).
--INPUT
 -I
Input SAM/BAM/CRAM file to extract reads from
Optional Tool Arguments
--arguments_file
read one or more arguments files and add them to the command line
--CLIPPING_ACTION
 -CLIP_ACT
The action that should be taken with clipped reads: 'X' means the reads and qualities should be trimmed at the clipped position; 'N' means the bases should be changed to Ns in the clipped region; and any integer means that the base qualities should be set to that value in the clipped region.
--CLIPPING_ATTRIBUTE
 -CLIP_ATTR
The attribute that stores the position at which the SAM record should be clipped
--CLIPPING_MIN_LENGTH
 -CLIP_MIN
0 When performing clipping with the CLIPPING_ATTRIBUTE and CLIPPING_ACTION parameters, ensure that the resulting reads after clipping are at least CLIPPING_MIN_LENGTH bases long. If the original read is shorter than CLIPPING_MIN_LENGTH then the original read length will be maintained.
--COMPRESS_OUTPUTS_PER_RG
 -GZOPRG
false Compress output FASTQ files per read group using gzip and append a .gz extension to the file names.
--help
 -h
false display the help message
--INCLUDE_NON_PF_READS
 -NON_PF
false Include non-PF reads from the SAM file into the output FASTQ files. PF means 'passes filtering'. Reads whose 'not passing quality controls' flag is set are non-PF reads. See GATK Dictionary for more info.
--INCLUDE_NON_PRIMARY_ALIGNMENTS
false If true, include non-primary alignments in the output. Support of non-primary alignments in SamToFastq is not comprehensive, so there may be exceptions if this is set to true and there are paired reads with non-primary alignments.
--INTERLEAVE
 -INTER
false Will generate an interleaved fastq if paired, each line will have /1 or /2 to describe which end it came from
--OUTPUT_DIR
 -ODIR
Directory in which to output the FASTQ file(s). Used only when OUTPUT_PER_RG is true.
--OUTPUT_PER_RG
 -OPRG
false Output a FASTQ file per read group (two FASTQ files per read group if the group is paired).
--QUALITY
 -Q
End-trim reads using the phred/bwa quality trimming algorithm and this quality.
--RE_REVERSE
 -RC
true Re-reverse bases and qualities of reads with negative strand flag set before writing them to FASTQ
--READ1_MAX_BASES_TO_WRITE
 -R1_MAX_BASES
The maximum number of bases to write from read 1 after trimming. If there are fewer than this many bases left after trimming, all will be written. If this value is null then all bases left after trimming will be written.
--READ1_TRIM
 -R1_TRIM
0 The number of bases to trim from the beginning of read 1.
--READ2_MAX_BASES_TO_WRITE
 -R2_MAX_BASES
The maximum number of bases to write from read 2 after trimming. If there are fewer than this many bases left after trimming, all will be written. If this value is null then all bases left after trimming will be written.
--READ2_TRIM
 -R2_TRIM
0 The number of bases to trim from the beginning of read 2.
--RG_TAG
 -RGT
PU The read group tag (PU or ID) to be used to output a FASTQ file per read group.
--SECOND_END_FASTQ
 -F2
Output FASTQ file (if paired, second end of the pair FASTQ).
--UNPAIRED_FASTQ
 -FU
Output FASTQ file for unpaired reads; may only be provided in paired-FASTQ mode
--version
false display the version number for this tool
Optional Common Arguments
--COMPRESSION_LEVEL
5 Compression level for all compressed files created (e.g. BAM and VCF).
--CREATE_INDEX
false Whether to create an index when writing VCF or coordinate sorted BAM output.
--CREATE_MD5_FILE
false Whether to create an MD5 digest for any BAM or FASTQ files created.
--MAX_RECORDS_IN_RAM
500000 When writing files that need to be sorted, this will specify the number of records stored in RAM before spilling to disk. Increasing this number reduces the number of file handles needed to sort the file, and increases the amount of RAM needed.
--QUIET
false Whether to suppress job-summary info on System.err.
--REFERENCE_SEQUENCE
 -R
Reference sequence file.
--TMP_DIR
One or more directories with space available to be used by this program for temporary storage of working files
--USE_JDK_DEFLATER
 -use_jdk_deflater
false Use the JDK Deflater instead of the Intel Deflater for writing compressed output
--USE_JDK_INFLATER
 -use_jdk_inflater
false Use the JDK Inflater instead of the Intel Inflater for reading compressed input
--VALIDATION_STRINGENCY
STRICT Validation stringency for all SAM files read by this program. Setting stringency to SILENT can improve performance when processing a BAM file in which variable-length data (read, qualities, tags) do not otherwise need to be decoded.
--VERBOSITY
INFO Control verbosity of logging.
Advanced Arguments
--showHidden
false display hidden arguments

Argument details

Arguments in this list are specific to this tool. Keep in mind that other arguments are available that are shared with other tools (e.g. command-line GATK arguments); see Inherited arguments above.


--arguments_file

read one or more arguments files and add them to the command line

List[File]  []


--CLIPPING_ACTION / -CLIP_ACT

The action that should be taken with clipped reads: 'X' means the reads and qualities should be trimmed at the clipped position; 'N' means the bases should be changed to Ns in the clipped region; and any integer means that the base qualities should be set to that value in the clipped region.

String  null


--CLIPPING_ATTRIBUTE / -CLIP_ATTR

The attribute that stores the position at which the SAM record should be clipped

String  null


--CLIPPING_MIN_LENGTH / -CLIP_MIN

When performing clipping with the CLIPPING_ATTRIBUTE and CLIPPING_ACTION parameters, ensure that the resulting reads after clipping are at least CLIPPING_MIN_LENGTH bases long. If the original read is shorter than CLIPPING_MIN_LENGTH then the original read length will be maintained.

int  0  [ [ -∞  ∞ ] ]


--COMPRESS_OUTPUTS_PER_RG / -GZOPRG

Compress output FASTQ files per read group using gzip and append a .gz extension to the file names.

Exclusion: This argument cannot be used at the same time as FASTQ, SECOND_END_FASTQ, UNPAIRED_FASTQ.

Boolean  false


--COMPRESSION_LEVEL

Compression level for all compressed files created (e.g. BAM and VCF).

int  5  [ [ -∞  ∞ ] ]


--CREATE_INDEX

Whether to create an index when writing VCF or coordinate sorted BAM output.

Boolean  false


--CREATE_MD5_FILE

Whether to create an MD5 digest for any BAM or FASTQ files created.

boolean  false


--FASTQ / -F

Output FASTQ file (single-end fastq or, if paired, first end of the pair FASTQ).

Exclusion: This argument cannot be used at the same time as OUTPUT_PER_RG, COMPRESS_OUTPUTS_PER_RG, OUTPUT_DIR.

R File  null


--help / -h

display the help message

boolean  false


--INCLUDE_NON_PF_READS / -NON_PF

Include non-PF reads from the SAM file into the output FASTQ files. PF means 'passes filtering'. Reads whose 'not passing quality controls' flag is set are non-PF reads. See GATK Dictionary for more info.

boolean  false


--INCLUDE_NON_PRIMARY_ALIGNMENTS

If true, include non-primary alignments in the output. Support of non-primary alignments in SamToFastq is not comprehensive, so there may be exceptions if this is set to true and there are paired reads with non-primary alignments.

boolean  false


--INPUT / -I

Input SAM/BAM/CRAM file to extract reads from

R File  null


--INTERLEAVE / -INTER

Will generate an interleaved fastq if paired, each line will have /1 or /2 to describe which end it came from

boolean  false


--MAX_RECORDS_IN_RAM

When writing files that need to be sorted, this will specify the number of records stored in RAM before spilling to disk. Increasing this number reduces the number of file handles needed to sort the file, and increases the amount of RAM needed.

Integer  500000  [ [ -∞  ∞ ] ]


--OUTPUT_DIR / -ODIR

Directory in which to output the FASTQ file(s). Used only when OUTPUT_PER_RG is true.

Exclusion: This argument cannot be used at the same time as FASTQ.

File  null


--OUTPUT_PER_RG / -OPRG

Output a FASTQ file per read group (two FASTQ files per read group if the group is paired).

Exclusion: This argument cannot be used at the same time as FASTQ, SECOND_END_FASTQ, UNPAIRED_FASTQ.

boolean  false


--QUALITY / -Q

End-trim reads using the phred/bwa quality trimming algorithm and this quality.

Integer  null


--QUIET

Whether to suppress job-summary info on System.err.

Boolean  false


--RE_REVERSE / -RC

Re-reverse bases and qualities of reads with negative strand flag set before writing them to FASTQ

boolean  true


--READ1_MAX_BASES_TO_WRITE / -R1_MAX_BASES

The maximum number of bases to write from read 1 after trimming. If there are fewer than this many bases left after trimming, all will be written. If this value is null then all bases left after trimming will be written.

Integer  null


--READ1_TRIM / -R1_TRIM

The number of bases to trim from the beginning of read 1.

int  0  [ [ -∞  ∞ ] ]


--READ2_MAX_BASES_TO_WRITE / -R2_MAX_BASES

The maximum number of bases to write from read 2 after trimming. If there are fewer than this many bases left after trimming, all will be written. If this value is null then all bases left after trimming will be written.

Integer  null


--READ2_TRIM / -R2_TRIM

The number of bases to trim from the beginning of read 2.

int  0  [ [ -∞  ∞ ] ]


--REFERENCE_SEQUENCE / -R

Reference sequence file.

PicardHtsPath  null


--RG_TAG / -RGT

The read group tag (PU or ID) to be used to output a FASTQ file per read group.

String  PU


--SECOND_END_FASTQ / -F2

Output FASTQ file (if paired, second end of the pair FASTQ).

Exclusion: This argument cannot be used at the same time as OUTPUT_PER_RG, COMPRESS_OUTPUTS_PER_RG.

File  null


--showHidden / -showHidden

display hidden arguments

boolean  false


--TMP_DIR

One or more directories with space available to be used by this program for temporary storage of working files

List[File]  []


--UNPAIRED_FASTQ / -FU

Output FASTQ file for unpaired reads; may only be provided in paired-FASTQ mode

Exclusion: This argument cannot be used at the same time as OUTPUT_PER_RG, COMPRESS_OUTPUTS_PER_RG.

File  null


--USE_JDK_DEFLATER / -use_jdk_deflater

Use the JDK Deflater instead of the Intel Deflater for writing compressed output

Boolean  false


--USE_JDK_INFLATER / -use_jdk_inflater

Use the JDK Inflater instead of the Intel Inflater for reading compressed input

Boolean  false


--VALIDATION_STRINGENCY

Validation stringency for all SAM files read by this program. Setting stringency to SILENT can improve performance when processing a BAM file in which variable-length data (read, qualities, tags) do not otherwise need to be decoded.

The --VALIDATION_STRINGENCY argument is an enumerated type (ValidationStringency), which can have one of the following values:

STRICT
LENIENT
SILENT

ValidationStringency  STRICT


--VERBOSITY

Control verbosity of logging.

The --VERBOSITY argument is an enumerated type (LogLevel), which can have one of the following values:

ERROR
WARNING
INFO
DEBUG

LogLevel  INFO


--version

display the version number for this tool

boolean  false


Return to top


See also General Documentation | Tool Docs Index Tool Documentation Index | Support Forum

GATK version 4.6.2.0 built at Sun, 13 Apr 2025 13:21:43 -0400.