File: read_bam_file.d

package info (click to toggle)
libbiod 0.2.3%2Bgit20191120.b8eecef-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,416 kB
  • sloc: makefile: 68; sh: 10
file content (44 lines) | stat: -rw-r--r-- 1,323 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
   To run this example from this directory:
   rdmd -I.. read_bam_file.d

// compile this example with

// debug version
dmd -i -I.. read_bam_file.d

// optimised version
dmd -i -O -release -inline -boundscheck=off -I.. read_bam_file.d

*/

import bio.std.hts.bam.reader;
import bio.std.hts.bam.pileup;
import std.stdio;

void main() {

    auto bam = new BamReader("../test/data/ex1_header.bam");
    auto reads = bam["chr2"][150 .. 160]; // region chr2:149-158
    auto pileup = makePileup(reads,
            false,     // reads don't contain MD tags
            155, 158); // specify [start, end) interval

    foreach (column; pileup) {
        writeln("Reference position: ", column.position);
        writeln("    Coverage: ", column.coverage);
        writeln("    Reads:");

        foreach (read; column.reads) {
            writefln("%30s\t%s\t%.2d\t%s\t%2s/%2s\t%2s/%2s\t%10s\t%s %s", 
                    read.name, 
                    read.current_base,
                    read.current_base_quality,
                    read.cigar_operation,
                    read.cigar_operation_offset + 1, read.cigar_operation.length,
                    read.query_offset + 1, read.sequence.length,
                    read.cigarString(),
                    read.cigar_before, read.cigar_after);
        }
    }
}