I have two BAM files that have a different sample in read group (@RG) section. I would like the sample to be the same. How can I quickly modify the sample of the read group in a BAM file, so the merge BAM file has a single sample?
I have two BAM files that have a different sample in read group (@RG) section. I would like the sample to be the same. How can I quickly modify the sample of the read group in a BAM file, so the merge BAM file has a single sample?
Try this command on bam file where you want to change the sample name. Oldname is the present sample name and the Newname is the correct sample name. Once done with this step then you can use Picard MergeSam to merge your files. This command is similar to Pierre but is a single step process.
samtools view -H $BAM | sed "s/SM:Oldname/SM:Newname/" | samtools reheader - $BAM
I would dump the header
samtools view -H the1.bam > header.txt
edit the header and change the sample in the header for each group-id
and re-insert the header:
samtools reheader header.txt the1.bam
and then merge the1.bam
and the2.bam
with picard MergeSamFiles
Use picard tools AddOrReplaceReadGroups
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Is there an API that I can use to accomplish the task to renaming the sample in the header?
just use awk ?