<commit_before>//---------------------------------------------------------
// Copyright 2016 Ontario Institute for Cancer Research
// Written by Jared Simpson (<EMAIL>)
//---------------------------------------------------------
//
// nanopolish_bam_processor -- framework for iterating
// over a bam file and running an arbitrary function
// on each aligned read in parallel
//
#include "nanopolish_bam_processor.h"
#include "nanopolish_common.h"
#include <assert.h>
#include <omp.h>
#include <vector>
#include <hdf5.h>

BamProcessor::BamProcessor(const std::string& bam_file,
                           const std::string& region,
                           const int num_threads) :
                            m_bam_file(bam_file),
                            m_region(region),
                            m_num_threads(num_threads)

{
    // load bam file
    m_bam_fh = sam_open(m_bam_file.c_str(), "r");
    assert(m_bam_fh != NULL);

    // load bam index file
    std::string index_filename = m_bam_file + ".bai";
    m_bam_idx = bam_index_load(index_filename.c_str());
    if(m_bam_idx == NULL) {
        bam_index_error_exit(m_bam_file);
    }

    // read the bam header
    m_hdr = sam_hdr_read(m_bam_fh);
    assert(m_hdr != NULL);
}

BamProcessor::~BamProcessor()
{
    bam_hdr_destroy(m_hdr);
    sam_close(m_bam_fh);
    hts_idx_destroy(m_bam_idx);<commit_msg>use sam_index_load in BamProcessor to support CRAM<commit_after>//---------------------------------------------------------
// Copyright 2016 Ontario Institute for Cancer Research
// Written by <NAME> (<EMAIL>)
//---------------------------------------------------------
//
// nanopolish_bam_processor -- framework for iterating
// over a bam file and running an arbitrary function
// on each aligned read in parallel
//
#include "nanopolish_bam_processor.h"
#include "nanopolish_common.h"
#include <assert.h>
#include <omp.h>
#include <vector>
#include <hdf5.h>

BamProcessor::BamProcessor(const std::string& bam_file,
                           const std::string& region,
                           const int num_threads) :
                            m_bam_file(bam_file),
                            m_region(region),
                            m_num_threads(num_threads)

{
    // load bam file
    m_bam_fh = sam_open(m_bam_file.c_str(), "r");
    assert(m_bam_fh != NULL);

    // load bam index file
    m_bam_idx = sam_index_load(m_bam_fh, bam_file.c_str());
    if(m_bam_idx == NULL) {
        bam_index_error_exit(m_bam_file);
    }

    // read the bam header
    m_hdr = sam_hdr_read(m_bam_fh);
    assert(m_hdr != NULL);
}

BamProcessor::~BamProcessor()
{
    bam_hdr_destroy(m_hdr);
    sam_close(m_bam_fh);
    hts_idx_destroy(m_bam_idx);
{'fraction_non_alphanumeric': 0.18571428571428572, 'fraction_numerical': 0.003663003663003663, 'mean_word_length': 1.923982869379015, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5203158', 'n_tokens_mistral': 903, 'n_tokens_neox': 877, 'n_words': 179}