Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Add support for reading SAM, BAM, CRAM, BCF, VCF with multiple thread… #241

Merged
merged 2 commits into from
Sep 26, 2021

Conversation

ghuls
Copy link
Contributor

@ghuls ghuls commented Sep 24, 2021

…s.hts_set_threads

Add support for reading SAM, BAM, CRAM, BCF, VCF with multiple threads
by using hts_set_threads().

…s.hts_set_threads

Add support for reading SAM, BAM, CRAM, BCF, VCF with multiple threads
by using hts_set_threads().
@ghuls
Copy link
Contributor Author

ghuls commented Sep 24, 2021

# count_reads_in_bam.seq 
from bio import *
from time import timing

bam_filename = 'ENCFF014BMO.bam'


def count_reads_in_bam(bam_filename, nthreads):
    nbr_reads = 0

    for r in SAM(bam_filename, nthreads=nthreads):
        nbr_reads += 1
        #print(r.name, r.read, r.pos, r.mapq, r.cigar, r.reversed)

    return nbr_reads

# Warmup cache.
count_reads_in_bam(bam_filename, 4)

for nthreads in [0, 1, 2, 3, 4, 6, 8]:
    with timing(f"Read BAM file with {nthreads} threads:"):
        print(count_reads_in_bam(bam_filename, nthreads))
seqc run --release count_reads_in_bam.seq 
15707047
Read BAM file with 0 threads: took 9.35422s
15707047
Read BAM file with 1 threads: took 6.34794s
15707047
Read BAM file with 2 threads: took 3.98488s
15707047
Read BAM file with 3 threads: took 3.93837s
15707047
Read BAM file with 4 threads: took 3.96835s
15707047
Read BAM file with 6 threads: took 4.01037s
15707047
Read BAM file with 8 threads: took 3.94179s

- Fix argument type of hts_set_threads C function
- Use "num_threads" to be consistent with new OpenMP interface
- Add some tests
@arshajii arshajii merged commit 51a62b5 into seq-lang:develop Sep 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants