Question: How to change SM tag in bam file
gravatar for ddzhangzz
18 months ago by
United States
ddzhangzz90 wrote:

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?

next-gen • 1.7k views
ADD COMMENTlink modified 18 months ago by ATpoint28k • written 18 months ago by ddzhangzz90
gravatar for ATpoint
18 months ago by
ATpoint28k wrote:

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
ADD COMMENTlink modified 18 months ago • written 18 months ago by ATpoint28k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2019 users visited in the last hour