How to change SM tag in bam file
I have a bam file with header such like this:
@RG ID:S1-L001 LB:L001 PL:Illumina SM:L001 PU:novaSeq
@RG ID:S1-L002 LB:L002 PL:Illumina SM:L002 PU:novaSeq
This bam file was generated by picard MergeSamFiles where one sample library was sequenced in two lanes (L001, L002) but I need to correct the SM tag to a single library name such like:
@RG ID:S1-L001 LB:L001 PL:Illumina SM:S1 PU:novaSeq
@RG ID:S1-L002 LB:L002 PL:Illumina SM:S1 PU:novaSeq
What I tried
samtools view -H abc.bam > header.sam
and manually edit the SM tages in header.sam and reheader using samtools:
samtools reheader header.sam abc.bam
But the terminal printed out unrecogniziable characters and I thought something went wrong. Any suggestions?
• 7,720 views
•
link
1 answer
reheader produces a new bam file with the altered header. In your command, it is send to stdout, and as bam is a compressed/non human-readable format, it looks weird on screen.
samtools reheader header.sam abc.bam > abc_reheadered.bam
• 0 views
•
link
Log in to answer this question.