Class: HTS::Native::BcfRecordHandle
- Inherits:
-
Object
- Object
- HTS::Native::BcfRecordHandle
- Defined in:
- ext/htslib_native/native_bcf.c
Class Method Summary collapse
Instance Method Summary collapse
- #alleles ⇒ Object
- #core_get(field) ⇒ Object
- #core_set(field, value) ⇒ Object
- #duplicate ⇒ Object
- #filter_ids ⇒ Object
- #filter_names(header) ⇒ Object
- #format_delete(header, key, type) ⇒ Object
- #format_fields(header) ⇒ Object
- #format_get(header_value, key_value, type_value, raw_value) ⇒ Object
- #format_record(header) ⇒ Object
- #format_update(header, key, type_value, values) ⇒ Object
- #format_update_float_words(header, key, values) ⇒ Object
- #genotype_update(header, values) ⇒ Object
- #id ⇒ Object
- #info_fields(header) ⇒ Object
- #info_get(header, key, type) ⇒ Object
- #info_present?(header, key, type) ⇒ Boolean
- #info_update(header, key, type_value, values) ⇒ Object
- #max_unpack=(level) ⇒ Object
- #set_alleles(header, value) ⇒ Object
- #set_id(header, id) ⇒ Object
- #subset(header, map) ⇒ Object
Class Method Details
.create ⇒ Object
240 |
# File 'ext/htslib_native/native_bcf.c', line 240 static VALUE native_bcf_record_create(VALUE klass) { return wrap_bcf_record(bcf_init()); } |
Instance Method Details
#alleles ⇒ Object
259 |
# File 'ext/htslib_native/native_bcf.c', line 259
static VALUE native_bcf_record_alleles(VALUE self) { bcf1_t *r=get_bcf_record(self)->pointer; int i; VALUE a; check_bcf_unpack(r,BCF_UN_STR); a=rb_ary_new_capa(r->n_allele); for(i=0;i<r->n_allele;i++){if(!r->d.allele[i])raise_bcf_record_error("BCF allele is missing after unpack");rb_ary_push(a,rb_str_new_cstr(r->d.allele[i]));} return a; }
|
#core_get(field) ⇒ Object
242 243 244 245 246 247 248 249 |
# File 'ext/htslib_native/native_bcf.c', line 242
static VALUE native_bcf_record_core_get(VALUE self,VALUE field) {
bcf1_t *r=get_bcf_record(self)->pointer; ID id=SYM2ID(field);
if(id==rb_intern("rid"))return INT2NUM(r->rid);
if(id==rb_intern("pos"))return LL2NUM(r->pos);
if(id==rb_intern("rlen"))return LL2NUM(r->rlen);
if(id==rb_intern("qual"))return DBL2NUM(r->qual);
rb_raise(rb_eArgError,"unknown BCF field");
}
|
#core_set(field, value) ⇒ Object
250 251 252 253 254 255 256 |
# File 'ext/htslib_native/native_bcf.c', line 250
static VALUE native_bcf_record_core_set(VALUE self,VALUE field,VALUE value) {
bcf1_t *r=get_bcf_record(self)->pointer; ID id=SYM2ID(field);
if(id==rb_intern("rid"))r->rid=NUM2INT(value); else if(id==rb_intern("pos"))r->pos=NUM2LL(value);
else if(id==rb_intern("qual"))r->qual=(float)NUM2DBL(value);
else rb_raise(rb_eArgError,"unknown BCF field");
return value;
}
|
#duplicate ⇒ Object
241 |
# File 'ext/htslib_native/native_bcf.c', line 241
static VALUE native_bcf_record_duplicate(VALUE self) { return wrap_bcf_record(bcf_dup(get_bcf_record(self)->pointer)); }
|
#filter_ids ⇒ Object
261 |
# File 'ext/htslib_native/native_bcf.c', line 261
static VALUE native_bcf_record_filter_ids(VALUE self) { bcf1_t *r=get_bcf_record(self)->pointer; int i; VALUE a; check_bcf_unpack(r,BCF_UN_FLT); a=rb_ary_new_capa(r->d.n_flt); for(i=0;i<r->d.n_flt;i++)rb_ary_push(a,INT2NUM(r->d.flt[i])); return a; }
|
#filter_names(header) ⇒ Object
262 |
# File 'ext/htslib_native/native_bcf.c', line 262
static VALUE native_bcf_record_filter_names(VALUE self,VALUE header) { bcf1_t *r=get_bcf_record(self)->pointer; bcf_hdr_t *h=get_bcf_header(header)->pointer; int i; VALUE a; check_bcf_unpack(r,BCF_UN_FLT); a=rb_ary_new_capa(r->d.n_flt); for(i=0;i<r->d.n_flt;i++)rb_ary_push(a,rb_str_new_cstr(checked_bcf_id(h,r->d.flt[i]))); return a; }
|
#format_delete(header, key, type) ⇒ Object
394 |
# File 'ext/htslib_native/native_bcf.c', line 394
static VALUE native_bcf_format_delete(VALUE self,VALUE header,VALUE key,VALUE type) {return INT2NUM(bcf_update_format(get_bcf_header(header)->pointer,get_bcf_record(self)->pointer,StringValueCStr(key),NULL,0,NUM2INT(type)));}
|
#format_fields(header) ⇒ Object
278 |
# File 'ext/htslib_native/native_bcf.c', line 278
static VALUE native_bcf_record_format_fields(VALUE self,VALUE header) { return field_rows(get_bcf_header(header)->pointer,get_bcf_record(self)->pointer,1); }
|
#format_get(header_value, key_value, type_value, raw_value) ⇒ Object
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'ext/htslib_native/native_bcf.c', line 356
static VALUE native_bcf_format_get(VALUE self,VALUE header_value,VALUE key_value,VALUE type_value,VALUE raw_value) {
bcf_hdr_t*h=get_bcf_header(header_value)->pointer;bcf1_t*r=get_bcf_record(self)->pointer;int type=NUM2INT(type_value),cap=0,count;void*dst=NULL;
if(type==BCF_HT_STR){
char **strings=NULL;
int sample_count=bcf_hdr_nsamples(h);
bcf_string_result_t result;
count=bcf_get_format_string(h,r,StringValueCStr(key_value),&strings,&cap);
if(count<0){const char *key=StringValueCStr(key_value);free(strings);if(count==-3)return Qnil;raise_bcf_field_read_error("FormatReadError",key,count);}
result.strings=strings;result.sample_count=sample_count;
return rb_ensure(bcf_string_result_to_ruby,(VALUE)(uintptr_t)&result,
bcf_string_result_free,(VALUE)(uintptr_t)&result);
}
count=bcf_get_format_values(h,r,StringValueCStr(key_value),&dst,&cap,type);if(count<0){const char *key=StringValueCStr(key_value);free(dst);if(count==-3)return Qnil;raise_bcf_field_read_error("FormatReadError",key,count);}
bcf_format_result_t result={dst,count,type,raw_value};
return rb_ensure(bcf_format_result_to_ruby,(VALUE)(uintptr_t)&result,
bcf_value_result_free,(VALUE)(uintptr_t)&result);
}
|
#format_record(header) ⇒ Object
263 |
# File 'ext/htslib_native/native_bcf.c', line 263
static VALUE native_bcf_record_to_s(VALUE self,VALUE header) { kstring_t s=KS_INITIALIZE; VALUE v; if(vcf_format(get_bcf_header(header)->pointer,get_bcf_record(self)->pointer,&s)<0){free(s.s);rb_raise(rb_eRuntimeError,"failed to format BCF record");}v=rb_str_new(s.s,s.l);free(s.s);return v; }
|
#format_update(header, key, type_value, values) ⇒ Object
373 374 375 376 377 378 |
# File 'ext/htslib_native/native_bcf.c', line 373
static VALUE native_bcf_format_update(VALUE self,VALUE header,VALUE key,VALUE type_value,VALUE values) {
bcf_hdr_t*h=get_bcf_header(header)->pointer;bcf1_t*r=get_bcf_record(self)->pointer;int type=NUM2INT(type_value),n,i,result;VALUE storage=0;
if(type==BCF_HT_INT){int32_t*p;n=RARRAY_LEN(values);p=ALLOCV_N(int32_t,storage,n?n:1);for(i=0;i<n;i++)p[i]=NUM2INT(rb_ary_entry(values,i));result=bcf_update_format_int32(h,r,StringValueCStr(key),p,n);ALLOCV_END(storage);}
else if(type==BCF_HT_REAL){float*p;n=RARRAY_LEN(values);p=ALLOCV_N(float,storage,n?n:1);for(i=0;i<n;i++)p[i]=(float)NUM2DBL(rb_ary_entry(values,i));result=bcf_update_format_float(h,r,StringValueCStr(key),p,n);ALLOCV_END(storage);}
else {int i;char**strings;n=RARRAY_LEN(values);strings=ALLOCV_N(char*,storage,n?n:1);for(i=0;i<n;i++){VALUE string=rb_ary_entry(values,i);strings[i]=StringValueCStr(string);}result=bcf_update_format_string(h,r,StringValueCStr(key),(const char**)strings,n);ALLOCV_END(storage);}return INT2NUM(result);
}
|
#format_update_float_words(header, key, values) ⇒ Object
379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'ext/htslib_native/native_bcf.c', line 379
static VALUE native_bcf_format_update_float_words(VALUE self,VALUE header,VALUE key,VALUE values) {
bcf_hdr_t *h=get_bcf_header(header)->pointer;
bcf1_t *r=get_bcf_record(self)->pointer;
int n=RARRAY_LEN(values),i,result;
VALUE storage=0;
float *floats=ALLOCV_N(float,storage,n?n:1);
for(i=0;i<n;i++){
uint32_t word=NUM2UINT(rb_ary_entry(values,i));
memcpy(&floats[i],&word,sizeof(word));
}
result=bcf_update_format_float(h,r,StringValueCStr(key),floats,n);
ALLOCV_END(storage);
return INT2NUM(result);
}
|
#genotype_update(header, values) ⇒ Object
393 |
# File 'ext/htslib_native/native_bcf.c', line 393
static VALUE native_bcf_genotype_update(VALUE self,VALUE header,VALUE values) {VALUE storage=0;int32_t*p;int n=RARRAY_LEN(values),i;p=ALLOCV_N(int32_t,storage,n?n:1);for(i=0;i<n;i++)p[i]=NUM2INT(rb_ary_entry(values,i));int result=bcf_update_genotypes(get_bcf_header(header)->pointer,get_bcf_record(self)->pointer,p,n);ALLOCV_END(storage);return INT2NUM(result);}
|
#id ⇒ Object
257 |
# File 'ext/htslib_native/native_bcf.c', line 257
static VALUE native_bcf_record_id(VALUE self) { bcf1_t *r=get_bcf_record(self)->pointer; check_bcf_unpack(r,BCF_UN_STR); if(!r->d.id)raise_bcf_record_error("BCF record ID is missing after unpack"); return rb_str_new_cstr(r->d.id); }
|
#info_fields(header) ⇒ Object
277 |
# File 'ext/htslib_native/native_bcf.c', line 277
static VALUE native_bcf_record_info_fields(VALUE self,VALUE header) { return field_rows(get_bcf_header(header)->pointer,get_bcf_record(self)->pointer,0); }
|
#info_get(header, key, type) ⇒ Object
324 |
# File 'ext/htslib_native/native_bcf.c', line 324
static VALUE native_bcf_info_get(VALUE self,VALUE header,VALUE key,VALUE type) { return info_get(self,header,key,type); }
|
#info_present?(header, key, type) ⇒ Boolean
325 |
# File 'ext/htslib_native/native_bcf.c', line 325
static VALUE native_bcf_info_present(VALUE self,VALUE header,VALUE key,VALUE type) { return NIL_P(info_get(self,header,key,type))?Qfalse:Qtrue; }
|
#info_update(header, key, type_value, values) ⇒ Object
326 327 328 329 330 331 332 333 334 335 336 |
# File 'ext/htslib_native/native_bcf.c', line 326
static VALUE native_bcf_info_update(VALUE self,VALUE header,VALUE key,VALUE type_value,VALUE values) {
bcf_hdr_t*h=get_bcf_header(header)->pointer;bcf1_t*r=get_bcf_record(self)->pointer;int type=NUM2INT(type_value),n,i,result;void*data=NULL;VALUE storage=0;
if(type!=BCF_HT_FLAG && (NIL_P(values) || values==Qfalse)){
return INT2NUM(bcf_update_info(h,r,StringValueCStr(key),NULL,0,type));
}
if(type==BCF_HT_INT){int32_t*p;n=RARRAY_LEN(values);p=ALLOCV_N(int32_t,storage,n?n:1);for(i=0;i<n;i++)p[i]=NUM2INT(rb_ary_entry(values,i));data=p;result=bcf_update_info(h,r,StringValueCStr(key),data,n,type);ALLOCV_END(storage);}
else if(type==BCF_HT_REAL){float*p;n=RARRAY_LEN(values);p=ALLOCV_N(float,storage,n?n:1);for(i=0;i<n;i++)p[i]=(float)NUM2DBL(rb_ary_entry(values,i));data=p;result=bcf_update_info(h,r,StringValueCStr(key),data,n,type);ALLOCV_END(storage);}
else if(type==BCF_HT_STR){result=bcf_update_info(h,r,StringValueCStr(key),StringValueCStr(values),1,type);}
else { n=RTEST(values)?1:0; result=bcf_update_info(h,r,StringValueCStr(key),NULL,n,type); }
return INT2NUM(result);
}
|
#max_unpack=(level) ⇒ Object
264 |
# File 'ext/htslib_native/native_bcf.c', line 264
static VALUE native_bcf_record_set_unpack(VALUE self,VALUE level){get_bcf_record(self)->pointer->max_unpack=NUM2INT(level);return level;}
|
#set_alleles(header, value) ⇒ Object
260 |
# File 'ext/htslib_native/native_bcf.c', line 260
static VALUE native_bcf_record_set_alleles(VALUE self,VALUE header,VALUE value) { return INT2NUM(bcf_update_alleles_str(get_bcf_header(header)->pointer,get_bcf_record(self)->pointer,StringValueCStr(value))); }
|
#set_id(header, id) ⇒ Object
258 |
# File 'ext/htslib_native/native_bcf.c', line 258
static VALUE native_bcf_record_set_id(VALUE self,VALUE header,VALUE id) { return INT2NUM(bcf_update_id(get_bcf_header(header)->pointer,get_bcf_record(self)->pointer,StringValueCStr(id))); }
|
#subset(header, map) ⇒ Object
265 |
# File 'ext/htslib_native/native_bcf.c', line 265
static VALUE native_bcf_record_subset(VALUE self,VALUE header,VALUE map){VALUE storage=0;int count=RARRAY_LEN(map),i,*imap=ALLOCV_N(int,storage,count?count:1);for(i=0;i<count;i++)imap[i]=NUM2INT(rb_ary_entry(map,i));int result=bcf_subset(get_bcf_header(header)->pointer,get_bcf_record(self)->pointer,count,imap);ALLOCV_END(storage);return INT2NUM(result);}
|