4
10
Entering edit mode
10.2 years ago

Greetings all,

Let me start by saying I know how to add read groups to a BAM file. What I am looking for is the easiest way to do it. This problem has been around for a while so I though I would see what neat tricks people are using.

Thanks

bam gatk samtools bwa • 45k views
16
Entering edit mode
10.2 years ago
Matteo ▴ 220

In my opinion the easy way to do is using AddOrReplaceReadGroups in Picard:

1
Entering edit mode

What parameter would you use for these options (mandatory) in AddOrReplaceReadGroups

LB=String    Read Group Library  Required.
PU=String    Read Group platform unit (eg. run barcode)  Required.
SM=String    Read Group sample name  Required.

6
Entering edit mode
10.2 years ago
Rm 8.2k

See this.

The library information of each read group is kept in rg.txt

perl -e 'print "@RG\tID:ga\tSM:hs\tLB:ga\tPL:Illumina\n@RG\tID:454\tSM:hs\tLB:454\tPL:454\n"' > rg.txt
samtools merge -rh rg.txt - ga.bam 454.bam | samtools rmdup - - | samtools rmdup -s - aln.bam


Some discussion over here.

How can I tell if my BAM file has read group and sample information

1
Entering edit mode

I think this solution is invalid.

1. you need to escape @ character, so it would be at least:

perl -e 'print "\@RG\tID:ga\tSM:hs\tLB:ga\tPL:Illumina\n\@RG\tID:454\tSM:hs\tLB:454\tPL:454\n"' > rg.txt

2. The second problem is that the line defined only the header and -r flag will assign readgroups by filenames - in this case ga and 454. Related question I asked to find a neat solution is here

0
Entering edit mode

Thanks for the note on escaping the @ character...was really confused

0
Entering edit mode

Could you please explain these two commands.

Can i use the same rg.txt in my libraries. Or i need to replace them. Not sure by what ?

In second command, why there are two bam ?

2
Entering edit mode
2.4 years ago
sagitaninta ▴ 20

I know this question is years ago, but I just want to add that there is bamaddrg as part of bamtools that has really straightforward usage: http://github.com/ekg/bamaddrg

0
Entering edit mode
14 months ago
Gregor Rot ▴ 520

Should samtools be able to do this: http://www.htslib.org/doc/samtools-addreplacerg.html