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
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.
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.