add sample name to bam header based on bam file name
1
1
Entering edit mode
3.8 years ago
Ana ▴ 200

I have a group of bam files but some of them do not have sample name SM in @RG,

example: sample1.gh37.bam

@RG     ID:13048        CN:BCCAGSC      LB:NA   PL:illumina     PU:NA   SM:N/A

I want to add the file name (but without "gh37.bam" suffix) to SM , to get something like this

@RG     ID:13048        CN:BCCAGSC      LB:NA   PL:illumina     PU:NA   SM:sample1

Any help how I can do it

samtools • 6.5k views
ADD COMMENT
0
Entering edit mode
3.8 years ago

picard AddOrReplaceReadGroups https://broadinstitute.github.io/picard/command-line-overview.html#AddOrReplaceReadGroups or samtools addreplacerg

ADD COMMENT
1
Entering edit mode
for file in *.bam; do
base_name=$(basename $file .grch37.bam);
samtools addreplacerg -r "SM:${base_name}" -o ${base_name}.bam $file;
done

Already using this but I get The supplied RG line lacks an ID ta error

ADD REPLY
0
Entering edit mode

option -r "ID:xxxx" is required.

ADD REPLY
0
Entering edit mode

I do not want to change the ID, its the same. How can I adjust it?

ADD REPLY
1
Entering edit mode

http://www.htslib.org/doc/samtools-addreplacerg.html

-R STRING Allows you to specify the read group ID of an existing @RG line and applies it to the reads specified.

ADD REPLY

Login before adding your answer.

Traffic: 1848 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6