<p>From <a href="http://bio-bwa.sourceforge.net/bwa.shtml" rel="nofollow noreferrer">BWA manual</a>, it is advised to use BWA-MEM in your longs read case (unless you have a good reason not to):</p>

<blockquote>
  <p>BWA-MEM and BWA-SW share similar features such as long-read support and split alignment, but BWA-MEM, which is the latest, is generally recommended for high-quality queries as it is faster and more accurate.</p>
</blockquote>

<p>I guess that BWA-SW returns several lines per transcript (based on local alignments). In that case, the <a href="https://sourceforge.net/p/bio-bwa/mailman/message/31199486/" rel="nofollow noreferrer">issue has already been reported</a>. The user asks: </p>

<blockquote>
  <p>How can I differentiate between a read that has multiple hits in the reference and a read that has a split alignment?</p>
</blockquote>

<p>The author replies: </p>

<blockquote>
  <p>In principle, it is hard to tell. Bwa-mem makes an arbitrary choice.
  Mappings flagged with 0x100 are multiple hits. Mappings flagged with
  0x800 are from a chimeric alignment.</p>
</blockquote>

<p>So you could actually filter by <a href="https://broadinstitute.github.io/picard/explain-flags.html" rel="nofollow noreferrer">flag</a>. But I am afraid the output could include something you do not necessarily want to (since there is no specific flag for the split reads).</p>

<p>Maybe a better solution: you could switch to some mapper that will report the proper split in the hit of the read map, such as <a href="https://github.com/lh3/minimap2" rel="nofollow noreferrer">minimap2</a> from the same author. It is suitable for long reads and comes with a <code>splice -x</code> feature.</p>

<p>Then, the laziest solution I see here would be to remove the split alignments exploiting the <a href="https://samtools.github.io/hts-specs/SAMv1.pdf" rel="nofollow noreferrer">sam format</a> and in particular the CIGAR string. Meaning, to remove the sam fields containing a <code>N</code> in their CIGAR (aka, skipped region from the reference). Something like this would work: </p>

<pre><code>cat alignment.sam | awk '$6 !~ /N/ {print $0}'
</code></pre>

<p>Hope this can be somewhat helpful.</p>

CC BY-SA 3.0
2017-11-06T11:02:28.493Z
2017-11-06T11:02:28.493Z
aechchiki
<p>Is there a way to remove split alignments of single-end long reads from BWA-SW output? BWA-MEM has an option to include or flag split alignments in the result, but it seems BWA-SW method include them in the result unless the split occur in paired-end reads.</p>

<phylogenetics><bwa><sam><long-reads>
Mark BWA-SW split alignments in output for long reads
# Mark BWA-SW split alignments in output for long reads

(Asked by: username_0 on 2017-10-25)

Is there a way to remove split alignments of single-end long reads from BWA-SW output? BWA-MEM has an option to include or flag split alignments in the result, but it seems BWA-SW method include them in the result unless the split occur in paired-end reads.

**Tags:** phylogenetics, bwa, sam, long-reads

---

## 1 answers

### Answer by username_1 on 2017-11-06. Score: 1 | Accepted answer

From BWA manual, it is advised to use BWA-MEM in your longs read case (unless you have a good reason not to):

BWA-MEM and BWA-SW share similar features such as long-read support and split alignment, but BWA-MEM, which is the latest, is generally recommended for high-quality queries as it is faster and more accurate.

I guess that BWA-SW returns several lines per transcript (based on local alignments). In that case, the issue has already been reported. The user asks: 

How can I differentiate between a read that has multiple hits in the reference and a read that has a split alignment?

The author replies: 

In principle, it is hard to tell. Bwa-mem makes an arbitrary choice.
  Mappings flagged with 0x100 are multiple hits. Mappings flagged with
  0x800 are from a chimeric alignment.

So you could actually filter by flag. But I am afraid the output could include something you do not necessarily want to (since there is no specific flag for the split reads).
Maybe a better solution: you could switch to some mapper that will report the proper split in the hit of the read map, such as minimap2 from the same author. It is suitable for long reads and comes with a splice -x feature.
Then, the laziest solution I see here would be to remove the split alignments exploiting the sam format and in particular the CIGAR string. Meaning, to remove the sam fields containing a N in their CIGAR (aka, skipped region from the reference). Something like this would work: 
cat alignment.sam | awk '$6 !~ /N/ {print $0}'

Hope this can be somewhat helpful.


---

