Exemplo n.º 1
0
void
bam_streamer::
set_new_region(const char* region)
{
    int ref,beg,end;
    bam_parse_region(_bfp->header, region, &ref, &beg, &end); // parse the region

    set_new_region(ref,beg,end);
    _region=region;
}
Exemplo n.º 2
0
bam_streamer::
bam_streamer(
    const char* filename,
    const char* region)
    : _is_record_set(false),
      _bfp(nullptr),
      _hidx(nullptr),
      _hitr(nullptr),
      _record_no(0),
      _stream_name(filename),
      _is_region(false)
{
    assert(nullptr != filename);
    if ('\0' == *filename)
    {
        throw blt_exception("Can't initialize bam_streamer with empty filename\n");
    }

    _bfp = samopen(filename, "rb", 0);

    if (nullptr == _bfp)
    {
        log_os << "ERROR: Failed to open SAM/BAM/CRAM file: " << filename << "\n";
        exit(EXIT_FAILURE);
    }

    if (nullptr == region)
    {
        // read the whole BAM file:

        if (_bfp->header->n_targets)
        {
            // parse a fake region so that header->hash is created
            std::string fake_region(target_id_to_name(0));
            fake_region += ":1-1";
            int ref,beg,end;
            bam_parse_region(_bfp->header, fake_region.c_str(), &ref, &beg, &end);
        }
        return;
    }

    // read a specific region of the bam file:
    set_new_region(region);
}
Exemplo n.º 3
0
bam_streamer::
bam_streamer(const char* filename,
             const char* region)
    : _is_record_set(false), _bfp(NULL), _bidx(NULL), _biter(NULL),
      _record_no(0), _stream_name(filename), _is_region(false)
{

    assert(NULL != filename);
    assert('\0' != *filename);

    _bfp = samopen(filename, "rb", 0);

    if (NULL == _bfp)
    {
        log_os << "ERROR: Failed to open SAM/BAM file: " << filename << "\n";
        exit(EXIT_FAILURE);
    }


    if (NULL == region)
    {
        // read the whole BAM file:

        if (_bfp->header->n_targets)
        {
            // parse a fake region so that header->hash is created
            std::string fake_region(target_id_to_name(0));
            fake_region += ":1-1";
            int ref,beg,end;
            bam_parse_region(_bfp->header, fake_region.c_str(), &ref, &beg, &end);
        }
        return;
    }

    // read a specific region of the bam file:
    set_new_region(region);
}