edlib 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72ca7381d858e17e8ba5e2641d072cb4f391410b97ef9138504efa6851020373
4
- data.tar.gz: 180e15f4a09149af7031536817a635be580d55afd25896341cb44cf54a9902be
3
+ metadata.gz: b4014e8ff49033ae36755f0752dba89486afc104ad67cf528358a3e1d12d2cfd
4
+ data.tar.gz: 4241313686e900f0d5751f10375f5afc347208737f66d19830c8b89add5e02f0
5
5
  SHA512:
6
- metadata.gz: 5f53003d5e12d9d55b40201f435a278b4a99d6e01569cf0f5e96a263822058257d3dd1b65c7c0f48d39a92177c271131d7752bf982c68893316e5dccbdeefc9f
7
- data.tar.gz: 27e1ec9237c5f86fe8775100dbda7e2b9851071a9043cace94b927a65e372afa0b7cbbca741d51266b1f2a0493917eeaf1b4b60da92600def529b2e4ac724edb
6
+ metadata.gz: 586d9f3730505eb43b61eee2d875af40d8aa0f2cc852fd342ebea69566e83f8255f291d4f29b2c731591ec0c29d7057cfff3065707e537acedcf7fcd66cb4cd2
7
+ data.tar.gz: f18b99c6456cc9c62a052ea0cf873832d537001a8d92add2073faf14f77fe103b09de3d0888d02a2ab92d4ce4c5982ea4125dccd93263b150172db6af925788c
data/README.md CHANGED
@@ -38,6 +38,26 @@ a.align("AACG", "TCAACCTG")
38
38
  |task |DISTANCE, LOC, PATH ["DISTANCE"] |
39
39
  |additional_equalities|List of pairs of characters, where each pair defines two characters as equal. [NULL]|
40
40
 
41
+
42
+ ```ruby
43
+ a.align("AACG", "TCAACCTG", nice: true)
44
+
45
+ # {
46
+ # :edit_distance=>1,
47
+ # :alphabet_length=>4,
48
+ # :locations=>[[2, 4], [2, 5]],
49
+ # :alignment=>[0, 0, 0, 1],
50
+ # :cigar=>"3=1I",
51
+ # :query_aligned=>"AACG",
52
+ # :match_aligned=>"|||-",
53
+ # :target_aligned=>"AAC-"
54
+ # }
55
+ ```
56
+
57
+ ## Documentation
58
+
59
+ https://kojix2.github.io/ruby-edlib/
60
+
41
61
  ## Development
42
62
 
43
63
  Pull requests welcome!
data/ext/edlib/edlib.cpp CHANGED
@@ -889,10 +889,10 @@ static int myersCalcEditDistanceNW(const Word* const Peq, const int W, const int
889
889
  (*alignData)->Ps[maxNumBlocks * c + b] = bl->P;
890
890
  (*alignData)->Ms[maxNumBlocks * c + b] = bl->M;
891
891
  (*alignData)->scores[maxNumBlocks * c + b] = bl->score;
892
- (*alignData)->firstBlocks[c] = firstBlock;
893
- (*alignData)->lastBlocks[c] = lastBlock;
894
892
  bl++;
895
893
  }
894
+ (*alignData)->firstBlocks[c] = firstBlock;
895
+ (*alignData)->lastBlocks[c] = lastBlock;
896
896
  }
897
897
  //----------------------------------------------------------//
898
898
  //---- If this is stop column, save it and finish ----//
@@ -901,9 +901,9 @@ static int myersCalcEditDistanceNW(const Word* const Peq, const int W, const int
901
901
  (*alignData)->Ps[b] = (blocks + b)->P;
902
902
  (*alignData)->Ms[b] = (blocks + b)->M;
903
903
  (*alignData)->scores[b] = (blocks + b)->score;
904
- (*alignData)->firstBlocks[0] = firstBlock;
905
- (*alignData)->lastBlocks[0] = lastBlock;
906
904
  }
905
+ (*alignData)->firstBlocks[0] = firstBlock;
906
+ (*alignData)->lastBlocks[0] = lastBlock;
907
907
  *bestScore_ = -1;
908
908
  *position_ = targetStopPosition;
909
909
  delete[] blocks;
data/ext/edlib/edlibext.c CHANGED
@@ -1,20 +1,20 @@
1
1
  #include "ruby.h"
2
2
  #include "edlibext.h"
3
3
 
4
- #define ALIGNER_GET_(name) \
5
- static VALUE \
6
- aligner_get_##name(VALUE self) \
7
- { \
8
- EdlibAlignConfig *config = aligner_get_config(self); \
9
- return get_##name(config); \
4
+ #define ALIGNER_GET_(name) \
5
+ static VALUE \
6
+ aligner_get_##name(VALUE self) \
7
+ { \
8
+ EdlibAlignConfig *config = aligner_get_config(self); \
9
+ return get_##name(config); \
10
10
  }
11
11
 
12
- #define ALIGNER_SET_(name) \
13
- static VALUE \
14
- aligner_set_##name(VALUE self, VALUE value) \
15
- { \
16
- EdlibAlignConfig *config = aligner_get_config(self); \
17
- return set_##name(config, value); \
12
+ #define ALIGNER_SET_(name) \
13
+ static VALUE \
14
+ aligner_set_##name(VALUE self, VALUE value) \
15
+ { \
16
+ EdlibAlignConfig *config = aligner_get_config(self); \
17
+ return set_##name(config, value); \
18
18
  }
19
19
 
20
20
  VALUE mEdlib;
@@ -26,12 +26,12 @@ static size_t aligner_config_memsize(const void *ptr);
26
26
  static void aligner_config_free(void *ptr);
27
27
 
28
28
  static const rb_data_type_t config_type = {
29
- .wrap_struct_name = "RbAlignConfig",
30
- .function = {
31
- .dfree = aligner_config_free,
32
- .dsize = aligner_config_memsize,
33
- },
34
- .flags = RUBY_TYPED_FREE_IMMEDIATELY,
29
+ .wrap_struct_name = "RbAlignConfig",
30
+ .function = {
31
+ .dfree = aligner_config_free,
32
+ .dsize = aligner_config_memsize,
33
+ },
34
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
35
35
  };
36
36
 
37
37
  static VALUE
@@ -131,8 +131,8 @@ set_mode(EdlibAlignConfig *config, VALUE mode)
131
131
  switch (TYPE(mode))
132
132
  {
133
133
  case T_STRING:;
134
- VALUE mode_str = rb_funcall(mode, rb_intern("upcase"), 0);
135
- char *mode_s = RSTRING_PTR(mode_str);
134
+ VALUE mode_str = rb_funcall(mode, rb_intern("upcase"), 0);
135
+ char *mode_s = RSTRING_PTR(mode_str);
136
136
  if (strcmp(mode_s, "NW") == 0)
137
137
  {
138
138
  config->mode = EDLIB_MODE_NW;
@@ -252,7 +252,7 @@ static VALUE
252
252
  set_additional_equalities(EdlibAlignConfig *config, EdlibEqualityPair *eqpairs, VALUE equalities)
253
253
  {
254
254
  Check_Type(equalities, T_ARRAY);
255
- int len = RARRAY_LEN(equalities);
255
+ size_t len = RARRAY_LEN(equalities);
256
256
  if (len == 0)
257
257
  {
258
258
  if (eqpairs != NULL)
@@ -264,9 +264,25 @@ set_additional_equalities(EdlibAlignConfig *config, EdlibEqualityPair *eqpairs,
264
264
  config->additionalEqualitiesLength = 0;
265
265
  return equalities;
266
266
  }
267
+
268
+ // Check if len is too large
269
+ if (len > SIZE_MAX / sizeof(EdlibEqualityPair))
270
+ {
271
+ rb_raise(rb_eArgError, "Requested array is too large");
272
+ }
273
+
267
274
  char *first_arr = malloc(len * sizeof(char));
268
275
  char *second_arr = malloc(len * sizeof(char));
269
- for (int i = 0; i < len; i++)
276
+ if (first_arr == NULL || second_arr == NULL)
277
+ {
278
+ if (first_arr != NULL)
279
+ free(first_arr);
280
+ if (second_arr != NULL)
281
+ free(second_arr);
282
+ rb_raise(rb_eNoMemError, "Failed to allocate memory for equality pairs");
283
+ }
284
+
285
+ for (size_t i = 0; i < len; i++)
270
286
  {
271
287
  VALUE pair = rb_ary_entry(equalities, i);
272
288
  Check_Type(pair, T_ARRAY);
@@ -295,7 +311,7 @@ set_additional_equalities(EdlibAlignConfig *config, EdlibEqualityPair *eqpairs,
295
311
 
296
312
  eqpairs = (EdlibEqualityPair *)malloc(sizeof(EdlibEqualityPair) * len);
297
313
 
298
- for (int i = 0; i < len; i++)
314
+ for (size_t i = 0; i < len; i++)
299
315
  {
300
316
  eqpairs[i].first = first_arr[i];
301
317
  eqpairs[i].second = second_arr[i];
@@ -341,7 +357,7 @@ aligner_initialize_raw(VALUE self, VALUE k, VALUE mode, VALUE task, VALUE additi
341
357
  config->k = NUM2INT(k);
342
358
  set_mode(config, mode);
343
359
  set_task(config, task);
344
-
360
+
345
361
  if (additional_equalities != Qnil)
346
362
  {
347
363
  set_additional_equalities(config, eqpairs, additional_equalities);
@@ -365,11 +381,11 @@ aligner_align(VALUE self, VALUE query, VALUE target)
365
381
  }
366
382
 
367
383
  EdlibAlignResult result = edlibAlign(
368
- StringValueCStr(query),
369
- RSTRING_LEN(query),
370
- StringValueCStr(target),
371
- RSTRING_LEN(target),
372
- *config);
384
+ StringValueCStr(query),
385
+ RSTRING_LEN(query),
386
+ StringValueCStr(target),
387
+ RSTRING_LEN(target),
388
+ *config);
373
389
 
374
390
  if (result.status != 0)
375
391
  {
data/lib/edlib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Edlib
4
- VERSION = '0.0.7'
4
+ VERSION = '0.0.8'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-07 00:00:00.000000000 Z
11
+ date: 2024-08-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'Lightweight, super fast C/C++ library for sequence alignment using edit
14
14
  (Levenshtein) distance. '
@@ -31,7 +31,7 @@ homepage: https://github.com/kojix2/ruby-edlib
31
31
  licenses:
32
32
  - MIT
33
33
  metadata: {}
34
- post_install_message:
34
+ post_install_message:
35
35
  rdoc_options: []
36
36
  require_paths:
37
37
  - lib
@@ -46,8 +46,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  requirements: []
49
- rubygems_version: 3.3.7
50
- signing_key:
49
+ rubygems_version: 3.5.11
50
+ signing_key:
51
51
  specification_version: 4
52
52
  summary: ruby-edlib is a wrapper for edlib.
53
53
  test_files: []