3
$\begingroup$

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?

$\endgroup$
1
$\begingroup$

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

$\endgroup$
1
$\begingroup$

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.

$\endgroup$
0
$\begingroup$

You can use the bam_alignments_compare.py script from the wub Python package.

$\endgroup$
  • 1
    $\begingroup$ 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 for more details. $\endgroup$ – Daniel Standage Aug 15 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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