samtools-split(1) | Bioinformatics tools | samtools-split(1) |
samtools-split - splits a file by read group.
samtools split [options] merged.sam|merged.bam|merged.cram
Splits a file by read group, or a specified tag, producing one or more output files matching a common prefix (by default based on the input filename).
Unless the -d option is used, the file will be split according to the @RG tags listed in the header. Records without an RG tag or with an RG tag undefined in the header will cause the program to exit with an error unless the -u option is used.
RG values defined in the header but with no records will produce an output file only containing a header.
If the -d TAG option is used, the file will be split on the value in the given aux tag. Note that only string tags (type Z) are currently supported. Unless the -u option is used, the program will exit with an error if it finds a record without the given tag.
Note that attempting to split on a tag with high cardinality may result in the creation of a large number of output files. To prevent this, the -M option can be used to set a limit on the number of splits made.
Using -d RG behaves in a similar way to the default (without -d), opening an output file for each @RG line in the header. However, unlike the default, new output files will be opened for any RG tags found in the alignment records irrespective of if they have a matching header @RG line.
The -u option may be used to specify the output filename for any records with a missing or unrecognised tag. This option will always write out a file even if there are no records.
Output format defaults to BAM. For SAM or CRAM then either set the format with --output-fmt or use -f to set the file extension e.g. -f %*_%#.sam.
If desired, the limit can be removed using -M -1, although in practice the number of outputs will still be restricted by system limits on the number of files that can be open at once.
If splitting by read group, and the read group count in the header is higher than the requested limit then the limit will be raised to match.
Format string expansions:
%% | % |
%* | basename |
%# | index (of @RG in the header, or count of TAG values seen so far) |
%! | @RG ID or TAG value |
%. | output format filename extension |
Written by Martin Pollard from the Sanger Institute.
samtools(1), samtools-addreplacerg(1)
Samtools website: <http://www.htslib.org/>
24 January 2024 | samtools-1.19.2 |