Usage
####### samtools reheader Usage
Usage: samtools reheader [-P] in.header.sam in.bam > out.bam
or samtools reheader [-P] -i in.header.sam file.bam
Options:
-P, --no-PG Do not generate an @PG header line.
-i, --in-place Modify the bam/cram file directly.
(Defaults to outputting to stdout.)
########## 注意 替换原内容的new_header格式必须是sam
实操流程
########## 原来的header
$ samtools view -H ETH_6h_rep2.sorted.REF_Chr1_2.bam|head
@HD VN:1.0 SO:coordinate
@SQ SN:Chr1_1 LN:399999920
@SQ SN:Chr1_2 LN:102330331
@SQ SN:Chr2_1 LN:399999920
@SQ SN:Chr2_2 LN:251661194
@SQ SN:Chr3_1 LN:399999920
@SQ SN:Chr3_2 LN:227182745
@SQ SN:Chr4_1 LN:399999920
@SQ SN:Chr4_2 LN:126018865
@SQ SN:Chr5_1 LN:399999920
################### 构建自己需要的header
$ samtools view -H ETH_6h_rep2.sorted.REF_Chr1_2.bam|grep '@'|grep 'Chr1_2' > old.sam
$ more old.sam
@SQ SN:Chr1_2 LN:102330331
########## 用samtools reheader 替换bam的heaer
$ samtools reheader -i old.sam ETH_6h_rep2.sorted.REF_Chr1_2.bam > out.bam
$ samtools view -H out.bam
@SQ SN:Chr1_2 LN:102330331
@PG ID:samtools PN:samtools VN:1.8 CL:samtools reheader -i old.sam ETH_6h_rep2.sorted.REF_Chr1_2.bam