Class: HTS::Native::BamFileHandle
- Inherits:
-
Object
- Object
- HTS::Native::BamFileHandle
- Defined in:
- ext/htslib_native/native_bam.c
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #file_format ⇒ Object
- #file_format_version ⇒ Object
- #index_loaded? ⇒ Boolean
- #load_index(index_value) ⇒ Object
- #query_interval(tid, beg, end) ⇒ Object
- #query_region(header, region) ⇒ Object
- #read(header, record) ⇒ Object
- #read_header ⇒ Object
- #seek(offset) ⇒ Object
- #set_fai(path) ⇒ Object
- #set_threads(count) ⇒ Object
- #tell ⇒ Object
- #write(header, record) ⇒ Object
- #write_header(header) ⇒ Object
Class Method Details
.build_index(path, index, shift, threads) ⇒ Object
607 608 609 610 |
# File 'ext/htslib_native/native_bam.c', line 607
static VALUE native_bam_build_index(VALUE klass, VALUE path, VALUE index, VALUE shift, VALUE threads) {
return INT2NUM(sam_index_build3(StringValueCStr(path), NIL_P(index) ? NULL : StringValueCStr(index),
NUM2INT(shift), NUM2INT(threads)));
}
|
.open(path_value, mode_value) ⇒ Object
517 518 519 520 521 522 523 524 525 526 527 |
# File 'ext/htslib_native/native_bam.c', line 517
static VALUE native_bam_open(VALUE klass, VALUE path_value, VALUE mode_value) {
ruby_bam_file_t *value;
VALUE object = TypedData_Make_Struct(klass, ruby_bam_file_t, &bam_file_type, value);
value->index = NULL;
value->active_io = 0;
value->path = rb_str_dup(StringValue(path_value));
RB_OBJ_WRITE(object, &value->path, value->path);
value->file = hts_open(StringValueCStr(value->path), StringValueCStr(mode_value));
if (!value->file) rb_syserr_fail_str(ENOENT, path_value);
return object;
}
|
Instance Method Details
#close ⇒ Object
528 529 530 531 532 533 534 |
# File 'ext/htslib_native/native_bam.c', line 528
static VALUE native_bam_close(VALUE self) {
ruby_bam_file_t *value = get_file(self, 1);
if (value->active_io) rb_raise(rb_eIOError, "cannot close BAM during active I/O");
if (value->index) { hts_idx_destroy(value->index); value->index = NULL; }
if (value->file) { hts_close(value->file); value->file = NULL; }
return Qnil;
}
|
#closed? ⇒ Boolean
535 |
# File 'ext/htslib_native/native_bam.c', line 535
static VALUE native_bam_closed(VALUE self) { return get_file(self, 1)->file ? Qfalse : Qtrue; }
|
#file_format ⇒ Object
567 568 569 570 571 572 573 574 575 576 577 578 |
# File 'ext/htslib_native/native_bam.c', line 567
static VALUE native_bam_format(VALUE self) {
const htsFormat *format = hts_get_format(get_file(self, 0)->file);
if (!format) return Qnil;
switch (format->format) {
case sam: return rb_str_new_cstr("sam");
case bam: return rb_str_new_cstr("bam");
case cram: return rb_str_new_cstr("cram");
case vcf: return rb_str_new_cstr("vcf");
case bcf: return rb_str_new_cstr("bcf");
default: return rb_str_new_cstr("unknown_format");
}
}
|
#file_format_version ⇒ Object
579 580 581 582 583 584 |
# File 'ext/htslib_native/native_bam.c', line 579
static VALUE native_bam_format_version(VALUE self) {
const htsFormat *format = hts_get_format(get_file(self, 0)->file);
if (!format) return Qnil;
if (format->version.minor == -1) return rb_sprintf("%d", format->version.major);
return rb_sprintf("%d.%d", format->version.major, format->version.minor);
}
|
#index_loaded? ⇒ Boolean
606 |
# File 'ext/htslib_native/native_bam.c', line 606
static VALUE native_bam_index_loaded(VALUE self) { return get_file(self, 0)->index ? Qtrue : Qfalse; }
|
#load_index(index_value) ⇒ Object
598 599 600 601 602 603 604 605 |
# File 'ext/htslib_native/native_bam.c', line 598
static VALUE native_bam_load_index(VALUE self, VALUE index_value) {
ruby_bam_file_t *value = get_file(self, 0);
if (value->index) { hts_idx_destroy(value->index); value->index = NULL; }
value->index = NIL_P(index_value)
? sam_index_load3(value->file, StringValueCStr(value->path), NULL, HTS_IDX_SAVE_REMOTE)
: sam_index_load2(value->file, StringValueCStr(value->path), StringValueCStr(index_value));
return value->index ? Qtrue : Qfalse;
}
|
#query_interval(tid, beg, end) ⇒ Object
611 612 613 614 615 |
# File 'ext/htslib_native/native_bam.c', line 611
static VALUE native_bam_query_interval(VALUE self, VALUE tid, VALUE beg, VALUE end) {
ruby_bam_file_t *file = get_file(self, 0);
if (!file->index) rb_raise(rb_eRuntimeError, "index file is required");
return wrap_iterator(self, sam_itr_queryi(file->index, NUM2INT(tid), NUM2LL(beg), NUM2LL(end)));
}
|
#query_region(header, region) ⇒ Object
616 617 618 619 620 |
# File 'ext/htslib_native/native_bam.c', line 616
static VALUE native_bam_query_region(VALUE self, VALUE header, VALUE region) {
ruby_bam_file_t *file = get_file(self, 0);
if (!file->index) rb_raise(rb_eRuntimeError, "index file is required");
return wrap_iterator(self, sam_itr_querys(file->index, get_header(header)->pointer, StringValueCStr(region)));
}
|
#read(header, record) ⇒ Object
553 554 555 556 |
# File 'ext/htslib_native/native_bam.c', line 553
static VALUE native_bam_read(VALUE self, VALUE header, VALUE record) {
ruby_bam_file_t *file=get_file(self,0); bam_io_args_t args={file->file,get_header(header)->pointer,get_record(record)->pointer,NULL,0};
bam_io_begin(file); rb_thread_call_without_gvl(bam_read_without_gvl,&args,RUBY_UBF_IO,NULL); file->active_io=0; return INT2NUM(args.result);
}
|
#read_header ⇒ Object
544 545 546 547 548 |
# File 'ext/htslib_native/native_bam.c', line 544
static VALUE native_bam_read_header(VALUE self) {
ruby_bam_file_t *file=get_file(self,0); bam_header_read_args_t args={file->file,NULL};
bam_io_begin(file); rb_thread_call_without_gvl(bam_read_header_without_gvl,&args,RUBY_UBF_IO,NULL); file->active_io=0;
return wrap_header(args.result);
}
|
#seek(offset) ⇒ Object
585 586 587 588 589 590 591 |
# File 'ext/htslib_native/native_bam.c', line 585
static VALUE native_bam_seek(VALUE self, VALUE offset) {
htsFile *file = get_file(self, 0)->file;
int64_t position = NUM2LL(offset);
if (file->is_cram) return LL2NUM(cram_seek(file->fp.cram, position, SEEK_SET));
if (file->is_bgzf) return LL2NUM(bgzf_seek(file->fp.bgzf, position, SEEK_SET));
return LL2NUM(hseek(file->fp.hfile, position, SEEK_SET));
}
|
#set_fai(path) ⇒ Object
561 562 563 |
# File 'ext/htslib_native/native_bam.c', line 561
static VALUE native_bam_set_fai(VALUE self, VALUE path) {
return INT2NUM(hts_set_fai_filename(get_file(self, 0)->file, StringValueCStr(path)));
}
|
#set_threads(count) ⇒ Object
564 565 566 |
# File 'ext/htslib_native/native_bam.c', line 564
static VALUE native_bam_set_threads(VALUE self, VALUE count) {
return INT2NUM(hts_set_threads(get_file(self, 0)->file, NUM2INT(count)));
}
|
#tell ⇒ Object
592 593 594 595 596 597 |
# File 'ext/htslib_native/native_bam.c', line 592
static VALUE native_bam_tell(VALUE self) {
htsFile *file = get_file(self, 0)->file;
if (file->is_cram) return Qnil;
if (file->is_bgzf) return LL2NUM(bgzf_tell(file->fp.bgzf));
return LL2NUM(htell(file->fp.hfile));
}
|
#write(header, record) ⇒ Object
557 558 559 560 |
# File 'ext/htslib_native/native_bam.c', line 557
static VALUE native_bam_write(VALUE self, VALUE header, VALUE record) {
ruby_bam_file_t *file=get_file(self,0); bam_io_args_t args={file->file,get_header(header)->pointer,get_record(record)->pointer,NULL,0};
bam_io_begin(file); rb_thread_call_without_gvl(bam_write_without_gvl,&args,RUBY_UBF_IO,NULL); file->active_io=0; return INT2NUM(args.result);
}
|
#write_header(header) ⇒ Object
549 550 551 552 |
# File 'ext/htslib_native/native_bam.c', line 549
static VALUE native_bam_write_header(VALUE self, VALUE header) {
ruby_bam_file_t *file=get_file(self,0); bam_io_args_t args={file->file,get_header(header)->pointer,NULL,NULL,0};
bam_io_begin(file); rb_thread_call_without_gvl(bam_write_header_without_gvl,&args,RUBY_UBF_IO,NULL); file->active_io=0; return INT2NUM(args.result);
}
|