I have a bunch of PAF files resulting from the alignments of fastq files on a reference genome with minimap2. I would like to convert them into SAM/BAM format so I can use samtools mpileup to recover the read coverage at filtered positions

So far I've looked at paftools.js and found sam2paf but no paf2sam

I am open to suggestions but I'd like to avoid mapping the reads again.


I have opened an issue on minimap2's github

Answer from Heng Li :

You need to rerun alignment. No tools exist to convert paf to sam.

why there is no paf2sam in paftools.js

It is technically possible, but someone needs to write the code.

  • $\begingroup$ I'm not sure the question is answerable in its current format, there doesn't appear to be enough background information and this often results in substancial misunderstanding between OP and the reply. Lets see what the other think. $\endgroup$
    – M__
    Commented Oct 9, 2019 at 12:38
  • $\begingroup$ Thanks for the feedback. So, as far I as know mpileup can take an alignment file and a list of genomic positions (eg BED) and return statistics for each positions, such as the read coverage. mpileup doesn't work with PAF file so I am looking to convert PAF format to SAM/BAM format. If there are alternatives to mpileup, I am open to the suggestions. Is this better ? $\endgroup$ Commented Oct 9, 2019 at 13:17
  • $\begingroup$ It's really weird that they provide sam2paf but not paf2sam. Could it be that the conversion in that direction isn't possible? Perhaps paf is missing information that would be essential for sam? $\endgroup$
    – terdon
    Commented Oct 9, 2019 at 17:39
  • $\begingroup$ @terdon I am not a specialist but it's stated that CIGAR can take different format depending on the input/output options. It might also be not written in the PAF in some case. Is that CIGAR essential to sam ? $\endgroup$ Commented Oct 10, 2019 at 8:17
  • 3
    $\begingroup$ I would take Heng Li's advice. minimap2 is fast. Just add the -a option when you re-run, which outputs the alignment in sam instead of paf $\endgroup$ Commented Oct 11, 2019 at 3:02

1 Answer 1


The paf format does not have the CIGAR string and base quality information that are typically present in a BAM/SAM file. While it is in principle possible to write a paf2sam converter, it's going to be very difficult to regenerate the CIGAR string with all the indel information (and maybe it's probably impossible to do so) that you'll need in a BAM/SAM file. If your motivation is to get coverage information, it might make more sense to convert the paf file into a bed file, before using a tool like bedtools to convert it into a coverage track.

  • $\begingroup$ note that PAF files can have a "cg:" tag that is a cigar string. it is an optional output from minimap2 for example (there is also cs: tag that is a different encoding of the sequence differences, but cg may be more common) $\endgroup$
    – Colin D
    Commented Aug 14, 2023 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.