samtools-reheader(1)
π samtools-reheader β bestie's guide to swapping headers π
okay so this is samtools-reheader, a page from the Bioinformatics tools manual set, and honestly? it's kind of a glow-up for your file's header. let's get into it β¨
π NAME
samtools reheader β replaces the header in the input file. that's it, that's the whole job. iconic behavior honestly.
π¦ SYNOPSIS
samtools reheader [-iP] [-c CMD | in.header.sam] in.bam
πΈ DESCRIPTION
so basically you're swapping the header in in.bam with the header from in.header.sam. and the way this is much faster than doing the whole BAMβSAMβBAM conversion thing? obsessed. that round-trip is a whole ordeal and this command just skips it entirely. no cap.
by default this command outputs the BAM or CRAM file to standard output (stdout), k? but for CRAM format files it has the option to do an in-place edit β like, reading and writing to the same file. main character energy fr.
β οΈ heads up bestie, there is no validity checking performed on the header. none. zero. it doesn't check that the header is suitable to use with the sequence data itself either. so likeβ¦ the vibes are trusting. you gotta be careful out there π
β¨ OPTIONS β¨
-P,--no-PGβ do not add a@PGline to the header of the output file. that's it. if you don't want the extra line, this is your girl.-i,--in-placeβ perform the header edit in-place, if possible. π«Ά and "if possible" is doing a lot of work here: this only works on CRAM files, and only if there is sufficient room to store the new header. the amount of space available will differ for each CRAM file. so it's giving β¨situationalβ¨.-c,--command CMDβ allow the header fromin.bamto be processed by an externalCMDand read back the result. when you use it this way, the external header filein.header.samhas to be omitted. can't have both, bestie.
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) β this is the part where things get messy if you're not careful, so double-check your quotes fr fr.
CMD must return an exit status of zero. that's a requirement, not a suggestion π
π EXAMPLES
- remove comment lines π§Ή
samtools reheader -c 'grep -v ^@CO' in.bam
- add "Chr" prefix to chromosome names β note the extra backslashes before dollar signs to prevent unwanted shell variable expansion. literally do not skip those backslashes π
samtools reheader -c 'perl -pe "s/^(@SQ.*)(\tSN:)(\d+|X|Y|MT)(\s|\$)/\$1Chr\$2\$3/"' in.bam
- remove "Chr" prefix β the reverse glow-down, we love a symmetry moment π
samtools reheader -c 'perl -pe "s/^(@SQ.*)(\tSN:)Chr/\$1\$2/"' in.bam
π AUTHOR
Written by Heng Li, with modifications by James Bonfield and Valeriu Ohan, all from the Sanger Institute. shoutout the squad π«Ά
π₯ SEE ALSO
samtools(1)- Samtools website: <http://www.htslib.org/>
β that's the whole page, bestie β this is from samtools-1.24, dated 9 July 2026. go forth and reheader responsibly π
β¨
π¦ where this page comes from
- epel 10: samtools 1.24-2.el10_3 Β· MIT
- nixpkgs unstable: samtools 1.24
- Copyright (C) 2008-2011, 2013-2019 Genome Research Ltd
- copyright (C) 2010, 2011 Broad Institute
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms