Module: HTS::Native

Defined in:
ext/htslib_native/htslib_native_ext.c

Defined Under Namespace

Classes: BamFileHandle, BamIteratorHandle, BamRecordHandle, BaseModHandle, BcfFileHandle, BcfHeaderRecordHandle, BcfIteratorHandle, BcfRecordHandle, MpileupHandle, PileupHandle

Constant Summary collapse

BCF_HT_FLAG =
INT2NUM(BCF_HT_FLAG)
BCF_HT_INT =
INT2NUM(BCF_HT_INT)
BCF_HT_REAL =
INT2NUM(BCF_HT_REAL)
BCF_HT_STR =
INT2NUM(BCF_HT_STR)
BCF_HT_LONG =
INT2NUM(BCF_HT_LONG)
BCF_INT32_MISSING =
INT2NUM(bcf_int32_missing)
BCF_INT32_VECTOR_END =
INT2NUM(bcf_int32_vector_end)
BCF_FLOAT_MISSING =
UINT2NUM(bcf_float_missing)
BCF_FLOAT_VECTOR_END =
UINT2NUM(bcf_float_vector_end)

Class Method Summary collapse

Class Method Details

.bam_flag_string(flag) ⇒ Object



637
638
639
640
641
642
# File 'ext/htslib_native/native_bam.c', line 637

static VALUE native_bam_flag_string(VALUE native, VALUE flag) {
    char *value = bam_flag2str(NUM2INT(flag));
    VALUE result = value ? rb_str_new_cstr(value) : Qnil;
    free(value);
    return result;
}

.cigar_parse(text) ⇒ Object



393
394
395
396
397
398
399
400
401
402
403
# File 'ext/htslib_native/native_bam.c', line 393

static VALUE native_cigar_parse(VALUE klass, VALUE text) {
    uint32_t *cigar = NULL;
    size_t capacity = 0;
    long result = sam_parse_cigar(StringValueCStr(text), NULL, &cigar, &capacity), i;
    VALUE array;
    if (result < 0) { free(cigar); rb_raise(rb_eRuntimeError, "sam_parse_cigar failed: %ld", result); }
    array = rb_ary_new_capa(result);
    for (i = 0; i < result; i++) rb_ary_push(array, UINT2NUM(cigar[i]));
    free(cigar);
    return array;
}

.cigar_qlen(array) ⇒ Object



404
405
406
407
408
409
410
411
# File 'ext/htslib_native/native_bam.c', line 404

static VALUE native_cigar_qlen(VALUE klass, VALUE array) {
    long count = RARRAY_LEN(array), i;
    uint32_t *values = ALLOC_N(uint32_t, count ? count : 1);
    for (i = 0; i < count; i++) values[i] = NUM2UINT(rb_ary_entry(array, i));
    hts_pos_t result = bam_cigar2qlen(count, values);
    xfree(values);
    return LL2NUM(result);
}

.cigar_rlen(array) ⇒ Object



412
413
414
415
416
417
418
419
# File 'ext/htslib_native/native_bam.c', line 412

static VALUE native_cigar_rlen(VALUE klass, VALUE array) {
    long count = RARRAY_LEN(array), i;
    uint32_t *values = ALLOC_N(uint32_t, count ? count : 1);
    for (i = 0; i < count; i++) values[i] = NUM2UINT(rb_ary_entry(array, i));
    hts_pos_t result = bam_cigar2rlen(count, values);
    xfree(values);
    return LL2NUM(result);
}

.htslib_versionObject



4
5
6
7
# File 'ext/htslib_native/htslib_native_ext.c', line 4

static VALUE native_htslib_version(VALUE self)
{
    return rb_str_new_cstr(hts_version());
}

.selected_fields(line, columns) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'ext/htslib_native/htslib_native_ext.c', line 9

static VALUE selected_fields(VALUE self, VALUE line, VALUE columns)
{
    const char *bytes;
    long length, column_count, field_start = 0, column = 0, offset, i;
    VALUE result;

    StringValue(line);
    Check_Type(columns, T_ARRAY);
    bytes = RSTRING_PTR(line);
    length = RSTRING_LEN(line);
    column_count = RARRAY_LEN(columns);
    result = rb_ary_new_capa(column_count);
    for (i = 0; i < column_count; i++) rb_ary_push(result, Qnil);

    for (offset = 0; offset <= length; offset++) {
        if (offset == length || bytes[offset] == '\t') {
            for (i = 0; i < column_count; i++) {
                long requested = NUM2LONG(rb_ary_entry(columns, i));
                if (requested == column) {
                    rb_ary_store(result, i, rb_str_new(bytes + field_start, offset - field_start));
                }
            }
            column++;
            field_start = offset + 1;
        }
    }
    return result;
}