This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How To Delete Some Rgs From One Bam File

Dear all, Before I only one sample in my analysis, but when I merge the bam file from different lane, I used the different RG. Just like the following:

@RG ID:Ptrem PL:ILLUMINA LB:Ptrem SM:Ptrem

@RG ID:PtPE14c PL:ILLUMINA LB:PtPE14c SM:PtPE14c

@RG ID:PtPE14d PL:ILLUMINA LB:PtPE14d SM:PtPE14d

@RG ID:PtPE15 PL:ILLUMINA LB:PtPE15 SM:PtPE15

@RG ID:PtPE16 PL:ILLUMINA LB:PtPE16 SM:PtPE16

@RG ID:PtPE1a PL:ILLUMINA LB:PtPE1a SM:PtPE1a

@RG ID:PtPE1a1 PL:ILLUMINA LB:PtPE1a1 SM:PtPE1a1

@RG ID:PtPE1a2 PL:ILLUMINA LB:PtPE1a2 SM:PtPE1a2

Now, I want to delete some RG from the BAM file. How could I do that? I just want to have onely one RG in the right BAM file.

3 answers

picard tools addOrReplaceReadgroups

From the documentation:

Replaces all read groups in the INPUT file with a new read group and assigns all reads to this read group in the OUTPUT BAMVersion: 1.0

Hi Irsan, I used the command: java -Xmx10g -jar /usr/local/bin/picard-tools-1.66/AddOrReplaceReadGroups.jar \ INPUT=new.sort.reheadered3.bam \ OUTPUT=new.sort.RG.bam \ SORT_ORDER=coordinate \ RGID=Ptrem \ RGLB=Ptrem \ RGPL=illumina \ RGPU=C063JACXX.6 RGSM=Ptrem

But I got the error: [Sun Sep 22 13:16:52 CDT 2013] net.sf.picard.sam.AddOrReplaceReadGroups done. Elapsed time: 0.02 minutes. Runtime.totalMemory()=1519058944 FAQ: http://sourceforge.net/apps/mediawiki/picard/index.php?title=Main_Page Exception in thread "main" net.sf.samtools.SAMFormatException: SAM validation error: ERROR: Record 683, Read name HWI-ST261:1:28:18847:188777#ATCACG, RG ID on SAMRecord not found in header: Ptrem1

    at net.sf.samtools.SAMUtils.processValidationErrors(SAMUtils.java:448)

    at net.sf.samtools.BAMFileReader$BAMFileIterator.advance(BAMFileReader.java:506)

    at net.sf.samtools.BAMFileReader$BAMFileIterator.next(BAMFileReader.java:487)

    at net.sf.samtools.BAMFileReader$BAMFileIterator.next(BAMFileReader.java:446)

    at net.sf.samtools.SAMFileReader$AssertableIterator.next(SAMFileReader.java:641)

    at net.sf.samtools.SAMFileReader$AssertableIterator.next(SAMFileReader.java:619)

    at net.sf.picard.sam.AddOrReplaceReadGroups.doWork(AddOrReplaceReadGroups.java:91)

    at net.sf.picard.cmdline.CommandLineProgram.instanceMain(CommandLineProgram.java:177)

    at net.sf.picard.cmdline.CommandLineProgram.instanceMainWithExit(CommandLineProgram.java:119)

    at net.sf.picard.sam.AddOrReplaceReadGroups.main(AddOrReplaceReadGroups.java:61)

What is the problem!

Thanks!

ZQ

Hmm well just as the error message says, it seems there is a read with a read group ID that is not in your header. Maybe you can add VALIDATION_STRINGENCY=LENIENT (or even VALIDATION_STRINGENCY=SILENT) to your command to ignore the error and continue to replace the read group info

I wrote a tool name samjs: you can filter a BAM using a javascript expression: https://github.com/lindenb/jvarkit#samjs-filtering-a-sambam-file-with-javascript

$ curl -s "ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/phase1/data/HG00096/exome_alignment/HG00096.mapped.illumina.mosaik.GBR.exome.20110411.bam" |\
java -jar dist/samjs.jar SE='record.readGroup.id!="SRR081241" > result.bam

Log in to answer this question.