Minimap2: Error : missing SAM header while using samtools flagstat

Created on 31 May 2018  路  5Comments  路  Source: lh3/minimap2

I have aligned reads obtained from an ONT MinION run, base-called with Albacore using minimap2 to the reference genome. When I use samtools flagstat to get the statistics of the alignment, the following error appears :

[E::sam_parse1] missing SAM header
[W::sam_read1] Parse error at line 2
[bam_flagstat_core] Truncated file? Continue anyway.

I have also tried converting the sam file to bam, it halts midway and gives the same error. It would be of great help if I could get this issue resolved. Thanks in advance!

Best,
A

duplicate question

Most helpful comment

You are probably aligning against a "multi-part" index. In this case, minimap2 is unable to output a proper header. You have to manually add it (e.g. with samtools view -b -T ref.fa in.sam > out.bam) as a post step.

All 5 comments

Can you add the command you used with minimap2? Is it possible that the alignment was interrupted?

You are probably aligning against a "multi-part" index. In this case, minimap2 is unable to output a proper header. You have to manually add it (e.g. with samtools view -b -T ref.fa in.sam > out.bam) as a post step.

Minimap2 generates a multi-part index when the total length of your database sequences is longer than 4Gbp by default.

Adding the sam header manually using samtools seems to work. Thank you

Best,
A

Hi, I meet the problem two. However I found it doesn't work even if I using samtools to add the header, since the resulted sam or bam file can't be sorted.
I solved the it by manually removing the first line of the sam file produced by minimap2 (sed -i '1d' in.sam). The first line looks like this "@PG ID:minimap2 PN:minimap2 VN:2.17-r954-dirty CL:minimap2 -ax sr --sam-hit-only -K 5000M -t 8 3_assembly/All.scaftigs.fa 2_cleandata/XXX_R1.fq 2_cleandata/XXX_R2.fq"
I added it here for anyone encounter this problem two.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dangchenyuan picture dangchenyuan  路  5Comments

fbemm picture fbemm  路  5Comments

a-89 picture a-89  路  3Comments

a-89 picture a-89  路  7Comments

fritzsedlazeck picture fritzsedlazeck  路  8Comments