How Can I Edit Some Rows In .Bam Header File?
1
4
Entering edit mode
13.5 years ago
Hmm ▴ 500

For example i have the following already in the bam header:

@RG    ID:110131_SN107_0398_A81DDCABXX_LANE2    PL:ILLUMINA    LB:P0007    SM:tumor
@RG    ID:110131_SN107_0398_A81DDCABXX_LANE4    PL:ILLUMINA    LB:P0007    SM:tumor
@RG    ID:110131_SN107_0398_A81DDCABXX_LANE6    PL:ILLUMINA    LB:P0007    SM:tumor
@RG    ID:110131_SN107_0398_A81DDCABXX_LANE8    PL:ILLUMINA    LB:P0007    SM:tumor
@RG    ID:110131_SN107_0399_B81CYUABXX_LANE2    PL:ILLUMINA    LB:P0007    SM:tumor
@RG    ID:110131_SN107_0399_B81CYUABXX_LANE4    PL:ILLUMINA    LB:P0007    SM:tumor
@RG    ID:110131_SN107_0399_B81CYUABXX_LANE6    PL:ILLUMINA    LB:P0007    SM:tumor
@RG    ID:110131_SN107_0399_B81CYUABXX_LANE8    PL:ILLUMINA    LB:P0007    SM:tumor

i want to make it:

@RG    ID:110131_SN107_0398_A81DDCABXX_LANE2    PL:ILLUMINA    LB:tumor_P0007    SM:tumor
@RG    ID:110131_SN107_0398_A81DDCABXX_LANE4    PL:ILLUMINA    LB:tumor_P0007    SM:tumor
@RG    ID:110131_SN107_0398_A81DDCABXX_LANE6    PL:ILLUMINA    LB:tumor_P0007    SM:tumor
@RG    ID:110131_SN107_0398_A81DDCABXX_LANE8    PL:ILLUMINA    LB:tumor_P0007    SM:tumor
@RG    ID:110131_SN107_0399_B81CYUABXX_LANE2    PL:ILLUMINA    LB:tumor_P0007    SM:tumor
@RG    ID:110131_SN107_0399_B81CYUABXX_LANE4    PL:ILLUMINA    LB:tumor_P0007    SM:tumor
@RG    ID:110131_SN107_0399_B81CYUABXX_LANE6    PL:ILLUMINA    LB:tumor_P0007    SM:tumor
@RG    ID:110131_SN107_0399_B81CYUABXX_LANE8    PL:ILLUMINA    LB:tumor_P0007    SM:tumor

Thanks.

samtools bam • 17k views
ADD COMMENT
3
Entering edit mode
samtools view -H inputfile.bam | sed -e 's/ID:XXX:/ID:21Normal/' | sed -e 's/SM:XXX/SM:21Normal/' | samtools reheader - inputfile.bam > outbamfile.reheadered.bam

This command just change header file , Do you have any Idea How can I change ID in complete .bam file rather to just change in header. I know samtools merge command to change R:Z: in reads but It occupies extra space and very time consuming. Above command is fast but It just change ID in header not in complete .bam file. I like to change R:Z: with R:Z:XXX

ADD REPLY
25
Entering edit mode
13.5 years ago
samtools view -H mybamfile.bam | sed -e 's/LB:/LB:tumor_/' | samtools reheader - mybamfile.bam > mybamfile.reheadered.bam
ADD COMMENT
3
Entering edit mode

Smooth!

In my case I just need to add a g, global, after the substitution pattern:

sed -e 's/LB:/LB:tumor_/g'
ADD REPLY
2
Entering edit mode

can any one tell me how to change two columns? for example the same change in LB column and totally replacing "tumor" with "cancer" in SM column! thanks a lot. I'm not familiar with sed! is what I wrote correct?

code:

samtools view -H mybamfile.bam | sed -e 's/LB:/LB:tumor_/' | sed -e 's/SM:tumor/SM:cancer/' | samtools reheader - mybamfile.bam > mybamfile.reheadered.bam
ADD REPLY

Login before adding your answer.

Traffic: 2002 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