<p>I'm not aware of any tools that do this out-of-the-box. Assuming some programming experience, it would be fairly straightforward to implement this in Python using <a href="https://pysam.readthedocs.io/en/latest/index.html" rel="nofollow noreferrer">pysam</a> (or htslib bindings for your favorite scripting language). In particular, the pileup is a very useful data structure.</p>

<p>Ultimately, you'll need to store an index of reference sequence positions by read name and position.</p>

<pre><code>read 1, offset 0 --&gt; chrom 3, offset 248879
read 1, offset 1 --&gt; chrom 3, offset 248880
read 1, offset 2 --&gt; chrom 3, offset 248882
...
...
...
</code></pre>

<p>Once you've done this for a pair of BAM files, computing the concordance statistics involves trivial set operations.</p>

<p>There are some important practical considerations though. If you implement the approach completely in memory, it will only be tractable for small-ish BAM files. It wouldn't take very many reads (relatively speaking) to overwhelm available RAM on a laptop or desktop. For large BAM files, you might even overwhelm the available RAM on a big-memory server. Alternatively, you could store the indexes in an on-disk database such as <a href="https://docs.python.org/3/library/sqlite3.html" rel="nofollow noreferrer">sqlite3</a>. This would keep RAM requirements low, but would slow things down substantially.</p>

<p>I think the most reasonable approach would be to process the BAM files in batches: grab all the reads in a 100kb region (or whatever size makes sense), compute the index, store the congruence statistics, move on to the next 100kb region and repeat, and then aggregate statistics when all regions have been processed.</p>

CC BY-SA 4.0
2019-07-25T18:36:05.980Z
2019-07-25T18:36:05.980Z
Daniel Standage
<p>I don't know of a single tool that can read multiple sets of BAM files and compare them. But you can use <a href="https://github.com/KyleLevi/SAM_Reader#how-do-i-examine-the-matches-at-each-individual-position-in-the-genome" rel="nofollow noreferrer">the Sam_Reader python3 module</a> to create a csv file that summarizes each position in the genome for each of your 3 results and then compare them manually.</p>

<p>It should be installable with:</p>

<pre><code>pip3 install sam_reader
</code></pre>

<p>And then generate the CSV with </p>

<pre><code>from sam_reader import Sam_Reader
my_files = Sam_Reader('my_bam_file_or_folder/')
my_files.per_base_stats(write_file='new_file.csv')
</code></pre>

<p>*but FYI this module requires <a href="https://pysam.readthedocs.io/en/latest/installation.html" rel="nofollow noreferrer">pysam</a>, which does not work on windows</p>

CC BY-SA 4.0
2019-07-25T16:10:17.743Z
2019-07-25T16:10:17.743Z
Kyle
<p>You can use the <a href="https://github.com/nanoporetech/wub/blob/master/scripts/bam_alignments_compare.py" rel="nofollow noreferrer">bam_alignments_compare.py</a> script from the <a href="https://wub.readthedocs.io/en/latest/" rel="nofollow noreferrer">wub</a> Python package. </p>

CC BY-SA 4.0
2019-08-15T13:25:07.567Z
Welcome to Bioinformatics.SE, and thanks for your answer. Note that when linking to external sites, please provide some context. Internet links tend to have a short half life, so describing, quoting, or embedding the most relevant content from the link helps preserve the information. See the **Provide Context for Links** section of [this help page](https://bioinformatics.stackexchange.com/help/how-to-answer) for more details.
Daniel Standage
CC BY-SA 4.0
2019-08-15T12:18:44.737Z
2019-08-15T13:26:56.553Z
2019-08-15T13:26:56.553Z
Botond Sipos
<p>I have aligned a nanopore data set to a reference genome with graphmap, minimap2 and BLASR. The alignment results are stored in BAM files. </p>

<p>I would like to do some concordance assessment, looking at the number of base pairs that are mapped to the same position by different aligner.   </p>

<p>Are there any tools or ways that allow me to do this effectively?</p>

CC BY-SA 4.0
2019-07-22T08:41:38.130Z
is this a DNA or RNA dataset you aligned to the reference genome?
aechchiki
CC BY-SA 4.0
2019-07-23T01:26:51.310Z
it is the RNA dataset from https://github.com/nanopore-wgs-consortium/NA12878/blob/master/RNA.md
Danielle Zhang
<phylogenetics><sam><nanopore>
Compare multiple alignment results' aligned bases
# Compare multiple alignment results' aligned bases

(Asked by: username_0 on 2019-07-22)

I have aligned a nanopore data set to a reference genome with graphmap, minimap2 and BLASR. The alignment results are stored in BAM files.

I would like to do some concordance assessment, looking at the number of base pairs that are mapped to the same position by different aligner.

Are there any tools or ways that allow me to do this effectively?

**Tags:** phylogenetics, sam, nanopore
> **Comments:**
> **username_1**: is this a DNA or RNA dataset you aligned to the reference genome?  
> **username_0**: it is the RNA dataset from https://github.com/nanopore-wgs-consortium/NA12878/blob/master/RNA.md  

---

## 3 answers

### Answer by username_2 on 2019-07-25. Score: 1

I'm not aware of any tools that do this out-of-the-box. Assuming some programming experience, it would be fairly straightforward to implement this in Python using pysam (or htslib bindings for your favorite scripting language). In particular, the pileup is a very useful data structure.
Ultimately, you'll need to store an index of reference sequence positions by read name and position.
read 1, offset 0 --> chrom 3, offset 248879
read 1, offset 1 --> chrom 3, offset 248880
read 1, offset 2 --> chrom 3, offset 248882
...
...
...

Once you've done this for a pair of BAM files, computing the concordance statistics involves trivial set operations.
There are some important practical considerations though. If you implement the approach completely in memory, it will only be tractable for small-ish BAM files. It wouldn't take very many reads (relatively speaking) to overwhelm available RAM on a laptop or desktop. For large BAM files, you might even overwhelm the available RAM on a big-memory server. Alternatively, you could store the indexes in an on-disk database such as sqlite3. This would keep RAM requirements low, but would slow things down substantially.
I think the most reasonable approach would be to process the BAM files in batches: grab all the reads in a 100kb region (or whatever size makes sense), compute the index, store the congruence statistics, move on to the next 100kb region and repeat, and then aggregate statistics when all regions have been processed.


---

### Answer by username_3 on 2019-07-25. Score: 1

I don't know of a single tool that can read multiple sets of BAM files and compare them. But you can use the Sam_Reader python3 module to create a csv file that summarizes each position in the genome for each of your 3 results and then compare them manually.
It should be installable with:
pip3 install sam_reader

And then generate the CSV with 
from sam_reader import Sam_Reader
my_files = Sam_Reader('my_bam_file_or_folder/')
my_files.per_base_stats(write_file='new_file.csv')

*but FYI this module requires pysam, which does not work on windows


---

### Answer by username_4 on 2019-08-15. Score: 0

You can use the [bam\_alignments\_compare.py](https://github.com/nanoporetech/wub/blob/master/scripts/bam_alignments_compare.py) script from the [wub](https://wub.readthedocs.io/en/latest/) Python package.

> **Comments:**
> **username_2**: Welcome to Bioinformatics.SE, and thanks for your answer. Note that when linking to external sites, please provide some context. Internet links tend to have a short half life, so describing, quoting, or embedding the most relevant content from the link helps preserve the information. See the **Provide Context for Links** section of [this help page](https://bioinformatics.stackexchange.com/help/how-to-answer) for more details.  

---

