minimap2 0.0.3 → 0.2.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +101 -61
- data/lib/minimap2/aligner.rb +16 -5
- data/lib/minimap2/alignment.rb +6 -2
- data/lib/minimap2/ffi/constants.rb +79 -57
- data/lib/minimap2/ffi.rb +1 -2
- data/lib/minimap2/version.rb +2 -1
- data/lib/minimap2.rb +35 -22
- data/vendor/libminimap2.so +0 -0
- metadata +7 -63
- data/lib/minimap2/ffi_helper.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b22ce0b5ca5e9cb117ba31802303053571c40d0893065298f8585f00dfdcb653
|
4
|
+
data.tar.gz: b76275c1b624ddbd12dc4bd1185f77ef16656fb113df4d668b1b651cd67ed1d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7a8ec0bbf34a82bf827293038a46210665a7c903e15fe3b2dbcfe71e88125ae82cca9b6649efefa1208e109538961c2a124517dc258ae2de8de8ff7aba10030
|
7
|
+
data.tar.gz: 9807c04d8cabd3b548a780c12266d6b0f4e3cfd4aae539e4d289541d64bff1e07ffebd9765fb6d0e33fb317030eb8142c950e21658b72be752b08aa90982be08
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# ruby-minimap2
|
2
2
|
|
3
3
|
[![Gem Version](https://img.shields.io/gem/v/minimap2?color=brightgreen)](https://rubygems.org/gems/minimap2)
|
4
4
|
[![CI](https://github.com/kojix2/ruby-minimap2/workflows/CI/badge.svg)](https://github.com/kojix2/ruby-minimap2/actions)
|
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
## Installation
|
14
14
|
|
15
|
-
|
15
|
+
Open your terminal and type the following commands in order. You need to build minimap2 on your own because you need to create a shared library that contains cmappy functions.
|
16
16
|
|
17
17
|
Build
|
18
18
|
|
@@ -29,98 +29,127 @@ Install
|
|
29
29
|
bundle exec rake install
|
30
30
|
```
|
31
31
|
|
32
|
-
Ruby-minimap2 is tested on Ubuntu and macOS.
|
32
|
+
Ruby-minimap2 is [tested on Ubuntu and macOS](https://github.com/kojix2/ruby-minimap2/actions).
|
33
33
|
|
34
34
|
## Quick Start
|
35
35
|
|
36
36
|
```ruby
|
37
37
|
require "minimap2"
|
38
|
+
```
|
39
|
+
|
40
|
+
Create aligner
|
38
41
|
|
39
|
-
|
42
|
+
```ruby
|
40
43
|
aligner = Minimap2::Aligner.new("minimap2/test/MT-human.fa")
|
44
|
+
```
|
45
|
+
|
46
|
+
Retrieve a subsequence from the index
|
41
47
|
|
42
|
-
|
48
|
+
```ruby
|
43
49
|
seq = aligner.seq("MT_human", 100, 200)
|
50
|
+
```
|
51
|
+
|
52
|
+
Mapping
|
44
53
|
|
45
|
-
|
54
|
+
```ruby
|
46
55
|
hits = aligner.align(seq)
|
47
|
-
pp hits[0]
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
56
|
+
pp hits[0]
|
57
|
+
```
|
58
|
+
|
59
|
+
```
|
60
|
+
=>
|
61
|
+
#<Minimap2::Alignment:0x000055fe18223f50
|
62
|
+
@blen=100,
|
63
|
+
@cigar=[[100, 0]],
|
64
|
+
@cigar_str="100M",
|
65
|
+
@cs="",
|
66
|
+
@ctg="MT_human",
|
67
|
+
@ctg_len=16569,
|
68
|
+
@mapq=60,
|
69
|
+
@md="",
|
70
|
+
@mlen=100,
|
71
|
+
@nm=0,
|
72
|
+
@primary=1,
|
73
|
+
@q_en=100,
|
74
|
+
@q_st=0,
|
75
|
+
@r_en=200,
|
76
|
+
@r_st=100,
|
77
|
+
@read_num=1,
|
78
|
+
@strand=1,
|
79
|
+
@trans_strand=0>
|
66
80
|
```
|
67
81
|
|
68
82
|
## APIs Overview
|
69
83
|
|
70
|
-
|
84
|
+
API is based on [Mappy](https://github.com/lh3/minimap2/tree/master/python), the official Python binding for Minimap2.
|
85
|
+
|
86
|
+
Note: `Aligner#map` has been changed to `align`, because `map` means iterator in Ruby.
|
71
87
|
|
72
88
|
```markdown
|
73
89
|
* Minimap2 module
|
74
|
-
- fastx_read
|
75
|
-
- revcomp
|
90
|
+
- fastx_read Read fasta/fastq file.
|
91
|
+
- revcomp Reverse complement sequence.
|
76
92
|
|
77
93
|
* Aligner class
|
78
94
|
* attributes
|
79
|
-
- index
|
80
|
-
- idx_opt
|
81
|
-
- map_opt
|
95
|
+
- index Returns the value of attribute index.
|
96
|
+
- idx_opt Returns the value of attribute idx_opt.
|
97
|
+
- map_opt Returns the value of attribute map_opt.
|
82
98
|
* methods
|
83
|
-
- new(path, preset: nil)
|
84
|
-
- align
|
99
|
+
- new(path, preset: nil) Create a new aligner. (presets: sr, map-pb, map-out, map-hifi, splice, asm5, etc.)
|
100
|
+
- align Maps and returns alignments.
|
101
|
+
- seq Retrieve a subsequence from the index.
|
85
102
|
|
86
103
|
* Alignment class
|
87
104
|
* attributes
|
88
|
-
- ctg
|
89
|
-
- ctg_len
|
90
|
-
- r_st
|
91
|
-
- r_en
|
92
|
-
- strand
|
93
|
-
- trans_strand
|
94
|
-
- blen
|
95
|
-
- mlen
|
96
|
-
- nm
|
97
|
-
- primary
|
98
|
-
- q_st
|
99
|
-
- q_en
|
100
|
-
- mapq
|
101
|
-
- cigar
|
102
|
-
- read_num
|
103
|
-
- cs
|
104
|
-
- md
|
105
|
-
- cigar_str
|
105
|
+
- ctg Returns name of the reference sequence the query is mapped to.
|
106
|
+
- ctg_len Returns total length of the reference sequence.
|
107
|
+
- r_st Returns start positions on the reference.
|
108
|
+
- r_en Returns end positions on the reference.
|
109
|
+
- strand Returns +1 if on the forward strand; -1 if on the reverse strand.
|
110
|
+
- trans_strand Returns transcript strand. +1 if on the forward strand; -1 if on the reverse strand; 0 if unknown.
|
111
|
+
- blen Returns length of the alignment, including both alignment matches and gaps but excluding ambiguous bases.
|
112
|
+
- mlen Returns length of the matching bases in the alignment, excluding ambiguous base matches.
|
113
|
+
- nm Returns number of mismatches, gaps and ambiguous poistions in the alignment.
|
114
|
+
- primary Returns if the alignment is primary (typically the best and the first to generate).
|
115
|
+
- q_st Returns start positions on the query.
|
116
|
+
- q_en Returns end positions on the query.
|
117
|
+
- mapq Returns mapping quality.
|
118
|
+
- cigar Returns CIGAR returned as an array of shape (n_cigar,2). The two numbers give the length and the operator of each CIGAR operation.
|
119
|
+
- read_num Returns read number that the alignment corresponds to; 1 for the first read and 2 for the second read.
|
120
|
+
- cs Returns the cs tag.
|
121
|
+
- md Returns the MD tag as in the SAM format. It is an empty string unless the md argument is applied when calling Aligner#align.
|
122
|
+
- cigar_str Returns CIGAR string.
|
106
123
|
* methods
|
107
|
-
- to_h
|
108
|
-
- to_s
|
124
|
+
- to_h Convert Alignment to hash.
|
125
|
+
- to_s Convert to the PAF format without the QueryName and QueryLength columns.
|
109
126
|
|
110
|
-
|
111
|
-
* IdxOpt class
|
112
|
-
* MapOpt class
|
127
|
+
## FFI module
|
128
|
+
* IdxOpt class Indexing options.
|
129
|
+
* MapOpt class Mapping options.
|
113
130
|
```
|
114
131
|
|
115
|
-
|
132
|
+
This is not all. See the [RubyDoc.info documentation](https://rubydoc.info/gems/minimap2/) for more details.
|
116
133
|
|
117
|
-
|
134
|
+
ruby-minimap2 is built on top of [Ruby-FFI](https://github.com/ffi/ffi).
|
135
|
+
Native functions can be called from the FFI module. FFI also provides the way to access some C structs.
|
118
136
|
|
119
|
-
ruby
|
137
|
+
```ruby
|
138
|
+
aligner.idx_opt.members
|
139
|
+
# => [:k, :w, :flag, :bucket_bits, :mini_batch_size, :batch_size]
|
140
|
+
aligner.kds_opt.values
|
141
|
+
# => [15, 10, 0, 14, 50000000, 9223372036854775807]
|
142
|
+
aligner.idx_opt[:k]
|
143
|
+
# => 15
|
144
|
+
aligner.idx_opt[:k] = 14
|
145
|
+
aligner.idx_opt[:k]
|
146
|
+
# => 14
|
147
|
+
```
|
120
148
|
|
121
149
|
## Development
|
122
150
|
|
123
|
-
Fork your repository
|
151
|
+
Fork your repository.
|
152
|
+
then clone.
|
124
153
|
|
125
154
|
```sh
|
126
155
|
git clone --recursive https://github.com/kojix2/ruby-minimap2
|
@@ -129,7 +158,7 @@ git clone --recursive https://github.com/kojix2/ruby-minimap2
|
|
129
158
|
# git submodule update -i
|
130
159
|
```
|
131
160
|
|
132
|
-
Build.
|
161
|
+
Build Minimap2 and Mappy.
|
133
162
|
|
134
163
|
```sh
|
135
164
|
cd ruby-minimap2
|
@@ -137,6 +166,13 @@ bundle install # Install dependent packages including Ruby-FFI
|
|
137
166
|
bundle exec rake minimap2:build
|
138
167
|
```
|
139
168
|
|
169
|
+
A shared library will be created in the vendor directory.
|
170
|
+
|
171
|
+
```
|
172
|
+
└── vendor
|
173
|
+
└── libminimap2.so
|
174
|
+
```
|
175
|
+
|
140
176
|
Run tests.
|
141
177
|
|
142
178
|
```
|
@@ -157,3 +193,7 @@ ruby-minimap2 is a library under development and there are many points to be imp
|
|
157
193
|
## License
|
158
194
|
|
159
195
|
[MIT License](https://opensource.org/licenses/MIT).
|
196
|
+
|
197
|
+
## Acknowledgements
|
198
|
+
|
199
|
+
I would like to thank Heng Li for making Minimap2, and all the readers who read the README to the end.
|
data/lib/minimap2/aligner.rb
CHANGED
@@ -4,11 +4,21 @@ module Minimap2
|
|
4
4
|
class Aligner
|
5
5
|
attr_reader :idx_opt, :map_opt, :index
|
6
6
|
|
7
|
-
# Create a new aligner
|
7
|
+
# Create a new aligner.
|
8
8
|
#
|
9
9
|
# @param fn_idx_in [String] index or sequence file name.
|
10
10
|
# @param seq [String] a single sequence to index.
|
11
11
|
# @param preset [String] minimap2 preset.
|
12
|
+
# * map-pb : PacBio CLR genomic reads
|
13
|
+
# * map-ont : Oxford Nanopore genomic reads
|
14
|
+
# * map-hifi : PacBio HiFi/CCS genomic reads (v2.19 or later)
|
15
|
+
# * asm20 : PacBio HiFi/CCS genomic reads (v2.18 or earlier)
|
16
|
+
# * sr : short genomic paired-end reads
|
17
|
+
# * splice : spliced long reads (strand unknown)
|
18
|
+
# * splice:hq : Final PacBio Iso-seq or traditional cDNA
|
19
|
+
# * asm5 : intra-species asm-to-asm alignment
|
20
|
+
# * ava-pb : PacBio read overlap
|
21
|
+
# * ava-ont : Nanopore read overlap
|
12
22
|
# @param k [Integer] k-mer length, no larger than 28.
|
13
23
|
# @param w [Integer] minimizer window size, no larger than 255.
|
14
24
|
# @param min_cnt [Integer] mininum number of minimizers on a chain.
|
@@ -101,6 +111,7 @@ module Minimap2
|
|
101
111
|
end
|
102
112
|
|
103
113
|
# Explicitly releases the memory of the index object.
|
114
|
+
|
104
115
|
def free_index
|
105
116
|
FFI.mm_idx_destroy(index) unless index.null?
|
106
117
|
end
|
@@ -184,10 +195,10 @@ module Minimap2
|
|
184
195
|
alignments
|
185
196
|
end
|
186
197
|
|
187
|
-
#
|
188
|
-
# @
|
189
|
-
# @
|
190
|
-
# @
|
198
|
+
# Retrieve a subsequence from the index.
|
199
|
+
# @param name
|
200
|
+
# @param start
|
201
|
+
# @param stop
|
191
202
|
|
192
203
|
def seq(name, start = 0, stop = 0x7fffffff)
|
193
204
|
lp = ::FFI::MemoryPointer.new(:int)
|
data/lib/minimap2/alignment.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Minimap2
|
4
|
-
# Alignment result
|
4
|
+
# Alignment result.
|
5
5
|
#
|
6
6
|
# @!attribute ctg
|
7
7
|
# @return [String] name of the reference sequence the query is mapped to.
|
@@ -73,17 +73,21 @@ module Minimap2
|
|
73
73
|
@cs = cs
|
74
74
|
@md = md
|
75
75
|
|
76
|
-
@cigar_str = cigar.map { |x| x[0].to_s +
|
76
|
+
@cigar_str = cigar.map { |x| x[0].to_s + FFI::CIGAR_STR[x[1]] }.join
|
77
77
|
end
|
78
78
|
|
79
79
|
def primary?
|
80
80
|
@primary == 1
|
81
81
|
end
|
82
82
|
|
83
|
+
# Convert Alignment to hash.
|
84
|
+
|
83
85
|
def to_h
|
84
86
|
self.class.keys.map { |k| [k, __send__(k)] }.to_h
|
85
87
|
end
|
86
88
|
|
89
|
+
# Convert to the PAF format without the QueryName and QueryLength columns.
|
90
|
+
|
87
91
|
def to_s
|
88
92
|
strand = if @strand.positive?
|
89
93
|
'+'
|
@@ -3,45 +3,60 @@
|
|
3
3
|
module Minimap2
|
4
4
|
module FFI
|
5
5
|
# flags
|
6
|
-
NO_DIAG
|
7
|
-
NO_DUAL
|
8
|
-
CIGAR
|
9
|
-
OUT_SAM
|
10
|
-
NO_QUAL
|
11
|
-
OUT_CG
|
12
|
-
OUT_CS
|
13
|
-
SPLICE
|
14
|
-
SPLICE_FOR
|
15
|
-
SPLICE_REV
|
16
|
-
NO_LJOIN
|
17
|
-
OUT_CS_LONG
|
18
|
-
SR
|
19
|
-
FRAG_MODE
|
20
|
-
NO_PRINT_2ND
|
21
|
-
TWO_IO_THREADS
|
22
|
-
LONG_CIGAR
|
23
|
-
INDEPEND_SEG
|
24
|
-
SPLICE_FLANK
|
25
|
-
SOFTCLIP
|
26
|
-
FOR_ONLY
|
27
|
-
REV_ONLY
|
28
|
-
HEAP_SORT
|
29
|
-
ALL_CHAINS
|
30
|
-
OUT_MD
|
31
|
-
COPY_COMMENT
|
32
|
-
EQX
|
33
|
-
PAF_NO_HIT
|
34
|
-
NO_END_FLT
|
35
|
-
HARD_MLEVEL
|
36
|
-
SAM_HIT_ONLY
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
6
|
+
NO_DIAG = 0x001 # no exact diagonal hit
|
7
|
+
NO_DUAL = 0x002 # skip pairs where query name is lexicographically larger than target name
|
8
|
+
CIGAR = 0x004
|
9
|
+
OUT_SAM = 0x008
|
10
|
+
NO_QUAL = 0x010
|
11
|
+
OUT_CG = 0x020
|
12
|
+
OUT_CS = 0x040
|
13
|
+
SPLICE = 0x080 # splice mode
|
14
|
+
SPLICE_FOR = 0x100 # match GT-AG
|
15
|
+
SPLICE_REV = 0x200 # match CT-AC, the reverse complement of GT-AG
|
16
|
+
NO_LJOIN = 0x400
|
17
|
+
OUT_CS_LONG = 0x800
|
18
|
+
SR = 0x1000
|
19
|
+
FRAG_MODE = 0x2000
|
20
|
+
NO_PRINT_2ND = 0x4000
|
21
|
+
TWO_IO_THREADS = 0x8000 # Translator's Note. MM_F_2_IO_THREADS. Constants starting with numbers cannot be defined.
|
22
|
+
LONG_CIGAR = 0x10000
|
23
|
+
INDEPEND_SEG = 0x20000
|
24
|
+
SPLICE_FLANK = 0x40000
|
25
|
+
SOFTCLIP = 0x80000
|
26
|
+
FOR_ONLY = 0x100000
|
27
|
+
REV_ONLY = 0x200000
|
28
|
+
HEAP_SORT = 0x400000
|
29
|
+
ALL_CHAINS = 0x800000
|
30
|
+
OUT_MD = 0x1000000
|
31
|
+
COPY_COMMENT = 0x2000000
|
32
|
+
EQX = 0x4000000 # use =/X instead of M
|
33
|
+
PAF_NO_HIT = 0x8000000 # output unmapped reads to PAF
|
34
|
+
NO_END_FLT = 0x10000000
|
35
|
+
HARD_MLEVEL = 0x20000000
|
36
|
+
SAM_HIT_ONLY = 0x40000000
|
37
|
+
RMQ = 0x80000000 # LL
|
38
|
+
QSTRAND = 0x100000000 # LL
|
39
|
+
NO_INV = 0x200000000
|
40
|
+
|
41
|
+
HPC = 0x1
|
42
|
+
NO_SEQ = 0x2
|
43
|
+
NO_NAME = 0x4
|
44
|
+
|
45
|
+
IDX_MAGIC = "MMI\2"
|
46
|
+
|
47
|
+
MAX_SEG = 255
|
48
|
+
|
49
|
+
CIGAR_MATCH = 0
|
50
|
+
CIGAR_INS = 1
|
51
|
+
CIGAR_DEL = 2
|
52
|
+
CIGAR_N_SKIP = 3
|
53
|
+
CIGAR_SOFTCLIP = 4
|
54
|
+
CIGAR_HARDCLIP = 5
|
55
|
+
CIGAR_PADDING = 6
|
56
|
+
CIGAR_EQ_MATCH = 7
|
57
|
+
CIGAR_X_MISMATCH = 8
|
58
|
+
|
59
|
+
CIGAR_STR = 'MIDNSHP=XB'
|
45
60
|
|
46
61
|
# emulate 128-bit integers
|
47
62
|
class MM128 < ::FFI::Struct
|
@@ -77,6 +92,7 @@ module Minimap2
|
|
77
92
|
:sdust_thres, :int, # score threshold for SDUST; 0 to disable
|
78
93
|
:max_qlen, :int, # max query length
|
79
94
|
:bw, :int, # bandwidth
|
95
|
+
:bw_long, :int,
|
80
96
|
:max_gap, :int, # break a chain if there are no minimizers in a max_gap window
|
81
97
|
:max_gap_ref, :int,
|
82
98
|
:max_frag_len, :int,
|
@@ -85,14 +101,15 @@ module Minimap2
|
|
85
101
|
:min_cnt, :int, # min number of minimizers on each chain
|
86
102
|
:min_chain_score, :int, # min chaining score
|
87
103
|
:chain_gap_scale, :float,
|
104
|
+
:chain_skip_scale, :float,
|
105
|
+
:rmq_size_cap, :int,
|
106
|
+
:rmq_inner_dist, :int,
|
107
|
+
:rmq_rescue_size, :int,
|
108
|
+
:rmq_rescue_ratio, :float,
|
88
109
|
:mask_level, :float,
|
89
110
|
:mask_len, :int,
|
90
111
|
:pri_ratio, :float,
|
91
112
|
:best_n, :int, # top best_n chains are subjected to DP alignment
|
92
|
-
:max_join_long, :int,
|
93
|
-
:max_join_short, :int,
|
94
|
-
:min_join_flank_sc, :int,
|
95
|
-
:min_join_flank_ratio, :float,
|
96
113
|
:alt_drop, :float,
|
97
114
|
:a, :int, # matching score
|
98
115
|
:b, :int, # mismatch
|
@@ -111,14 +128,18 @@ module Minimap2
|
|
111
128
|
:anchor_ext_len, :int,
|
112
129
|
:anchor_ext_shift, :int,
|
113
130
|
:max_clip_ratio, :float, # drop an alignment if BOTH ends are clipped above this ratio
|
131
|
+
:rank_min_len, :int,
|
132
|
+
:rank_frac, :float,
|
114
133
|
:pe_ori, :int,
|
115
134
|
:pe_bonus, :int,
|
116
135
|
:mid_occ_frac, :float, # only used by mm_mapopt_update(); see below
|
136
|
+
:q_occ_frac, :float,
|
117
137
|
:min_mid_occ, :int32_t,
|
118
138
|
:mid_occ, :int32_t, # ignore seeds with occurrences above this threshold
|
119
139
|
:max_occ, :int32_t,
|
120
140
|
:mini_batch_size, :int64_t, # size of a batch of query bases to process in parallel
|
121
141
|
:max_sw_mat, :int64_t,
|
142
|
+
:cap_kalloc, :int64_t,
|
122
143
|
:split_prefix, :string
|
123
144
|
end
|
124
145
|
|
@@ -169,7 +190,7 @@ module Minimap2
|
|
169
190
|
:n_ambi_trans_strand, :uint32,
|
170
191
|
:n_cigar, :uint32
|
171
192
|
|
172
|
-
|
193
|
+
bit_field :n_ambi_trans_strand,
|
173
194
|
:n_ambi, 30, # number of ambiguous bases
|
174
195
|
:trans_strand, 2 # transcript strand: 0 for unknown, 1 for +, 2 for -
|
175
196
|
|
@@ -201,19 +222,20 @@ module Minimap2
|
|
201
222
|
:div, :float,
|
202
223
|
:p, Extra.ptr
|
203
224
|
|
204
|
-
|
205
|
-
:mapq,
|
206
|
-
:split,
|
207
|
-
:rev,
|
208
|
-
:inv,
|
209
|
-
:sam_pri,
|
210
|
-
:proper_frag,
|
211
|
-
:pe_thru,
|
212
|
-
:seg_split,
|
213
|
-
:seg_id,
|
214
|
-
:split_inv,
|
215
|
-
:is_alt,
|
216
|
-
:
|
225
|
+
bit_field :fields,
|
226
|
+
:mapq, 8,
|
227
|
+
:split, 2,
|
228
|
+
:rev, 1,
|
229
|
+
:inv, 1,
|
230
|
+
:sam_pri, 1,
|
231
|
+
:proper_frag, 1,
|
232
|
+
:pe_thru, 1,
|
233
|
+
:seg_split, 1,
|
234
|
+
:seg_id, 8,
|
235
|
+
:split_inv, 1,
|
236
|
+
:is_alt, 1,
|
237
|
+
:strand_retained, 1,
|
238
|
+
:dummy, 5
|
217
239
|
end
|
218
240
|
|
219
241
|
# memory buffer for thread-local storage during mapping
|
data/lib/minimap2/ffi.rb
CHANGED
data/lib/minimap2/version.rb
CHANGED
data/lib/minimap2.rb
CHANGED
@@ -3,9 +3,6 @@
|
|
3
3
|
# dependencies
|
4
4
|
require 'ffi'
|
5
5
|
|
6
|
-
# bit fields
|
7
|
-
require_relative 'minimap2/ffi_helper'
|
8
|
-
|
9
6
|
# modules
|
10
7
|
require_relative 'minimap2/aligner'
|
11
8
|
require_relative 'minimap2/alignment'
|
@@ -34,30 +31,34 @@ module Minimap2
|
|
34
31
|
|
35
32
|
# methods from mappy
|
36
33
|
class << self
|
37
|
-
#
|
34
|
+
# Set verbosity level.
|
35
|
+
# @param [Integer] level
|
36
|
+
|
37
|
+
def verbose(level = -1)
|
38
|
+
FFI.mm_verbose_level(level)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Read fasta/fastq file.
|
38
42
|
# @param [String] file_path
|
39
|
-
# @param [Boolean]
|
43
|
+
# @param [Boolean] comment If True, the comment will be read.
|
40
44
|
# @yield [name, seq, qual, comment]
|
41
|
-
#
|
45
|
+
# @return [Enumerator] enum Retrun Enumerator if not block given.
|
46
|
+
# Note: You can BioRuby instead of this method.
|
42
47
|
|
43
|
-
def fastx_read(file_path,
|
48
|
+
def fastx_read(file_path, comment: false, &block)
|
44
49
|
path = File.expand_path(file_path)
|
45
50
|
ks = FFI.mm_fastx_open(path)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
comment
|
52
|
-
yield [name, seq, qual, comment]
|
53
|
-
else
|
54
|
-
yield [name, seq, qual]
|
51
|
+
if block_given?
|
52
|
+
fastx_each(ks, comment, &block)
|
53
|
+
else
|
54
|
+
Enumerator.new do |y|
|
55
|
+
# rewind not work
|
56
|
+
fastx_each(ks, comment) { |r| y << r }
|
55
57
|
end
|
56
58
|
end
|
57
|
-
FFI.mm_fastx_close(ks)
|
58
59
|
end
|
59
60
|
|
60
|
-
#
|
61
|
+
# Reverse complement sequence.
|
61
62
|
# @param [String] seq
|
62
63
|
# @return [string] seq
|
63
64
|
|
@@ -68,11 +69,23 @@ module Minimap2
|
|
68
69
|
FFI.mappy_revcomp(l, bseq)
|
69
70
|
end
|
70
71
|
|
71
|
-
|
72
|
-
# @param [Integer] level
|
72
|
+
private
|
73
73
|
|
74
|
-
def
|
75
|
-
FFI.
|
74
|
+
def fastx_each(ks, comment)
|
75
|
+
yield fastx_next(ks, comment) while FFI.kseq_read(ks) >= 0
|
76
|
+
FFI.mm_fastx_close(ks)
|
77
|
+
end
|
78
|
+
|
79
|
+
def fastx_next(ks, read_comment)
|
80
|
+
qual = ks[:qual][:s] if (ks[:qual][:l]).positive?
|
81
|
+
name = ks[:name][:s]
|
82
|
+
seq = ks[:seq][:s]
|
83
|
+
if read_comment
|
84
|
+
comment = ks[:comment][:s] if (ks[:comment][:l]).positive?
|
85
|
+
[name, seq, qual, comment]
|
86
|
+
else
|
87
|
+
[name, seq, qual]
|
88
|
+
end
|
76
89
|
end
|
77
90
|
end
|
78
91
|
end
|
Binary file
|
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.2.23.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kojix2
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -25,76 +25,20 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: ffi-bitfield
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
|
-
type: :
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: minitest
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rake
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rubocop
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: tty-command
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
34
|
+
type: :runtime
|
91
35
|
prerelease: false
|
92
36
|
version_requirements: !ruby/object:Gem::Requirement
|
93
37
|
requirements:
|
94
38
|
- - ">="
|
95
39
|
- !ruby/object:Gem::Version
|
96
40
|
version: '0'
|
97
|
-
description:
|
41
|
+
description: Ruby bindings to the Minimap2 aligner.
|
98
42
|
email:
|
99
43
|
- 2xijok@gmail.com
|
100
44
|
executables: []
|
@@ -110,8 +54,8 @@ files:
|
|
110
54
|
- lib/minimap2/ffi/constants.rb
|
111
55
|
- lib/minimap2/ffi/functions.rb
|
112
56
|
- lib/minimap2/ffi/mappy.rb
|
113
|
-
- lib/minimap2/ffi_helper.rb
|
114
57
|
- lib/minimap2/version.rb
|
58
|
+
- vendor/libminimap2.so
|
115
59
|
homepage: https://github.com/kojix2/ruby-minimap2
|
116
60
|
licenses:
|
117
61
|
- MIT
|
@@ -131,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
75
|
- !ruby/object:Gem::Version
|
132
76
|
version: '0'
|
133
77
|
requirements: []
|
134
|
-
rubygems_version: 3.2.
|
78
|
+
rubygems_version: 3.2.26
|
135
79
|
signing_key:
|
136
80
|
specification_version: 4
|
137
81
|
summary: minimap2
|
data/lib/minimap2/ffi_helper.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'ffi'
|
4
|
-
|
5
|
-
module FFI
|
6
|
-
class BitStruct < Struct
|
7
|
-
class << self
|
8
|
-
# def union_layout(*args)
|
9
|
-
# Class.new(FFI::Union) { layout(*args) }
|
10
|
-
# end
|
11
|
-
|
12
|
-
# def struct_layout(*args)
|
13
|
-
# Class.new(FFI::Struct) { layout(*args) }
|
14
|
-
# end
|
15
|
-
|
16
|
-
module BitFieldsModule
|
17
|
-
def [](name)
|
18
|
-
bit_fields = self.class.bit_fields_map
|
19
|
-
parent, start, width = bit_fields[name]
|
20
|
-
if parent
|
21
|
-
(super(parent) >> start) & ((1 << width) - 1)
|
22
|
-
else
|
23
|
-
super(name)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
private_constant :BitFieldsModule
|
28
|
-
|
29
|
-
attr_reader :bit_fields_map
|
30
|
-
|
31
|
-
def bitfields(*args)
|
32
|
-
unless instance_variable_defined?(:@bit_fields)
|
33
|
-
@bit_fields_map = {}
|
34
|
-
prepend BitFieldsModule
|
35
|
-
end
|
36
|
-
|
37
|
-
parent = args.shift
|
38
|
-
labels = []
|
39
|
-
widths = []
|
40
|
-
args.each_slice(2) do |l, w|
|
41
|
-
labels << l
|
42
|
-
widths << w
|
43
|
-
end
|
44
|
-
starts = widths.inject([0]) do |result, w|
|
45
|
-
result << (result.last + w)
|
46
|
-
end
|
47
|
-
labels.zip(starts, widths).each do |l, s, w|
|
48
|
-
@bit_fields_map[l] = [parent, s, w]
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|