Class: Edlib::Aligner

Inherits:
Object
  • Object
show all
Defined in:
lib/edlib.rb,
ext/edlib/edlibext.c

Instance Method Summary collapse

Constructor Details

#initialize(k: -1,, mode: 'NW', task: 'DISTANCE', additional_equalities: nil) ⇒ Aligner

Returns a new instance of Aligner.



7
8
9
10
11
12
13
# File 'lib/edlib.rb', line 7

def initialize(k: -1, mode: 'NW', task: 'DISTANCE', additional_equalities: nil)
  mode = mode.to_s if mode.is_a? Symbol
  task = task.to_s if task.is_a? Symbol
  mode = mode.upcase if mode.is_a? String
  task = task.upcase if task.is_a? String
  initialize_raw(k, mode, task, additional_equalities)
end

Instance Method Details

#additional_equalitiesObject

#additional_equalities=(equalities) ⇒ Object



329
330
331
332
333
334
335
# File 'ext/edlib/edlibext.c', line 329

static VALUE
aligner_set_additional_equalities(VALUE self, VALUE equalities)
{
	EdlibAlignConfig *config = aligner_get_config(self);
	EdlibEqualityPair *eqpairs = aligner_get_equalityPairs(self);
	return set_additional_equalities(config, eqpairs, equalities);
}

#align(query, target, nice: false) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/edlib.rb', line 15

def align(query, target, nice: false)
  if nice
    align_nice(query, target)
  else
    align_raw(query, target)
  end
end

#align_raw(query, target) ⇒ Object



374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'ext/edlib/edlibext.c', line 374

static VALUE
aligner_align(VALUE self, VALUE query, VALUE target)
{
	EdlibAlignConfig *config = aligner_get_config(self);
	if (!config)
	{
		rb_raise(rb_eRuntimeError, "config is NULL");
	}

	EdlibAlignResult result = edlibAlign(
			StringValueCStr(query),
			RSTRING_LEN(query),
			StringValueCStr(target),
			RSTRING_LEN(target),
			*config);

	if (result.status != 0)
	{
		rb_raise(rb_eRuntimeError, "edlibAlign failed");
	}

	VALUE edit_distance = INT2NUM(result.editDistance);
	VALUE alphabet_length = INT2NUM(result.alphabetLength);
	VALUE locations = rb_ary_new();
	VALUE alignment = rb_ary_new();
	VALUE cigar;

	int *el = result.endLocations;
	int *sl = result.startLocations;
	for (int i = 0; i < result.numLocations; i++)
	{
		VALUE ary = rb_ary_new();
		if (sl)
		{
			rb_ary_push(ary, INT2NUM(sl[i]));
		}
		else
		{
			rb_ary_push(ary, Qnil);
		}
		if (el)
		{
			rb_ary_push(ary, INT2NUM(el[i]));
		}
		else
		{
			rb_ary_push(ary, Qnil);
		}
		rb_ary_push(locations, ary);
	}

	for (int i = 0; i < result.alignmentLength; i++)
	{
		rb_ary_push(alignment, UINT2NUM(result.alignment[i]));
	}

	char *ccigar = edlibAlignmentToCigar(result.alignment, result.alignmentLength, 1); // EDLIB_CIGAR_EXTENDED
	cigar = rb_str_new2(ccigar);
	free(ccigar);

	VALUE hash = rb_hash_new();
	rb_hash_aset(hash, ID2SYM(rb_intern("edit_distance")), edit_distance);
	rb_hash_aset(hash, ID2SYM(rb_intern("alphabet_length")), alphabet_length);
	rb_hash_aset(hash, ID2SYM(rb_intern("locations")), locations);
	rb_hash_aset(hash, ID2SYM(rb_intern("alignment")), alignment);
	rb_hash_aset(hash, ID2SYM(rb_intern("cigar")), cigar);

	edlibFreeAlignResult(result);

	return hash;
}

#configObject



337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'ext/edlib/edlibext.c', line 337

static VALUE
aligner_config_hash(VALUE self)
{
	EdlibAlignConfig *config = aligner_get_config(self);

	VALUE hash = rb_hash_new();

	rb_hash_aset(hash, ID2SYM(rb_intern("k")), get_k(config));
	rb_hash_aset(hash, ID2SYM(rb_intern("mode")), get_mode(config));
	rb_hash_aset(hash, ID2SYM(rb_intern("task")), get_task(config));
	rb_hash_aset(hash, ID2SYM(rb_intern("additional_equalities")), get_additional_equalities(config));

	return hash;
}

#kObject

#k=Object

#modeObject

#mode=Object

#taskObject

#task=Object