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
651 652 653 654 |
# File 'ext/htslib_native/native_bam.c', line 651 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
552 553 554 555 556 557 558 559 560 561 562 563 |
# File 'ext/htslib_native/native_bam.c', line 552 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); errno = 0; value->file = hts_open(StringValueCStr(value->path), StringValueCStr(mode_value)); if (!value->file) raise_bam_open_error(path_value, errno); return object; } |
Instance Method Details
#close ⇒ Object
564 565 566 567 568 569 570 571 |
# File 'ext/htslib_native/native_bam.c', line 564 static VALUE native_bam_close(VALUE self) { ruby_bam_file_t *value = get_file(self, 1); int result = 0; 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) { result = hts_close(value->file); value->file = NULL; } return INT2NUM(result); } |
#closed? ⇒ Boolean
572 |
# File 'ext/htslib_native/native_bam.c', line 572 static VALUE native_bam_closed(VALUE self) { return get_file(self, 1)->file ? Qfalse : Qtrue; } |
#file_format ⇒ Object
611 612 613 614 615 616 617 618 619 620 621 622 |
# File 'ext/htslib_native/native_bam.c', line 611 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
623 624 625 626 627 628 |
# File 'ext/htslib_native/native_bam.c', line 623 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
650 |
# File 'ext/htslib_native/native_bam.c', line 650 static VALUE native_bam_index_loaded(VALUE self) { return get_file(self, 0)->index ? Qtrue : Qfalse; } |
#load_index(index_value) ⇒ Object
642 643 644 645 646 647 648 649 |
# File 'ext/htslib_native/native_bam.c', line 642 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
655 656 657 658 659 |
# File 'ext/htslib_native/native_bam.c', line 655 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
660 661 662 663 664 |
# File 'ext/htslib_native/native_bam.c', line 660 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
597 598 599 600 |
# File 'ext/htslib_native/native_bam.c', line 597 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_run(file,bam_read_without_gvl,&args); return INT2NUM(args.result); } |
#read_header ⇒ Object
588 589 590 591 592 |
# File 'ext/htslib_native/native_bam.c', line 588 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_run(file,bam_read_header_without_gvl,&args); return wrap_header(args.result); } |
#seek(offset) ⇒ Object
629 630 631 632 633 634 635 |
# File 'ext/htslib_native/native_bam.c', line 629 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
605 606 607 |
# File 'ext/htslib_native/native_bam.c', line 605 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
608 609 610 |
# File 'ext/htslib_native/native_bam.c', line 608 static VALUE native_bam_set_threads(VALUE self, VALUE count) { return INT2NUM(hts_set_threads(get_file(self, 0)->file, NUM2INT(count))); } |
#tell ⇒ Object
636 637 638 639 640 641 |
# File 'ext/htslib_native/native_bam.c', line 636 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
601 602 603 604 |
# File 'ext/htslib_native/native_bam.c', line 601 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_run(file,bam_write_without_gvl,&args); return INT2NUM(args.result); } |
#write_header(header) ⇒ Object
593 594 595 596 |
# File 'ext/htslib_native/native_bam.c', line 593 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_run(file,bam_write_header_without_gvl,&args); return INT2NUM(args.result); } |