samtools-reheader(1) | Bioinformatics tools | samtools-reheader(1) |
samtools-reheader - replaces the header in the input file
samtools reheader [-iP] [-c CMD | in.header.sam ] in.bam
Replace the header in in.bam with the header in in.header.sam. This command is much faster than replacing the header with a BAM→SAM→BAM conversion.
By default this command outputs the BAM or CRAM file to standard output (stdout), but for CRAM format files it has the option to perform an in-place edit, both reading and writing to the same file. No validity checking is performed on the header, nor that it is suitable to use with the sequence data itself.
CMD must take the original header through stdin in SAM format and output the modified header to stdout. CMD is passed to the system's command shell. Care should be taken to ensure the command is quoted correctly to avoid unwanted shell expansions (for example of $ variables).
CMD must return an exit status of zero.
samtools reheader -c 'grep -v ^@CO' in.bam
samtools reheader -c 'perl -pe "s/^(@SQ.*)(\tSN:)(\d+|X|Y|MT)(\s|\$)/\$1Chr\$2\$3/"' in.bam
samtools reheader -c 'perl -pe "s/^(@SQ.*)(\tSN:)Chr/\$1\$2/"' in.bam
Written by Heng Li with modifications by James Bonfield and Valeriu Ohan, all from the Sanger Institute.
Samtools website: <http://www.htslib.org/>
2 September 2022 | samtools-1.16.1 |