This project is read-only.

Bam Parser API

Nov 4, 2014 at 11:07 AM
Hello everyone!

I'm just trying figure out how can I access to bam-file using indexed bai-file? Of course I can read into memory whole bam-file using Bio.IO.BAM.BAMParser.Parse(stream) but this is not exactly that I need. I've found functions GetAlignment(bamStream, bamIndexStorage, refSeqName, start, end) or GetAlignmentWithIndex or GetAlignmentMap but they are internal or private.

Nov 4, 2014 at 3:33 PM
Edited Nov 4, 2014 at 3:33 PM
Hi Pavel,

There are a bunch of extension methods that allow you to manage the index file. Here's the source file:

These are in the namespace: Bio.IO.BAM, so if you add that to your source you should see them. Then you can do this:
BAMParser parser = ...;
SequenceAlignmentMap sam = parser. ParseRange(@"someFile.bam", refSequenceName);
It assumes the index file is in the same folder with your .bam file with a ".bai" extension.

Let me know if you have trouble.

Marked as answer by pgsinitsyn on 11/4/2014 at 3:09 PM
Nov 4, 2014 at 9:23 PM
Hello Mark!

It works perfectly with Bio.Core.dll
using (BAMParser parser = new BAMParser()) {
    SequenceAlignmentMap result = BAMParserExtensions.ParseRange(parser, fileName, refSeqName, start, end);
I appologize because I'm fresh in c# and I can't resolve one problem. I've downloaded the source code and opened Bio.sln in VS12, but the such error was appeared (PrintScrean). And as result I couldn't find the any function that uses GetAlignment, particulary BAMParserExtensions.cs in Shared.shproj . I already tried to do it in win7 (vs12) and win8 (vs12 and vs13). Do you know the reason of a problem?

The Generated log file is attached.

Thank you for fast reply.
Nov 4, 2014 at 9:26 PM
To build the source, you need Visual Studio 2013 with at least Update 2 applied. It uses a new project type to share the source code across different architectures which was added into that version. You don't need to build the source however, just include the latest binary using Nuget (References > Add Package, search for .NET Bio) and then write your own code in a separate project.

Nov 4, 2014 at 10:00 PM
Because I decided to explore the code instead using it like a black box. And it is a good practice.
Thank you for the beauty code and intensive comments.

Nov 5, 2014 at 8:17 PM
That's great, you will need VS2013 with Update 2 or better (or VS '15 CTP) to load the project, alternatively, you can explore it in the Github repo source as well if you just want to examine source code..