genomer-plugin-summary 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/features/contigs.feature +347 -0
- data/features/gaps.feature +34 -0
- data/features/genome.feature +213 -0
- data/features/sequences.feature +39 -8
- data/lib/genomer-plugin-summary/contigs.rb +63 -0
- data/lib/genomer-plugin-summary/enumerators.rb +81 -0
- data/lib/genomer-plugin-summary/format.rb +87 -0
- data/lib/genomer-plugin-summary/gaps.rb +25 -33
- data/lib/genomer-plugin-summary/genome.rb +51 -0
- data/lib/genomer-plugin-summary/metrics.rb +23 -9
- data/lib/genomer-plugin-summary/sequences.rb +44 -70
- data/spec/genomer-plugin-summary_spec/contigs_spec.rb +211 -0
- data/spec/genomer-plugin-summary_spec/enumerators_spec.rb +383 -0
- data/spec/genomer-plugin-summary_spec/format_spec.rb +285 -0
- data/spec/genomer-plugin-summary_spec/gaps_spec.rb +32 -7
- data/spec/genomer-plugin-summary_spec/{scaffold_spec.rb → genome_spec.rb} +26 -7
- data/spec/genomer-plugin-summary_spec/metrics_spec.rb +64 -0
- data/spec/genomer-plugin-summary_spec/sequences_spec.rb +52 -85
- data/spec/spec_helper.rb +1 -1
- metadata +20 -9
- data/features/scaffold.feature +0 -122
- data/lib/genomer-plugin-summary/scaffold.rb +0 -56
@@ -0,0 +1,211 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'genomer-plugin-summary/contigs'
|
3
|
+
|
4
|
+
describe GenomerPluginSummary::Contigs do
|
5
|
+
|
6
|
+
def row(num,start,stop,percent,gc)
|
7
|
+
{:id => num,
|
8
|
+
:start => start,
|
9
|
+
:stop => stop,
|
10
|
+
:size => (stop - start) + 1,
|
11
|
+
:percent => percent,
|
12
|
+
:type => :contig,
|
13
|
+
:gc => gc}
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#tabulate" do
|
17
|
+
|
18
|
+
subject do
|
19
|
+
described_class.new([],{}).tabulate(contigs,total,flags)
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:flags) do
|
23
|
+
{}
|
24
|
+
end
|
25
|
+
|
26
|
+
context "passed an empty array" do
|
27
|
+
|
28
|
+
let(:contigs) do
|
29
|
+
[]
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:total) do
|
33
|
+
{:start => 0,
|
34
|
+
:stop => 0,
|
35
|
+
:size => 0,
|
36
|
+
:percent => 0,
|
37
|
+
:gc => 0 }
|
38
|
+
end
|
39
|
+
|
40
|
+
it do
|
41
|
+
should ==<<-EOS.unindent!
|
42
|
+
+--------+------------+------------+------------+----------+--------+
|
43
|
+
| Scaffold Contigs |
|
44
|
+
+--------+------------+------------+------------+----------+--------+
|
45
|
+
| Contig | Start (bp) | End (bp) | Size (bp) | Size (%) | GC (%) |
|
46
|
+
+--------+------------+------------+------------+----------+--------+
|
47
|
+
+--------+------------+------------+------------+----------+--------+
|
48
|
+
| All | 0 | 0 | 0 | 0.00 | 0.00 |
|
49
|
+
+--------+------------+------------+------------+----------+--------+
|
50
|
+
EOS
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
context "passed an array with a single row" do
|
56
|
+
|
57
|
+
let(:contigs) do
|
58
|
+
[row(1,1,4,100.0,50.0)]
|
59
|
+
end
|
60
|
+
|
61
|
+
let(:total) do
|
62
|
+
{:start => '1',
|
63
|
+
:stop => '4',
|
64
|
+
:size => '4',
|
65
|
+
:percent => 100.0,
|
66
|
+
:gc => 50.0 }
|
67
|
+
end
|
68
|
+
|
69
|
+
it do
|
70
|
+
should ==<<-EOS.unindent!
|
71
|
+
+--------+------------+------------+------------+----------+--------+
|
72
|
+
| Scaffold Contigs |
|
73
|
+
+--------+------------+------------+------------+----------+--------+
|
74
|
+
| Contig | Start (bp) | End (bp) | Size (bp) | Size (%) | GC (%) |
|
75
|
+
+--------+------------+------------+------------+----------+--------+
|
76
|
+
| 1 | 1 | 4 | 4 | 100.00 | 50.00 |
|
77
|
+
+--------+------------+------------+------------+----------+--------+
|
78
|
+
| All | 1 | 4 | 4 | 100.00 | 50.00 |
|
79
|
+
+--------+------------+------------+------------+----------+--------+
|
80
|
+
EOS
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
context "passed a array with two rows" do
|
86
|
+
|
87
|
+
let(:contigs) do
|
88
|
+
[row(1,1,4,100.0,50.0),
|
89
|
+
row(2,1,4,100.0,50.0)]
|
90
|
+
end
|
91
|
+
|
92
|
+
let(:total) do
|
93
|
+
{:start => '1',
|
94
|
+
:stop => '4',
|
95
|
+
:size => '4',
|
96
|
+
:percent => 100.0,
|
97
|
+
:gc => 50.0 }
|
98
|
+
end
|
99
|
+
|
100
|
+
it do
|
101
|
+
should ==<<-EOS.unindent!
|
102
|
+
+--------+------------+------------+------------+----------+--------+
|
103
|
+
| Scaffold Contigs |
|
104
|
+
+--------+------------+------------+------------+----------+--------+
|
105
|
+
| Contig | Start (bp) | End (bp) | Size (bp) | Size (%) | GC (%) |
|
106
|
+
+--------+------------+------------+------------+----------+--------+
|
107
|
+
| 1 | 1 | 4 | 4 | 100.00 | 50.00 |
|
108
|
+
| 2 | 1 | 4 | 4 | 100.00 | 50.00 |
|
109
|
+
+--------+------------+------------+------------+----------+--------+
|
110
|
+
| All | 1 | 4 | 4 | 100.00 | 50.00 |
|
111
|
+
+--------+------------+------------+------------+----------+--------+
|
112
|
+
EOS
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
context "passed the csv output option" do
|
118
|
+
|
119
|
+
let(:flags) do
|
120
|
+
{:output => 'csv'}
|
121
|
+
end
|
122
|
+
|
123
|
+
let(:contigs) do
|
124
|
+
[row(1,1,4,100.0,50.0),
|
125
|
+
row(2,1,4,100.0,50.0)]
|
126
|
+
end
|
127
|
+
|
128
|
+
let(:total) do
|
129
|
+
{:start => '1',
|
130
|
+
:stop => '4',
|
131
|
+
:size => '4',
|
132
|
+
:percent => 100.0,
|
133
|
+
:gc => 50.0 }
|
134
|
+
end
|
135
|
+
|
136
|
+
it do
|
137
|
+
should ==<<-EOS.unindent!
|
138
|
+
contig,start_bp,end_bp,size_bp,size_%,gc_%
|
139
|
+
1,1,4,4,100.00,50.00
|
140
|
+
2,1,4,4,100.00,50.00
|
141
|
+
all,1,4,4,100.00,50.00
|
142
|
+
EOS
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "#calculate" do
|
150
|
+
|
151
|
+
subject do
|
152
|
+
described_class.new([],{}).calculate(scaffold)
|
153
|
+
end
|
154
|
+
|
155
|
+
context "passed an empty array" do
|
156
|
+
let(:scaffold) do
|
157
|
+
[]
|
158
|
+
end
|
159
|
+
|
160
|
+
it do
|
161
|
+
should == []
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context "passed one sequence" do
|
166
|
+
let(:scaffold) do
|
167
|
+
[sequence('AAAGGG','contig1')]
|
168
|
+
end
|
169
|
+
|
170
|
+
it do
|
171
|
+
should == [row(1,1,6,100.0,50.0)]
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context "passed two sequences" do
|
176
|
+
let(:scaffold) do
|
177
|
+
[sequence('AAAGGG','contig1'),
|
178
|
+
sequence('AAAGGG','contig2')]
|
179
|
+
end
|
180
|
+
|
181
|
+
it do
|
182
|
+
should == [row(1, 1, 12, 100.0, 50.0)]
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
context "passed two sequences separated by a gap" do
|
187
|
+
let(:scaffold) do
|
188
|
+
[sequence('AAAGGG','contig1'),
|
189
|
+
unresolved('NNNNNNNN'),
|
190
|
+
sequence('AAAGGG','contig2')]
|
191
|
+
end
|
192
|
+
|
193
|
+
it do
|
194
|
+
should == [row(1, 1, 6, 30.0, 50.0),
|
195
|
+
row(2, 15, 20, 30.0, 50.0)]
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
context "passed one contig containing a gap" do
|
200
|
+
let(:scaffold) do
|
201
|
+
[sequence('AAAGGGNNNNNNNNAAAGGG','contig1')]
|
202
|
+
end
|
203
|
+
|
204
|
+
it do
|
205
|
+
should == [row(1, 1, 6, 30.0, 50.0),
|
206
|
+
row(2, 15, 20, 30.0, 50.0)]
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
end
|
@@ -0,0 +1,383 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'genomer-plugin-summary/enumerators'
|
3
|
+
|
4
|
+
describe GenomerPluginSummary::Enumerators do
|
5
|
+
|
6
|
+
describe "#enumerator_for" do
|
7
|
+
|
8
|
+
subject do
|
9
|
+
o = Object.new
|
10
|
+
o.extend described_class
|
11
|
+
o.enumerator_for(type,scaffold).to_a
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "sequence" do
|
15
|
+
|
16
|
+
let(:type){ :sequence }
|
17
|
+
|
18
|
+
context "with an empty scaffold" do
|
19
|
+
|
20
|
+
let(:scaffold) do
|
21
|
+
[]
|
22
|
+
end
|
23
|
+
|
24
|
+
it do
|
25
|
+
should == []
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with a single unresolved region" do
|
31
|
+
|
32
|
+
let(:scaffold) do
|
33
|
+
[unresolved('NNNN')]
|
34
|
+
end
|
35
|
+
|
36
|
+
it do
|
37
|
+
should == []
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
context "with a single sequence region" do
|
43
|
+
|
44
|
+
let(:scaffold) do
|
45
|
+
[sequence('ATGC','ctg1')]
|
46
|
+
end
|
47
|
+
|
48
|
+
it do
|
49
|
+
should == [
|
50
|
+
{:start => 1,
|
51
|
+
:stop => 4,
|
52
|
+
:id => 'ctg1',
|
53
|
+
:sequence => 'ATGC',
|
54
|
+
:type => :sequence}
|
55
|
+
]
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
context "with two sequence regions" do
|
61
|
+
|
62
|
+
let(:scaffold) do
|
63
|
+
[sequence('ATGC','ctg1'),sequence('ATGC','ctg2')]
|
64
|
+
end
|
65
|
+
|
66
|
+
it do
|
67
|
+
should == [
|
68
|
+
{ :start => 1,
|
69
|
+
:stop => 4,
|
70
|
+
:id => 'ctg1',
|
71
|
+
:sequence => 'ATGC',
|
72
|
+
:type => :sequence},
|
73
|
+
{ :start => 5,
|
74
|
+
:stop => 8,
|
75
|
+
:id => 'ctg2',
|
76
|
+
:sequence => 'ATGC',
|
77
|
+
:type => :sequence}
|
78
|
+
]
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
context "with two sequence regions separated by a gap" do
|
84
|
+
|
85
|
+
let(:scaffold) do
|
86
|
+
[sequence('ATGC','ctg1'), unresolved('NNNN'), sequence('ATGC','ctg2')]
|
87
|
+
end
|
88
|
+
|
89
|
+
it do
|
90
|
+
should == [
|
91
|
+
{ :start => 1,
|
92
|
+
:stop => 4,
|
93
|
+
:id => 'ctg1',
|
94
|
+
:sequence => 'ATGC',
|
95
|
+
:type => :sequence},
|
96
|
+
{ :start => 9,
|
97
|
+
:stop => 12,
|
98
|
+
:id => 'ctg2',
|
99
|
+
:sequence => 'ATGC',
|
100
|
+
:type => :sequence}
|
101
|
+
]
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "contig" do
|
109
|
+
|
110
|
+
let(:type){ :contig }
|
111
|
+
|
112
|
+
context "with an empty scaffold" do
|
113
|
+
|
114
|
+
let(:scaffold) do
|
115
|
+
[]
|
116
|
+
end
|
117
|
+
|
118
|
+
it do
|
119
|
+
should == []
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
context "with a single unresolved region" do
|
125
|
+
|
126
|
+
let(:scaffold) do
|
127
|
+
[unresolved('NNNN')]
|
128
|
+
end
|
129
|
+
|
130
|
+
it do
|
131
|
+
should == []
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
context "with a single sequence region" do
|
137
|
+
|
138
|
+
let(:scaffold) do
|
139
|
+
[sequence('ATGC','ctg1')]
|
140
|
+
end
|
141
|
+
|
142
|
+
it do
|
143
|
+
should == [
|
144
|
+
{:start => 1,
|
145
|
+
:stop => 4,
|
146
|
+
:id => 1,
|
147
|
+
:sequence => 'ATGC',
|
148
|
+
:type => :contig}
|
149
|
+
]
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
context "with two sequence regions" do
|
155
|
+
|
156
|
+
let(:scaffold) do
|
157
|
+
[sequence('ATGC','ctg1'),sequence('ATGC','ctg2')]
|
158
|
+
end
|
159
|
+
|
160
|
+
it do
|
161
|
+
should == [
|
162
|
+
{:start => 1,
|
163
|
+
:stop => 8,
|
164
|
+
:id => 1,
|
165
|
+
:sequence => 'ATGCATGC',
|
166
|
+
:type => :contig}
|
167
|
+
]
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
context "with two sequence regions separated by a gap" do
|
173
|
+
|
174
|
+
let(:scaffold) do
|
175
|
+
[sequence('ATGC','ctg1'), unresolved('NNNN'), sequence('ATGC','ctg2')]
|
176
|
+
end
|
177
|
+
|
178
|
+
it do
|
179
|
+
should == [
|
180
|
+
{ :start => 1,
|
181
|
+
:stop => 4,
|
182
|
+
:id => 1,
|
183
|
+
:sequence => 'ATGC',
|
184
|
+
:type => :contig},
|
185
|
+
{ :start => 9,
|
186
|
+
:stop => 12,
|
187
|
+
:id => 2,
|
188
|
+
:sequence => 'ATGC',
|
189
|
+
:type => :contig}
|
190
|
+
]
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
context "with two sequence regions, one containing a gap" do
|
196
|
+
|
197
|
+
let(:scaffold) do
|
198
|
+
[sequence('ATGCNNNNATGC','ctg1'), sequence('ATGC','ctg2')]
|
199
|
+
end
|
200
|
+
|
201
|
+
it do
|
202
|
+
should == [
|
203
|
+
{ :start => 1,
|
204
|
+
:stop => 4,
|
205
|
+
:id => 1,
|
206
|
+
:sequence => 'ATGC',
|
207
|
+
:type => :contig},
|
208
|
+
{ :start => 9,
|
209
|
+
:stop => 16,
|
210
|
+
:id => 2,
|
211
|
+
:sequence => 'ATGCATGC',
|
212
|
+
:type => :contig}
|
213
|
+
]
|
214
|
+
end
|
215
|
+
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "unresolved" do
|
221
|
+
|
222
|
+
let(:type){ :unresolved }
|
223
|
+
|
224
|
+
context "with an empty scaffold" do
|
225
|
+
|
226
|
+
let(:scaffold) do
|
227
|
+
[]
|
228
|
+
end
|
229
|
+
|
230
|
+
it do
|
231
|
+
should == []
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
context "with a single unresolved region" do
|
237
|
+
|
238
|
+
let(:scaffold) do
|
239
|
+
[unresolved('NNNN')]
|
240
|
+
end
|
241
|
+
|
242
|
+
it do
|
243
|
+
should == [
|
244
|
+
{ :start => 1,
|
245
|
+
:stop => 4,
|
246
|
+
:id => nil,
|
247
|
+
:sequence => 'NNNN',
|
248
|
+
:type => :unresolved},
|
249
|
+
]
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
|
254
|
+
context "with a single sequence region" do
|
255
|
+
|
256
|
+
let(:scaffold) do
|
257
|
+
[sequence('ATGC','ctg1')]
|
258
|
+
end
|
259
|
+
|
260
|
+
it do
|
261
|
+
should == []
|
262
|
+
end
|
263
|
+
|
264
|
+
end
|
265
|
+
|
266
|
+
context "with two sequence regions separated by a gap" do
|
267
|
+
|
268
|
+
let(:scaffold) do
|
269
|
+
[sequence('ATGC','ctg1'), unresolved('NNNN'), sequence('ATGC','ctg2')]
|
270
|
+
end
|
271
|
+
|
272
|
+
it do
|
273
|
+
should == [
|
274
|
+
{ :start => 5,
|
275
|
+
:stop => 8,
|
276
|
+
:id => nil,
|
277
|
+
:sequence => 'NNNN',
|
278
|
+
:type => :unresolved},
|
279
|
+
]
|
280
|
+
end
|
281
|
+
|
282
|
+
end
|
283
|
+
|
284
|
+
end
|
285
|
+
|
286
|
+
describe "gap" do
|
287
|
+
|
288
|
+
let(:type){ :gap }
|
289
|
+
|
290
|
+
context "with an empty scaffold" do
|
291
|
+
|
292
|
+
let(:scaffold) do
|
293
|
+
[]
|
294
|
+
end
|
295
|
+
|
296
|
+
it do
|
297
|
+
should == []
|
298
|
+
end
|
299
|
+
|
300
|
+
end
|
301
|
+
|
302
|
+
context "with a single unresolved region" do
|
303
|
+
|
304
|
+
let(:scaffold) do
|
305
|
+
[unresolved('NNNN')]
|
306
|
+
end
|
307
|
+
|
308
|
+
it do
|
309
|
+
should == [
|
310
|
+
{ :start => 1,
|
311
|
+
:stop => 4,
|
312
|
+
:id => 1,
|
313
|
+
:sequence => 'NNNN',
|
314
|
+
:type => :gap},
|
315
|
+
]
|
316
|
+
end
|
317
|
+
|
318
|
+
end
|
319
|
+
|
320
|
+
context "with a single sequence region" do
|
321
|
+
|
322
|
+
let(:scaffold) do
|
323
|
+
[sequence('ATGC','ctg1')]
|
324
|
+
end
|
325
|
+
|
326
|
+
it do
|
327
|
+
should == []
|
328
|
+
end
|
329
|
+
|
330
|
+
end
|
331
|
+
|
332
|
+
context "with two sequence regions" do
|
333
|
+
|
334
|
+
let(:scaffold) do
|
335
|
+
[sequence('ATGC','ctg1'),sequence('ATGC','ctg2')]
|
336
|
+
end
|
337
|
+
|
338
|
+
it do
|
339
|
+
should == []
|
340
|
+
end
|
341
|
+
|
342
|
+
end
|
343
|
+
|
344
|
+
context "with two sequence regions separated by a gap" do
|
345
|
+
|
346
|
+
let(:scaffold) do
|
347
|
+
[sequence('ATGC','ctg1'), unresolved('NNNN'), sequence('ATGC','ctg2')]
|
348
|
+
end
|
349
|
+
|
350
|
+
it do
|
351
|
+
should == [
|
352
|
+
{ :start => 5,
|
353
|
+
:stop => 8,
|
354
|
+
:id => 1,
|
355
|
+
:sequence => 'NNNN',
|
356
|
+
:type => :gap},
|
357
|
+
]
|
358
|
+
end
|
359
|
+
|
360
|
+
end
|
361
|
+
|
362
|
+
context "with two sequence regions, one containing a gap" do
|
363
|
+
|
364
|
+
let(:scaffold) do
|
365
|
+
[sequence('ATGCNNNNATGC','ctg1'), sequence('ATGC','ctg2')]
|
366
|
+
end
|
367
|
+
|
368
|
+
it do
|
369
|
+
should == [
|
370
|
+
{ :start => 5,
|
371
|
+
:stop => 8,
|
372
|
+
:id => 1,
|
373
|
+
:sequence => 'NNNN',
|
374
|
+
:type => :gap},
|
375
|
+
]
|
376
|
+
end
|
377
|
+
|
378
|
+
end
|
379
|
+
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
end
|