Failed to run bamqc net.sf.samtools.SAMFormatException: Error parsing SAM header. @RG line missing SM tag. Line: @RG

302 views
Skip to first unread message

Gabriel A. C. Gama

unread,
Apr 25, 2021, 1:12:52 PM4/25/21
to QualiMap
Hello everyone! I've been trying to run qualimap bamqc and RNAseq QC with my BAM files

To make sure I have no problems on processing previously to qualimap, I used STAR aligner to output SAM files (sorted by name) using ensembl reference and gtf.

Then I converted the SAM files to BAM with samtools (-fixmate) then sorted it by coordinate with samtools also. Finally, I indexed these sorted bam files.

Then, I tried:

qualimap --java-mem-size=16G bamqc -bam /home/samtools/sorted_ensembl/101_FRAS202421991-1a_1.fqAligned.out-sorted.bam -gff /home/references/ENSEMBL/star/Homo_sapiens.GRCh38.103.chr_patch_hapl_scaff.gtf -gd HUMAN -ip -nt 4 -p non-strand-specific -outdir /home/qualimap/bamqc -outfile BAMQC_ensembl.pdf

Which gives me this error:


Selected tool: bamqc
Available memory (Mb): 32
Max memory (Mb): 15271
Sun Apr 25 14:08:37 GMT-03:00 2021              WARNING Output folder already exists, the results will be saved there

Starting bam qc....
Failed to run bamqc
net.sf.samtools.SAMFormatException: Error parsing SAM header. @RG line missing SM tag. Line:
@RG     ID:GRPundef; File /home/samtools/sorted_ensembl/101_FRAS202421991-1a_1.fqAligned.out-sorted.bam; Line number 199
        at net.sf.samtools.SAMTextHeaderCodec.reportErrorParsingLine(SAMTextHeaderCodec.java:230)
        at net.sf.samtools.SAMTextHeaderCodec.access$100(SAMTextHeaderCodec.java:39)
        at net.sf.samtools.SAMTextHeaderCodec$ParsedHeaderLine.requireTag(SAMTextHeaderCodec.java:306)
        at net.sf.samtools.SAMTextHeaderCodec.parseRGLine(SAMTextHeaderCodec.java:160)
        at net.sf.samtools.SAMTextHeaderCodec.decode(SAMTextHeaderCodec.java:93)
        at net.sf.samtools.BAMFileReader.readHeader(BAMFileReader.java:393)
        at net.sf.samtools.BAMFileReader.<init>(BAMFileReader.java:146)
        at net.sf.samtools.BAMFileReader.<init>(BAMFileReader.java:114)
        at net.sf.samtools.SAMFileReader.init(SAMFileReader.java:514)
        at net.sf.samtools.SAMFileReader.<init>(SAMFileReader.java:167)
        at net.sf.samtools.SAMFileReader.<init>(SAMFileReader.java:122)
        at org.bioinfo.ngs.qc.qualimap.process.BamStatsAnalysis.run(BamStatsAnalysis.java:202)
        at org.bioinfo.ngs.qc.qualimap.main.BamQcTool.execute(BamQcTool.java:242)
        at org.bioinfo.ngs.qc.qualimap.main.NgsSmartTool.run(NgsSmartTool.java:190)
        at org.bioinfo.ngs.qc.qualimap.main.NgsSmartMain.main(NgsSmartMain.java:111)

I've observed the same error for all samples, in the same line

Konstantin Okonechnikov

unread,
Apr 26, 2021, 12:37:12 PM4/26/21
to qual...@googlegroups.com
Hi!

Seems to be the issue with header parsing. Could you perhaps share a small subsample from this BAM file (http://okko73313.blogspot.com/2013/03/random-subsample-from-bam-file.html)? Or at least the header to check it in detail.

Best regards,
   Konstantin

--
You received this message because you are subscribed to the Google Groups "QualiMap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qualimap+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qualimap/7f2e7136-2b82-4656-9f33-0d5b0ced3ac4n%40googlegroups.com.

Gabriel Gama

unread,
Apr 27, 2021, 9:08:34 PM4/27/21
to qual...@googlegroups.com
Hello Konstantin!
I transferred 5% of reads from one of the files:



--
Atenciosamente,

Gabriel A. C. Gama
Universidade Federal de São Paulo - UNIFESP
Laboratório Bases Genéticas dos Tumores da Tiroide
Rua Pedro de Toledo, 669 - 11º andar Vila Clementino São Paulo/SP - 04039-032
(11) 5576-4979 / (11) 999731226

Konstantin Okonechnikov

unread,
Apr 28, 2021, 12:51:23 PM4/28/21
to qual...@googlegroups.com
The issue was due to incorrectly formatted according to SAM format read group - the SM tag is missing: 
@RG     ID:GRPundef 

This happened due to dependence on picard library requirements for SAM parser. Simply removing it from header fixes the situation, since Qualimap does not require read group in the analysis. Something like this:
samtools view -h 101_random.bam | grep -v "^@RG" > 101_random.sam

Possible solution is to clean header and save to temporary BAM file, run Qualimap and then remove the file or fix the read group in the BAM file. 

Best regards,
   Konstantin


Gabriel A. C. Gama

unread,
May 31, 2021, 4:52:40 PM5/31/21
to QualiMap
This worked, and I got BAMqc to run just fine.
Reply all
Reply to author
Forward
0 new messages