Question: Error parsing SAM header. @RG line missing SM tag
0
gravatar for kwangchol.mun
3.0 years ago by
kwangchol.mun10 wrote:

I have a bam file called test.bam with malformed @RG line. @RG line has only one parameter as following:

@RG ID:foo

I want to add the parameters like SM, LB, PL to @RG line, but I have difficulties to do it.

I already tried with samtools as following:

samtools view -H test.bam | sed 's,^@PG.*,@PG\tID:None\tSM:None\tLB:None\tPL:Illumina,g' |  samtools reheader - test.bam > test.rg.bam

However, It gives an error like this:

[E::sam_hdr_error] Missing tab at line 198: "@PGtID:NonetSM:NonetLB:NonetPL:Illumina"

I also tried picard with AddOrReplaceReadGroups function, but it also replied with errors!

java -jar picard.jar AddOrReplaceReadGroups I=test.bam O=test.out.bam RGID=4 RGLB=lib1 RGPL=illumina RGPU=unit1 RGSM=20

Exception in thread "main" htsjdk.samtools.SAMFormatException: Error parsing SAM header. @RG line missing SM tag. Line: @RG ID:foo

Please help!

Thank you in advance

ADD COMMENTlink modified 3.0 years ago • written 3.0 years ago by kwangchol.mun10
1

Thank you! samtools command does not work but the VALIDATION_STRINGENCY=LENIENT option works! Cheers

ADD REPLYlink written 3.0 years ago by kwangchol.mun10
2
gravatar for Pierre Lindenbaum
3.0 years ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum131k wrote:

in picard/htsjdk RG must have another tag than ID, the separator is the tabulation.

try to fix this with:

samtools -h view in.bam | sed 's/^\(@RG\tID:.*\)/\1\tSM:foo/' | samtools view -b -o out.bam -
ADD COMMENTlink written 3.0 years ago by Pierre Lindenbaum131k
4

another option: use AddOrReplaceReadGroups with the option VALIDATION_STRINGENCY=LENIENT

ADD REPLYlink written 3.0 years ago by Pierre Lindenbaum131k
1

Sorry about the off-topic comment but you crossed 100K points landmark today. WooHoo!

ADD REPLYlink modified 3.0 years ago • written 3.0 years ago by genomax91k
1

not really :-) Pierre Lindenbaum 99550

ADD REPLYlink written 3.0 years ago by Pierre Lindenbaum131k

Upward rounding of the BioStars code already put you at 100K :-)

ADD REPLYlink written 3.0 years ago by genomax91k

I edited several (multi-readgroup) BAM file SM tags this way. After reindexing them, they seem to work fine, ie. I can open them in IGV without errors. However, when I use Picard ValidateSamFile I get the following error:

## HISTOGRAM    java.lang.String
Error Type      Count
ERROR:INVALID_INDEX_FILE_POINTER        1

I thought this wasn't a big deal, because they open fine. However, when I try to use other GATK tools to further process these files I'm often given an error like:

htsjdk.samtools.util.RuntimeIOException: my.bam has invalid uncompressedLength: -1998504602
    at htsjdk.samtools.util.BlockCompressedInputStream.inflateBlock(BlockCompressedInputStream.java:543)
        ...
        at org.broadinstitute.hellbender.Main.main(Main.java:289)

or

htsjdk.samtools.SAMFormatException: Invalid GZIP header
        at htsjdk.samtools.util.BlockGunzipper.unzipBlock(BlockGunzipper.java:121)
        ...
        at org.broadinstitute.hellbender.Main.main(Main.java:289)

Is there anything else I can do to fix this other than regenerate the BAMs from source?

ADD REPLYlink written 23 months ago by floris.barthel40

hi! I also have the same problem: htsjdk.samtools.util.RuntimeIOException: my.bam has invalid uncompressedLength

Have you finally solved this problem? and how do you solve it? thanks

ADD REPLYlink written 18 months ago by jtzheng2220

This is because the .bam.bai does not correspond to the bam file. After you change the @RG tag of BAM, you need to re-build the index, such as:

samtools index xx.bam

good luck!

ADD REPLYlink written 7 months ago by xuyao1592740289710

Any ideas anyone? Pierre Lindenbaum ? Using samtools reheader + sed to change the SM tag for multiple readgroups at once (something that I dont' think is possible with AddOrReplaceReadGroups) is a very elegant solution but if GATK complains about an invalid file it's not a viable one.

ADD REPLYlink written 23 months ago by floris.barthel40
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 813 users visited in the last hour