how to convert minimap2 generated sam file to bam
1
0
Entering edit mode
22 months ago
mthm ▴ 50

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?

minimap2 sam bam samtools • 5.9k views
ADD COMMENT
5
Entering edit mode
22 months ago
GenoMax 148k

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.

ADD COMMENT
0
Entering edit mode

thank you GenoMax for your answer. I did this

minimap2 -t 8 sample.fa reference.fa > sample.map.sam

I will try your suggestion, thanks

ADD REPLY
2
Entering edit mode

Realign with -a option, your current alignments are in PAF format.

ADD REPLY

Login before adding your answer.

Traffic: 2132 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6