Пример #1
0
void
bam_streamer::
report_state(std::ostream& os) const
{
    const bam_record* bamp(get_record_ptr());

    os << "\tbam_stream_label: " << name() << "\n";
    if (_is_region && (! _region.empty()))
    {
        os << "\tbam_stream_selected_region: " << _region << "\n";
    }
    if (nullptr != bamp)
    {
        os << "\tbam_stream_record_no: " << record_no() << "\n";
        os << "\tbam_record QNAME/read_number: " << bamp->qname() << "/" << bamp->read_no() << "\n";
        const char* chrom_name(target_id_to_name(bamp->target_id()));
        os << "\tbam record RNAME: " << chrom_name << "\n";
        os << "\tbam record POS: " << bamp->pos() << "\n";

    }
    else
    {
        os << "\tno bam record currently set\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);
}
Пример #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);
}