Skip to content

FAQ and miscellaneous tips

Ryan Wick edited this page Jul 26, 2021 · 40 revisions

Table of contents

Can I align my paired-end reads in a single BWA-MEM command?

The How to run Polypolish page instructs you to align paired-end reads into separate SAM files like this:

bwa mem -t 16 -a draft.fasta reads_1.fastq.gz > alignments_1.sam
bwa mem -t 16 -a draft.fasta reads_2.fastq.gz > alignments_2.sam

You might be tempted to combine those into a single command:

bwa mem -t 16 -a draft.fasta reads_1.fastq.gz reads_2.fastq.gz > alignments.sam

DON'T DO THIS! While that BWA-MEM command will run successfully, it will not make a SAM file appropriate for use with Polypolish. BWA-MEM's -a option (which Polypolish relies on to polish repeat regions) has no effect when used on paired read files, so the combined command will only have a single alignment for each read.

Does the order of alignments in the SAM file matter?

Yes, it can matter! Polypolish assumes that all of the alignments for each read are grouped together on adjacent lines in the SAM file. This is how BWA-MEM outputs its SAM files, so it shouldn't be a problem. But if you've sorted your alignments using samtools sort, they may not work with Polypolish.

When BWA-MEM is run in all-alignments mode (using the -a option, as you should do for Polypolish alignments), it does not include the read sequence on every line. The primary alignment for each read will contain the sequence, but secondary alignments will only contain a * to save space. If the alignments for each read are not grouped together, Polypolish will be unable to get the read sequence for secondary alignments and will quit with an error like this:

Error: no alignments for read NS500764:85:H3J5TBGXF:2:12111:13314:18114 contain sequence

If your SAM files have gotten out of order, you can use the samtools 'sort by read name' option (-n) to make them compatible with Polypolish:

samtools sort -n -O sam alignments.sam > alignments_sorted.sam

Assuming your SAM files meet the above requirement (all alignments for each read are grouped on adjacent lines), then the order of the SAM file does not matter. E.g. if you reverse the order of lines in your SAM file with tac, Polypolish will still run and it will produce identical output.

Can I use Bwa-mem2 instead of BWA-MEM?

Yes! Bwa-mem2 is a faster implementation of BWA-MEM. It produces nearly identical alignments to BWA-MEM, so its alignments are definitely appropriate for use with Polypolish.

Can I use Bowtie2 instead of BWA-MEM?

Bowtie2 is another popular short-read aligner, and like BWA-MEM, it has an option (-a) to align each read to all possible locations. So yes, you can use it to generate alignments for Polypolish!

Example alignment commands with Bowtie2 might look something like this:

bowtie2 -a -p 16 -x draft.fasta -U reads_1.fastq.gz > alignments_1.sam
bowtie2 -a -p 16 -x draft.fasta -U reads_2.fastq.gz > alignments_2.sam

However, I used BWA-MEM when developing and testing Polypolish, and I've only briefly tried using Bowtie2. So BWA-MEM is probably the safer choice.