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



990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
# File 'ext/htslib_native/native_bam.c', line 990

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



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

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

#nextObject



1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
# File 'ext/htslib_native/native_bam.c', line 1035

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



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

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