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;
}
|