how to convert minimap2 generated sam file to bam
I have mapped the reference chromosome assembly on other chromosome assemblies using minimap2 to generate sam file. my sam file doesn't have header
I tried
samtools ref.fa.fai sample.sam sample.bam
and
samtools view -bT ref.fa sample.sam > sample.bam
both errors are:
fail to read the header from sample.sam
how can I create bam file out of that?
• 9,269 views
•
link
1 answer
Why would your SAM file not have a header? Did you not use
-a output in the SAM format
when you did the alignments? If you did not, then your alignment output is in PAF format (which is the default). You could simply realign with this parameter and directly pipe into samtools to get a sorted BAM file
minimap2 -x map-ont -a ref.fa reads.fq.gz | samtools sort -o out.bam --write-index -
It was not possible to convert PAF to SAM at one point so you will need to realign.
• 0 views
•
link
Realign with -a option, your current alignments are in PAF format.
• 0 views
•
link
Log in to answer this question.