minimap2 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +93 -13
- data/lib/minimap2.rb +9 -9
- data/lib/minimap2/aligner.rb +87 -51
- data/lib/minimap2/alignment.rb +53 -9
- data/lib/minimap2/ffi.rb +4 -4
- data/lib/minimap2/ffi/functions.rb +7 -7
- data/lib/minimap2/ffi/mappy.rb +2 -2
- data/lib/minimap2/ffi_helper.rb +1 -1
- data/lib/minimap2/version.rb +1 -1
- metadata +2 -3
- data/vendor/libminimap2.so +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09e4267638f072ee219b2af3ef1afd3938c3a6d02f5370aa9454b25b871652b7'
|
4
|
+
data.tar.gz: ab035c12eb6d6bda353ffab1b5f5923ec8327fea9a4552259b01b02523b7f934
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f24c1f2d8e07e1be825fbc2a67049d378c1e1d5f3d23312d474e796fa7968b7d85b58b061226dbf4a14e637c27708667a5737da246e4874f03cadf9df4f013e
|
7
|
+
data.tar.gz: 5e92b4c08e02416b0385c9a5a6b6c7b46381469ae70447fea80a9269a06e1ac11155a06de3d3a4a97995880f542d8adf9cd6063afa2c133be474644dd6d3245f
|
data/README.md
CHANGED
@@ -1,28 +1,33 @@
|
|
1
1
|
# Minimap2
|
2
2
|
|
3
|
+
[](https://rubygems.org/gems/minimap2)
|
3
4
|
[](https://github.com/kojix2/ruby-minimap2/actions)
|
5
|
+
[](LICENSE.txt)
|
6
|
+
[](https://rubydoc.info/gems/minimap2)
|
4
7
|
|
5
8
|
:dna: [minimap2](https://github.com/lh3/minimap2) - the long-read mapper - for [Ruby](https://github.com/ruby/ruby)
|
6
9
|
|
7
10
|
## Installation
|
8
11
|
|
9
|
-
You need to install
|
10
|
-
|
12
|
+
You need to install ruby-minimap2 from the source code. Because you need to build minimap2 and create a shared library. Open your terminal and type the following commands in order.
|
13
|
+
|
14
|
+
Build
|
11
15
|
|
12
16
|
```sh
|
13
17
|
git clone --recurse-submodules https://github.com/kojix2/ruby-minimap2
|
14
18
|
cd ruby-minimap2
|
15
19
|
bundle install
|
16
20
|
bundle exec rake minimap2:build
|
17
|
-
bundle exec rake install
|
18
21
|
```
|
19
22
|
|
20
|
-
|
23
|
+
Install
|
21
24
|
|
22
25
|
```
|
23
|
-
bundle exec rake
|
26
|
+
bundle exec rake install
|
24
27
|
```
|
25
28
|
|
29
|
+
Ruby-minimap2 is tested on Ubuntu and macOS.
|
30
|
+
|
26
31
|
## Quick Start
|
27
32
|
|
28
33
|
```ruby
|
@@ -37,40 +42,115 @@ seq = aligner.seq("MT_human", 100, 200)
|
|
37
42
|
# mapping
|
38
43
|
aligner.align(seq) do |h|
|
39
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"}
|
40
63
|
end
|
41
64
|
```
|
42
65
|
|
43
|
-
## APIs
|
66
|
+
## APIs Overview
|
44
67
|
|
45
|
-
See
|
46
|
-
* [Mappy: Minimap2 Python Binding](https://github.com/lh3/minimap2/tree/master/python)
|
68
|
+
See the [RubyDoc.info document](https://rubydoc.info/gems/minimap2) for details.
|
47
69
|
|
48
70
|
```markdown
|
49
71
|
* Minimap2 module
|
72
|
+
- fastx_read
|
73
|
+
- revcomp
|
74
|
+
|
50
75
|
* Aligner class
|
76
|
+
* attributes
|
77
|
+
- index
|
78
|
+
- idx_opt
|
79
|
+
- map_opt
|
80
|
+
* methods
|
81
|
+
- new(path, preset: nil)
|
82
|
+
- align
|
83
|
+
|
51
84
|
* Alignment class
|
85
|
+
* attributes
|
86
|
+
- ctg
|
87
|
+
- ctg_len
|
88
|
+
- r_st
|
89
|
+
- r_en
|
90
|
+
- strand
|
91
|
+
- trans_strand
|
92
|
+
- blen
|
93
|
+
- mlen
|
94
|
+
- nm
|
95
|
+
- primary
|
96
|
+
- q_st
|
97
|
+
- q_en
|
98
|
+
- mapq
|
99
|
+
- cigar
|
100
|
+
- read_num
|
101
|
+
- cs
|
102
|
+
- md
|
103
|
+
- cigar_str
|
104
|
+
* methods
|
105
|
+
- to_h
|
106
|
+
- to_s
|
107
|
+
|
108
|
+
* FFI module
|
109
|
+
* IdxOpt class
|
110
|
+
* MapOpt class
|
52
111
|
```
|
53
112
|
|
113
|
+
The ruby-minimap2 API is compliant with mappy, the official Python binding for Minimap2. However, there are a few differences. For example, the `map` method has been renamed to `align` since map is the common name for iterators in Ruby.
|
114
|
+
|
115
|
+
* [Mappy: Minimap2 Python Binding](https://github.com/lh3/minimap2/tree/master/python)
|
116
|
+
|
117
|
+
ruby-minimap2 is built on top of [Ruby-FFI](https://github.com/ffi/ffi). Native functions can be called from the FFI module, which also provides a way to access some C structs such as IdxOpt and MapOpt.
|
118
|
+
|
54
119
|
## Development
|
55
120
|
|
121
|
+
Fork your repository and clone.
|
122
|
+
|
56
123
|
```sh
|
57
124
|
git clone --recurse-submodules https://github.com/kojix2/ruby-minimap2
|
58
125
|
# git clone https://github.com/kojix2/ruby-minimap2
|
59
126
|
# cd ruby-minimap2
|
60
127
|
# git submodule update -i
|
128
|
+
```
|
129
|
+
|
130
|
+
Build.
|
131
|
+
|
132
|
+
```sh
|
61
133
|
cd ruby-minimap2
|
62
|
-
bundle install
|
134
|
+
bundle install # Install dependent packages including Ruby-FFI
|
63
135
|
bundle exec rake minimap2:build
|
136
|
+
```
|
137
|
+
|
138
|
+
Run tests.
|
139
|
+
|
140
|
+
```
|
64
141
|
bundle exec rake test
|
65
142
|
```
|
66
143
|
|
67
144
|
## Contributing
|
68
145
|
|
69
|
-
ruby-minimap2 is a library under development and there are many points to be improved.
|
70
|
-
If you improve the source code, please feel free to send us your pull request.
|
71
|
-
Typo corrections are also welcome.
|
146
|
+
ruby-minimap2 is a library under development and there are many points to be improved. Please feel free to send us your pull request.
|
72
147
|
|
73
|
-
|
148
|
+
* [Report bugs](https://github.com/kojix2/ruby-minimap2/issues)
|
149
|
+
* Fix bugs and [submit pull requests](https://github.com/kojix2/ruby-minimap2/pulls)
|
150
|
+
* Write, clarify, or fix documentation
|
151
|
+
* Suggest or add new features
|
152
|
+
* Create tools based on ruby-minimap2
|
153
|
+
* Update minimap2 in github submodule
|
74
154
|
|
75
155
|
## License
|
76
156
|
|
data/lib/minimap2.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# dependencies
|
4
|
-
require
|
4
|
+
require 'ffi'
|
5
5
|
|
6
6
|
# bit fields
|
7
|
-
require_relative
|
7
|
+
require_relative 'minimap2/ffi_helper'
|
8
8
|
|
9
9
|
# modules
|
10
|
-
require_relative
|
11
|
-
require_relative
|
12
|
-
require_relative
|
10
|
+
require_relative 'minimap2/aligner'
|
11
|
+
require_relative 'minimap2/alignment'
|
12
|
+
require_relative 'minimap2/version'
|
13
13
|
|
14
14
|
# Minimap2 mapper for long read sequences
|
15
15
|
# https://github.com/lh3/minimap2
|
@@ -22,15 +22,15 @@ module Minimap2
|
|
22
22
|
attr_accessor :ffi_lib
|
23
23
|
end
|
24
24
|
|
25
|
-
lib_name = ::FFI.map_library_name(
|
26
|
-
self.ffi_lib = if ENV[
|
27
|
-
File.expand_path(lib_name, ENV[
|
25
|
+
lib_name = ::FFI.map_library_name('minimap2')
|
26
|
+
self.ffi_lib = if ENV['MINIMAPDIR']
|
27
|
+
File.expand_path(lib_name, ENV['MINIMAPDIR'])
|
28
28
|
else
|
29
29
|
File.expand_path("../vendor/#{lib_name}", __dir__)
|
30
30
|
end
|
31
31
|
|
32
32
|
# friendlier error message
|
33
|
-
autoload :FFI,
|
33
|
+
autoload :FFI, 'minimap2/ffi'
|
34
34
|
|
35
35
|
# methods from mappy
|
36
36
|
class << self
|
data/lib/minimap2/aligner.rb
CHANGED
@@ -2,10 +2,34 @@
|
|
2
2
|
|
3
3
|
module Minimap2
|
4
4
|
class Aligner
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :idx_opt, :map_opt, :index
|
6
|
+
|
7
|
+
# Create a new aligner
|
8
|
+
#
|
9
|
+
# @param fn_idx_in [String] index or sequence file name.
|
10
|
+
# @param seq [String] a single sequence to index.
|
11
|
+
# @param preset [String] minimap2 preset.
|
12
|
+
# @param k [Integer] k-mer length, no larger than 28.
|
13
|
+
# @param w [Integer] minimizer window size, no larger than 255.
|
14
|
+
# @param min_cnt [Integer] mininum number of minimizers on a chain.
|
15
|
+
# @param min_chain_score [Integer] minimum chaing score.
|
16
|
+
# @param min_dp_score
|
17
|
+
# @param bw [Integer] chaining and alignment band width.
|
18
|
+
# @param best_n [Integer] max number of alignments to return.
|
19
|
+
# @param n_threads [Integer] number of indexing threads.
|
20
|
+
# @param fn_idx_out [String] name of file to which the index is written.
|
21
|
+
# This parameter has no effect if seq is set.
|
22
|
+
# @param max_frag_len [Integer]
|
23
|
+
# @param extra_flags [Integer] additional flags defined in minimap.h.
|
24
|
+
# @param scoring [Array] scoring system.
|
25
|
+
# It is a tuple/list consisting of 4, 6 or 7 positive integers.
|
26
|
+
# The first 4 elements specify match scoring, mismatch penalty, gap open and gap extension penalty.
|
27
|
+
# The 5th and 6th elements, if present, set long-gap open and long-gap extension penalty.
|
28
|
+
# The 7th sets a mismatch penalty involving ambiguous bases.
|
6
29
|
|
7
30
|
def initialize(
|
8
|
-
fn_idx_in
|
31
|
+
fn_idx_in = nil,
|
32
|
+
seq: nil,
|
9
33
|
preset: nil,
|
10
34
|
k: nil,
|
11
35
|
w: nil,
|
@@ -18,76 +42,81 @@ module Minimap2
|
|
18
42
|
fn_idx_out: nil,
|
19
43
|
max_frag_len: nil,
|
20
44
|
extra_flags: nil,
|
21
|
-
seq: nil,
|
22
45
|
scoring: nil
|
23
46
|
)
|
24
47
|
|
25
|
-
@
|
26
|
-
@
|
48
|
+
@idx_opt = FFI::IdxOpt.new
|
49
|
+
@map_opt = FFI::MapOpt.new
|
27
50
|
|
28
|
-
|
29
|
-
|
30
|
-
else
|
31
|
-
# set the default options
|
32
|
-
FFI.mm_set_opt(0, index_options, map_options)
|
33
|
-
end
|
51
|
+
r = FFI.mm_set_opt(preset, idx_opt, map_opt)
|
52
|
+
raise ArgumentError, "Unknown preset name: #{preset}" if r == -1
|
34
53
|
|
35
54
|
# always perform alignment
|
36
|
-
|
37
|
-
|
55
|
+
map_opt[:flag] |= 4
|
56
|
+
idx_opt[:batch_size] = 0x7fffffffffffffff
|
38
57
|
|
39
58
|
# override preset options
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
59
|
+
idx_opt[:k] = k if k
|
60
|
+
idx_opt[:w] = w if w
|
61
|
+
map_opt[:min_cnt] = min_cnt if min_cnt
|
62
|
+
map_opt[:min_chain_score] = min_chain_score if min_chain_score
|
63
|
+
map_opt[:min_dp_max] = min_dp_score if min_dp_score
|
64
|
+
map_opt[:bw] = bw if bw
|
65
|
+
map_opt[:best_n] = best_n if best_n
|
66
|
+
map_opt[:max_frag_len] = max_frag_len if max_frag_len
|
67
|
+
map_opt[:flag] |= extra_flags if extra_flags
|
49
68
|
if scoring && scoring.size >= 4
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
69
|
+
map_opt[:a] = scoring[0]
|
70
|
+
map_opt[:b] = scoring[1]
|
71
|
+
map_opt[:q] = scoring[2]
|
72
|
+
map_opt[:e] = scoring[3]
|
73
|
+
map_opt[:q2] = map_opt.q
|
74
|
+
map_opt[:e2] = map_opt.e
|
56
75
|
if scoring.size >= 6
|
57
|
-
|
58
|
-
|
59
|
-
|
76
|
+
map_opt[:q2] = scoring[4]
|
77
|
+
map_opt[:e2] = scoring[5]
|
78
|
+
map_opt[:sc_ambi] = scoring[6] if scoring.size >= 7
|
60
79
|
end
|
61
80
|
end
|
62
81
|
|
63
|
-
if
|
64
|
-
|
65
|
-
|
66
|
-
index_options.bucket_bits, seq, seq.size
|
67
|
-
)
|
68
|
-
FFI.mm_mapopt_update(map_options, index)
|
69
|
-
map_options.mid_occ = 1000 # don't filter high-occ seeds
|
70
|
-
else
|
71
|
-
reader = FFI.mm_idx_reader_open(fn_idx_in, index_options, fn_idx_out)
|
82
|
+
if fn_idx_in
|
83
|
+
warn "Since fn_idx_in is specified, the seq argument will be ignored." if seq
|
84
|
+
reader = FFI.mm_idx_reader_open(fn_idx_in, idx_opt, fn_idx_out)
|
72
85
|
|
73
86
|
# The Ruby version raises an error here
|
74
87
|
raise "Cannot open : #{fn_idx_in}" if reader.null?
|
75
88
|
|
76
89
|
@index = FFI.mm_idx_reader_read(reader, n_threads)
|
77
90
|
FFI.mm_idx_reader_close(reader)
|
78
|
-
FFI.mm_mapopt_update(
|
91
|
+
FFI.mm_mapopt_update(map_opt, index)
|
79
92
|
FFI.mm_idx_index_name(index)
|
93
|
+
elsif seq
|
94
|
+
@index = FFI.mappy_idx_seq(
|
95
|
+
idx_opt[:w], idx_opt[:k], idx_opt[:flag] & 1,
|
96
|
+
idx_opt[:bucket_bits], seq, seq.size
|
97
|
+
)
|
98
|
+
FFI.mm_mapopt_update(map_opt, index)
|
99
|
+
map_opt[:mid_occ] = 1000 # don't filter high-occ seeds
|
80
100
|
end
|
81
101
|
end
|
82
102
|
|
83
|
-
#
|
84
|
-
def
|
103
|
+
# Explicitly releases the memory of the index object.
|
104
|
+
def free_index
|
85
105
|
FFI.mm_idx_destroy(index) unless index.null?
|
86
106
|
end
|
87
107
|
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
108
|
+
# @param seq [String]
|
109
|
+
# @param seq2 [String]
|
110
|
+
# @param buf [FFI::TBuf]
|
111
|
+
# @param cs [true, false]
|
112
|
+
# @param md [true, false]
|
113
|
+
# @param max_frag_len [Integer]
|
114
|
+
# @param extra_flags [Integer]
|
115
|
+
# @note Name change: map -> align
|
116
|
+
# In the Ruby language, the name map means iterator.
|
117
|
+
# The original name is map, but here I use the method name align.
|
118
|
+
# @note The use of Enumerator is being considered. The method names may change again.
|
119
|
+
|
91
120
|
def align(
|
92
121
|
seq, seq2 = nil,
|
93
122
|
buf: nil,
|
@@ -99,14 +128,14 @@ module Minimap2
|
|
99
128
|
|
100
129
|
return if index.null?
|
101
130
|
|
102
|
-
|
103
|
-
|
131
|
+
map_opt.max_frag_len = max_frag_len if max_frag_len
|
132
|
+
map_opt.flag |= extra_flags if extra_flags
|
104
133
|
|
105
134
|
buf ||= FFI::TBuf.new
|
106
135
|
km = FFI.mm_tbuf_get_km(buf)
|
107
136
|
n_regs_ptr = ::FFI::MemoryPointer.new :int
|
108
137
|
|
109
|
-
ptr = FFI.mm_map_aux(index, seq, seq2, n_regs_ptr, buf,
|
138
|
+
ptr = FFI.mm_map_aux(index, seq, seq2, n_regs_ptr, buf, map_opt)
|
110
139
|
n_regs = n_regs_ptr.read_int
|
111
140
|
|
112
141
|
regs = Array.new(n_regs) { |i| FFI::Reg1.new(ptr + i * FFI::Reg1.size) }
|
@@ -124,13 +153,13 @@ module Minimap2
|
|
124
153
|
# convert the 32-bit CIGAR encoding to Ruby array
|
125
154
|
cigar = c.map { |x| [x >> 4, x & 0xf] }
|
126
155
|
|
127
|
-
_cs =
|
156
|
+
_cs = ''
|
128
157
|
if cs
|
129
158
|
l_cs_str = FFI.mm_gen_cs(km, cs_str, m_cs_str, @index, regs[i], seq, 1)
|
130
159
|
_cs = cs_str.read_pointer.read_string(l_cs_str)
|
131
160
|
end
|
132
161
|
|
133
|
-
_md =
|
162
|
+
_md = ''
|
134
163
|
if md
|
135
164
|
l_cs_str = FFI.mm_gen_md(km, cs_str, m_cs_str, @index, regs[i], seq)
|
136
165
|
_md = cs_str.read_pointer.read_string(l_cs_str)
|
@@ -149,6 +178,11 @@ module Minimap2
|
|
149
178
|
end
|
150
179
|
end
|
151
180
|
|
181
|
+
# retrieve a subsequence from the index.
|
182
|
+
# @params name
|
183
|
+
# @params start
|
184
|
+
# @params stop
|
185
|
+
|
152
186
|
def seq(name, start = 0, stop = 0x7fffffff)
|
153
187
|
lp = ::FFI::MemoryPointer.new(:int)
|
154
188
|
s = FFI.mappy_fetch_seq(index, name, start, stop, lp)
|
@@ -158,10 +192,12 @@ module Minimap2
|
|
158
192
|
s.read_string(l)
|
159
193
|
end
|
160
194
|
|
195
|
+
# k-mer length, no larger than 28
|
161
196
|
def k
|
162
197
|
index[:k]
|
163
198
|
end
|
164
199
|
|
200
|
+
# minimizer window size, no larger than 255
|
165
201
|
def w
|
166
202
|
index[:w]
|
167
203
|
end
|
data/lib/minimap2/alignment.rb
CHANGED
@@ -1,13 +1,57 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Minimap2
|
4
|
+
# Alignment result
|
5
|
+
#
|
6
|
+
# @!attribute ctg
|
7
|
+
# @return [String] name of the reference sequence the query is mapped to.
|
8
|
+
# @!attribute ctg_len
|
9
|
+
# @return [Integer] total length of the reference sequence.
|
10
|
+
# @!attribute r_st
|
11
|
+
# @return [Integer] start positions on the reference.
|
12
|
+
# @!attribute r_en
|
13
|
+
# @return [Integer] end positions on the reference.
|
14
|
+
# @!attribute strand
|
15
|
+
# @return [Integer] +1 if on the forward strand; -1 if on the reverse strand.
|
16
|
+
# @!attribute trans_strand
|
17
|
+
# @return [Integer] transcript strand.
|
18
|
+
# +1 if on the forward strand; -1 if on the reverse strand; 0 if unknown.
|
19
|
+
# @!attribute blen
|
20
|
+
# @return [Integer] length of the alignment, including both alignment matches and gaps
|
21
|
+
# but excluding ambiguous bases.
|
22
|
+
# @!attribute mlen
|
23
|
+
# @return [Integer] length of the matching bases in the alignment,
|
24
|
+
# excluding ambiguous base matches.
|
25
|
+
# @!attribute nm
|
26
|
+
# @return [Integer] number of mismatches, gaps and ambiguous poistions in the alignment.
|
27
|
+
# @!attribute primary
|
28
|
+
# @return [Integer] if the alignment is primary (typically the best and the first to generate)
|
29
|
+
# @!attribute q_st
|
30
|
+
# @return [Integer] start positions on the query.
|
31
|
+
# @!attribute q_en
|
32
|
+
# @return [Integer] end positions on the query.
|
33
|
+
# @!attribute mapq
|
34
|
+
# @return [Integer] mapping quality.
|
35
|
+
# @!attribute cigar
|
36
|
+
# @return [Array] CIGAR returned as an array of shape (n_cigar,2).
|
37
|
+
# The two numbers give the length and the operator of each CIGAR operation.
|
38
|
+
# @!attribute read_num
|
39
|
+
# @return [Integer] read number that the alignment corresponds to;
|
40
|
+
# 1 for the first read and 2 for the second read.
|
41
|
+
# @!attribute cs
|
42
|
+
# @return [String] the cs tag.
|
43
|
+
# @!attribute md
|
44
|
+
# @return [String] the MD tag as in the SAM format.
|
45
|
+
# It is an empty string unless the md argument is applied when calling Aligner#align.
|
46
|
+
# @!attribute cigar_str
|
47
|
+
# @return [String] CIGAR string.
|
48
|
+
|
4
49
|
class Alignment
|
5
50
|
def self.keys
|
6
51
|
%i[ctg ctg_len r_st r_en strand trans_strand blen mlen nm primary
|
7
52
|
q_st q_en mapq cigar read_num cs md cigar_str]
|
8
53
|
end
|
9
54
|
|
10
|
-
# Read only
|
11
55
|
attr_reader(*keys)
|
12
56
|
|
13
57
|
def initialize(h, cigar, cs = nil, md = nil)
|
@@ -29,7 +73,7 @@ module Minimap2
|
|
29
73
|
@cs = cs
|
30
74
|
@md = md
|
31
75
|
|
32
|
-
@cigar_str = cigar.map { |x| x[0].to_s +
|
76
|
+
@cigar_str = cigar.map { |x| x[0].to_s + 'MIDNSH'[x[1]] }.join
|
33
77
|
end
|
34
78
|
|
35
79
|
def primary?
|
@@ -42,19 +86,19 @@ module Minimap2
|
|
42
86
|
|
43
87
|
def to_s
|
44
88
|
strand = if @strand.positive?
|
45
|
-
|
89
|
+
'+'
|
46
90
|
elsif @strand.negative?
|
47
|
-
|
91
|
+
'-'
|
48
92
|
else
|
49
|
-
|
93
|
+
'?'
|
50
94
|
end
|
51
|
-
tp = @primary != 0 ?
|
95
|
+
tp = @primary != 0 ? 'tp:A:P' : 'tp:A:S'
|
52
96
|
ts = if @trans_strand.positive?
|
53
|
-
|
97
|
+
'ts:A:+'
|
54
98
|
elsif @trans_strand.negative?
|
55
|
-
|
99
|
+
'ts:A:-'
|
56
100
|
else
|
57
|
-
|
101
|
+
'ts:A:.'
|
58
102
|
end
|
59
103
|
a = [@q_st, @q_en, strand, @ctg, @ctg_len, @r_st, @r_en,
|
60
104
|
@mlen, @blen, @mapq, tp, ts, "cg:Z:#{@cigar_str}"]
|
data/lib/minimap2/ffi.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# bit fields
|
4
|
-
require_relative
|
4
|
+
require_relative 'ffi_helper'
|
5
5
|
|
6
6
|
module Minimap2
|
7
7
|
# Native APIs
|
@@ -22,6 +22,6 @@ module Minimap2
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
require_relative
|
26
|
-
require_relative
|
27
|
-
require_relative
|
25
|
+
require_relative 'ffi/constants'
|
26
|
+
require_relative 'ffi/functions'
|
27
|
+
require_relative 'ffi/mappy'
|
@@ -6,15 +6,15 @@ module Minimap2
|
|
6
6
|
:mm_set_opt_raw, :mm_set_opt,
|
7
7
|
[:pointer, IdxOpt.by_ref, MapOpt.by_ref],
|
8
8
|
:int
|
9
|
-
|
9
|
+
|
10
10
|
private_class_method :mm_set_opt_raw
|
11
|
-
|
11
|
+
|
12
12
|
def self.mm_set_opt(preset, io, mo)
|
13
|
-
if preset
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
ptr = if preset
|
14
|
+
::FFI::MemoryPointer.from_string(preset.to_s)
|
15
|
+
else
|
16
|
+
::FFI::Pointer.new(:int, 0)
|
17
|
+
end
|
18
18
|
mm_set_opt_raw(ptr, io, mo)
|
19
19
|
end
|
20
20
|
|
data/lib/minimap2/ffi/mappy.rb
CHANGED
@@ -38,7 +38,7 @@ module Minimap2
|
|
38
38
|
:seq, KString,
|
39
39
|
:qual, KString,
|
40
40
|
:last_char, :int,
|
41
|
-
:f, :pointer #
|
41
|
+
:f, :pointer # KStream
|
42
42
|
end
|
43
43
|
|
44
44
|
attach_function \
|
@@ -88,7 +88,7 @@ module Minimap2
|
|
88
88
|
|
89
89
|
attach_function \
|
90
90
|
:mappy_idx_seq,
|
91
|
-
%i[int int int int
|
91
|
+
%i[int int int int string int],
|
92
92
|
Idx.by_ref
|
93
93
|
|
94
94
|
attach_function \
|
data/lib/minimap2/ffi_helper.rb
CHANGED
data/lib/minimap2/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.2
|
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-
|
11
|
+
date: 2021-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -112,7 +112,6 @@ files:
|
|
112
112
|
- lib/minimap2/ffi/mappy.rb
|
113
113
|
- lib/minimap2/ffi_helper.rb
|
114
114
|
- lib/minimap2/version.rb
|
115
|
-
- vendor/libminimap2.so
|
116
115
|
homepage: https://github.com/kojix2/ruby-minimap2
|
117
116
|
licenses:
|
118
117
|
- MIT
|
data/vendor/libminimap2.so
DELETED
Binary file
|