Class: HTS::Native::MpileupHandle

Inherits:
Object
  • Object
show all
Defined in:
ext/htslib_native/native_bam.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.open(files, headers, region, beg, end, maxcnt, overlaps) ⇒ Object



931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
# File 'ext/htslib_native/native_bam.c', line 931

static VALUE native_mpileup_open(VALUE klass, VALUE files, VALUE headers, VALUE region,
                                 VALUE beg, VALUE end, VALUE maxcnt, VALUE overlaps) {
    ruby_mpileup_t *value;
    VALUE object;
    int index, count;
    Check_Type(files, T_ARRAY);
    Check_Type(headers, T_ARRAY);
    count = RARRAY_LEN(files);
    if (count <= 0 || RARRAY_LEN(headers) != count) rb_raise(rb_eArgError, "invalid mpileup inputs");
    object = TypedData_Make_Struct(klass, ruby_mpileup_t, &mpileup_type, value);
    memset(value, 0, sizeof(*value));
    value->count = count;
    value->files = files;
    value->headers = headers;
    RB_OBJ_WRITE(object, &value->files, files);
    RB_OBJ_WRITE(object, &value->headers, headers);
    value->inputs = ALLOC_N(ruby_mplp_input_t, count);
    value->input_data = ALLOC_N(void *, count);
    value->depths = ALLOC_N(int, count);
    value->entries = ALLOC_N(const bam_pileup1_t *, count);
    memset(value->inputs, 0, sizeof(ruby_mplp_input_t) * count);
    for (index = 0; index < count; index++) {
        ruby_bam_file_t *file = get_file(rb_ary_entry(files, index), 0);
        sam_hdr_t *header = get_header(rb_ary_entry(headers, index))->pointer;
        value->inputs[index].file = file;
        value->inputs[index].header = header;
        if (!NIL_P(region)) {
            if (!file->index) { mpileup_release(value); rb_raise(rb_eRuntimeError, "index file is required to use region mpileup"); }
            if (NIL_P(beg) && NIL_P(end))
                value->inputs[index].iterator = sam_itr_querys(file->index, header, StringValueCStr(region));
            else
                value->inputs[index].iterator = sam_itr_queryi(file->index, sam_hdr_name2tid(header, StringValueCStr(region)), NUM2LL(beg), NUM2LL(end));
            if (!value->inputs[index].iterator) { mpileup_release(value); rb_raise(rb_eRuntimeError, "failed to query mpileup region"); }
        }
        value->input_data[index] = &value->inputs[index];
    }
    value->pileup = bam_mplp_init(count, native_mpileup_read, value->input_data);
    if (!value->pileup) { mpileup_release(value); rb_raise(rb_eNoMemError, "bam_mplp_init failed"); }
    if (!NIL_P(maxcnt)) bam_mplp_set_maxcnt(value->pileup, NUM2INT(maxcnt));
    if (RTEST(overlaps) && bam_mplp_init_overlaps(value->pileup) < 0) {
        mpileup_release(value);
        rb_raise(rb_eRuntimeError, "bam_mplp_init_overlaps failed");
    }
    return object;
}

Instance Method Details

#closeObject



998
# File 'ext/htslib_native/native_bam.c', line 998

static VALUE native_mpileup_close(VALUE self) { mpileup_release(get_mpileup(self, 1)); return Qnil; }

#nextObject



976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
# File 'ext/htslib_native/native_bam.c', line 976

static VALUE native_mpileup_next(VALUE self) {
    ruby_mpileup_t *value = get_mpileup(self, 0);
    int tid = -1, result, index;
    hts_pos_t position = -1;
    VALUE rows, depths, output;
    result = bam_mplp64_auto(value->pileup, &tid, &position, value->depths, value->entries);
    if (result == 0) return Qnil;
    if (result < 0) rb_raise(rb_eRuntimeError, "HTSlib mpileup error");
    rows = rb_ary_new_capa(value->count);
    depths = rb_ary_new_capa(value->count);
    for (index = 0; index < value->count; index++) {
        rb_ary_push(depths, INT2NUM(value->depths[index]));
        rb_ary_push(rows, pileup_rows(value->entries[index], value->depths[index]));
    }
    output = rb_ary_new_capa(4);
    rb_ary_push(output, INT2NUM(tid));
    rb_ary_push(output, LL2NUM(position));
    rb_ary_push(output, depths);
    rb_ary_push(output, rows);
    return output;
}

#resetObject



997
# File 'ext/htslib_native/native_bam.c', line 997

static VALUE native_mpileup_reset(VALUE self) { bam_mplp_reset(get_mpileup(self, 0)->pileup); return Qnil; }