minimap2 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09e4267638f072ee219b2af3ef1afd3938c3a6d02f5370aa9454b25b871652b7'
4
- data.tar.gz: ab035c12eb6d6bda353ffab1b5f5923ec8327fea9a4552259b01b02523b7f934
3
+ metadata.gz: 7c74321430e1bfb742b2717a27967cc9a801ac2d65308831cecb7824ca7553b8
4
+ data.tar.gz: 92950765d1d18ca0855ee5de981e56e33be4499015e7a1e28ee52409d68845e5
5
5
  SHA512:
6
- metadata.gz: 8f24c1f2d8e07e1be825fbc2a67049d378c1e1d5f3d23312d474e796fa7968b7d85b58b061226dbf4a14e637c27708667a5737da246e4874f03cadf9df4f013e
7
- data.tar.gz: 5e92b4c08e02416b0385c9a5a6b6c7b46381469ae70447fea80a9269a06e1ac11155a06de3d3a4a97995880f542d8adf9cd6063afa2c133be474644dd6d3245f
6
+ metadata.gz: 339fa71b957f497298422d4c5f21554e9cf7ea01036ba64c7b34fadc44e16ecb34125f5ec92aca91eb0e103a443a349b78d4613f07a7e94f35f2a5e745ab17d5
7
+ data.tar.gz: 0230b2e2b1bea4aebf9611012de44781a56bd94e42a5208604e64c7892df9547a6e67d5db4547f546e227abc4d9010a393d6d0d8506e2e8162e1099172edecd1
data/README.md CHANGED
@@ -4,6 +4,9 @@
4
4
  [![CI](https://github.com/kojix2/ruby-minimap2/workflows/CI/badge.svg)](https://github.com/kojix2/ruby-minimap2/actions)
5
5
  [![The MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.txt)
6
6
  [![Docs Latest](https://img.shields.io/badge/docs-stable-blue.svg)](https://rubydoc.info/gems/minimap2)
7
+ [![DOI](https://zenodo.org/badge/325711305.svg)](https://zenodo.org/badge/latestdoi/325711305)
8
+
9
+
7
10
 
8
11
  :dna: [minimap2](https://github.com/lh3/minimap2) - the long-read mapper - for [Ruby](https://github.com/ruby/ruby)
9
12
 
@@ -14,7 +17,7 @@ You need to install ruby-minimap2 from the source code. Because you need to buil
14
17
  Build
15
18
 
16
19
  ```sh
17
- git clone --recurse-submodules https://github.com/kojix2/ruby-minimap2
20
+ git clone --recursive https://github.com/kojix2/ruby-minimap2
18
21
  cd ruby-minimap2
19
22
  bundle install
20
23
  bundle exec rake minimap2:build
@@ -40,27 +43,26 @@ aligner = Minimap2::Aligner.new("minimap2/test/MT-human.fa")
40
43
  seq = aligner.seq("MT_human", 100, 200)
41
44
 
42
45
  # mapping
43
- aligner.align(seq) do |h|
44
- pp h.to_h
45
- # {:ctg => "MT_human",
46
- # :ctg_len => 16569,
47
- # :r_st => 100,
48
- # :r_en => 200,
49
- # :strand => 1,
50
- # :trans_strand => 0,
51
- # :blen => 100,
52
- # :mlen => 100,
53
- # :nm => 0,
54
- # :primary => 1,
55
- # :q_st => 0,
56
- # :q_en => 100,
57
- # :mapq => 60,
58
- # :cigar => [[100, 0]],
59
- # :read_num => 1,
60
- # :cs => "",
61
- # :md => "",
62
- # :cigar_str => "100M"}
63
- end
46
+ hits = aligner.align(seq)
47
+ pp hits[0].to_h
48
+ # {:ctg => "MT_human",
49
+ # :ctg_len => 16569,
50
+ # :r_st => 100,
51
+ # :r_en => 200,
52
+ # :strand => 1,
53
+ # :trans_strand => 0,
54
+ # :blen => 100,
55
+ # :mlen => 100,
56
+ # :nm => 0,
57
+ # :primary => 1,
58
+ # :q_st => 0,
59
+ # :q_en => 100,
60
+ # :mapq => 60,
61
+ # :cigar => [[100, 0]],
62
+ # :read_num => 1,
63
+ # :cs => "",
64
+ # :md => "",
65
+ # :cigar_str => "100M"}
64
66
  ```
65
67
 
66
68
  ## APIs Overview
@@ -121,7 +123,7 @@ ruby-minimap2 is built on top of [Ruby-FFI](https://github.com/ffi/ffi). Native
121
123
  Fork your repository and clone.
122
124
 
123
125
  ```sh
124
- git clone --recurse-submodules https://github.com/kojix2/ruby-minimap2
126
+ git clone --recursive https://github.com/kojix2/ruby-minimap2
125
127
  # git clone https://github.com/kojix2/ruby-minimap2
126
128
  # cd ruby-minimap2
127
129
  # git submodule update -i
@@ -80,7 +80,7 @@ module Minimap2
80
80
  end
81
81
 
82
82
  if fn_idx_in
83
- warn "Since fn_idx_in is specified, the seq argument will be ignored." if seq
83
+ warn 'Since fn_idx_in is specified, the seq argument will be ignored.' if seq
84
84
  reader = FFI.mm_idx_reader_open(fn_idx_in, idx_opt, fn_idx_out)
85
85
 
86
86
  # The Ruby version raises an error here
@@ -116,6 +116,7 @@ module Minimap2
116
116
  # In the Ruby language, the name map means iterator.
117
117
  # The original name is map, but here I use the method name align.
118
118
  # @note The use of Enumerator is being considered. The method names may change again.
119
+ # @return [Array] alignments
119
120
 
120
121
  def align(
121
122
  seq, seq2 = nil,
@@ -133,25 +134,29 @@ module Minimap2
133
134
 
134
135
  buf ||= FFI::TBuf.new
135
136
  km = FFI.mm_tbuf_get_km(buf)
136
- n_regs_ptr = ::FFI::MemoryPointer.new :int
137
137
 
138
- ptr = FFI.mm_map_aux(index, seq, seq2, n_regs_ptr, buf, map_opt)
138
+ n_regs_ptr = ::FFI::MemoryPointer.new :int
139
+ regs_ptr = FFI.mm_map_aux(index, seq, seq2, n_regs_ptr, buf, map_opt)
139
140
  n_regs = n_regs_ptr.read_int
140
141
 
141
- regs = Array.new(n_regs) { |i| FFI::Reg1.new(ptr + i * FFI::Reg1.size) }
142
+ regs = Array.new(n_regs) do |i|
143
+ FFI::Reg1.new(regs_ptr + i * FFI::Reg1.size)
144
+ end
142
145
 
143
146
  hit = FFI::Hit.new
147
+
144
148
  cs_str = ::FFI::MemoryPointer.new(::FFI::MemoryPointer.new(:string))
145
149
  m_cs_str = ::FFI::MemoryPointer.new :int
150
+
151
+ alignments = []
152
+
146
153
  i = 0
147
154
  begin
148
155
  while i < n_regs
149
156
  FFI.mm_reg2hitpy(index, regs[i], hit)
150
- cigar = []
151
157
 
152
158
  c = hit[:cigar32].read_array_of_uint32(hit[:n_cigar32])
153
- # convert the 32-bit CIGAR encoding to Ruby array
154
- cigar = c.map { |x| [x >> 4, x & 0xf] }
159
+ cigar = c.map { |x| [x >> 4, x & 0xf] } # 32-bit CIGAR encoding -> Ruby array
155
160
 
156
161
  _cs = ''
157
162
  if cs
@@ -165,7 +170,7 @@ module Minimap2
165
170
  _md = cs_str.read_pointer.read_string(l_cs_str)
166
171
  end
167
172
 
168
- yield Alignment.new(hit, cigar, _cs, _md)
173
+ alignments << Alignment.new(hit, cigar, _cs, _md)
169
174
 
170
175
  FFI.mm_free_reg1(regs[i])
171
176
  i += 1
@@ -176,6 +181,7 @@ module Minimap2
176
181
  i += 1
177
182
  end
178
183
  end
184
+ alignments
179
185
  end
180
186
 
181
187
  # retrieve a subsequence from the index.
@@ -193,11 +199,13 @@ module Minimap2
193
199
  end
194
200
 
195
201
  # k-mer length, no larger than 28
202
+
196
203
  def k
197
204
  index[:k]
198
205
  end
199
206
 
200
207
  # minimizer window size, no larger than 255
208
+
201
209
  def w
202
210
  index[:w]
203
211
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minimap2
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minimap2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-14 00:00:00.000000000 Z
11
+ date: 2021-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi