bio 2.0.1 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,462 @@
1
+ #
2
+ # test/unit/bio/sequence/test_ruby3.rb - Unit test for Bio::Sequencce::Common with Ruby version 3
3
+ #
4
+ # Copyright:: Copyright (C) 2021 BioRuby Project
5
+ # Maintainter:: Naohisa Goto <ng@bioruby.org>
6
+ # License:: The Ruby License
7
+ #
8
+
9
+ # loading helper routine for testing bioruby
10
+ require 'pathname'
11
+ load Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 3,
12
+ 'bioruby_test_helper.rb')).cleanpath.to_s
13
+
14
+ # libraries needed for the tests
15
+ require 'test/unit'
16
+ require 'bio/sequence'
17
+ require 'bio/sequence/common'
18
+
19
+ module Bio; module TestSequenceRuby3
20
+
21
+ class TSeq < String
22
+ include Bio::Sequence::Common
23
+ end
24
+
25
+ class TestSequenceCommon < Test::Unit::TestCase
26
+
27
+ def test_multiply
28
+ str = 'atgc'.freeze
29
+ obj = TSeq.new(str)
30
+ val = obj * 3
31
+ assert_instance_of(TSeq, val)
32
+ assert_equal(TSeq.new(str * 3), val)
33
+ end
34
+
35
+ def test_chomp
36
+ [ "atgc\n".freeze, "atgc".freeze ].each do |str|
37
+ obj = TSeq.new(str)
38
+ val = obj.chomp
39
+ assert_instance_of(TSeq, val)
40
+ assert_equal(TSeq.new(str.chomp), val)
41
+ end
42
+ end
43
+
44
+ def test_chop
45
+ [ "atgc\n".freeze, "atgc".freeze ].each do |str|
46
+ obj = TSeq.new(str)
47
+ val = obj.chop
48
+ assert_instance_of(TSeq, val)
49
+ assert_equal(TSeq.new(str.chop), val)
50
+ end
51
+ end
52
+
53
+ def test_delete
54
+ str = "atgggc".freeze
55
+ obj = TSeq.new(str)
56
+ val = obj.delete("g")
57
+ assert_instance_of(TSeq, val)
58
+ assert_equal(TSeq.new("atc"), val)
59
+ end
60
+
61
+ if "string".respond_to?(:delete_prefix)
62
+ def test_delete_prefix
63
+ str = "atgggc".freeze
64
+ obj = TSeq.new(str)
65
+ val = obj.delete_prefix("atg")
66
+ assert_instance_of(TSeq, val)
67
+ assert_equal(TSeq.new("ggc"), val)
68
+ end
69
+ end #if "string".respond_to?(:delete_prefix)
70
+
71
+
72
+ if "string".respond_to?(:delete_suffix)
73
+ def test_delete_suffix
74
+ str = "atgggc".freeze
75
+ obj = TSeq.new(str)
76
+ val = obj.delete_suffix("ggc")
77
+ assert_instance_of(TSeq, val)
78
+ assert_equal(TSeq.new("atg"), val)
79
+ end
80
+ end #if "string".respond_to?(:delete_suffix)
81
+
82
+ def test_each_char
83
+ str = 'atgc'.freeze
84
+ ary = str.split(//)
85
+ obj = TSeq.new(str)
86
+ obj.each_char do |c|
87
+ assert_instance_of(TSeq, c)
88
+ assert_equal(TSeq.new(ary.shift), c)
89
+ end
90
+ end
91
+
92
+ def test_each_char_enum
93
+ str = 'atgc'.freeze
94
+ ary = str.split(//).collect { |c| TSeq.new(c) }
95
+ obj = TSeq.new(str)
96
+ e = obj.each_char
97
+ to_a = e.to_a
98
+ to_a.each { |c| assert_instance_of(TSeq, c) }
99
+ assert_equal(ary, to_a)
100
+ end
101
+
102
+ if "string".respond_to?(:each_grapheme_cluster)
103
+ def test_each_grapheme_cluster
104
+ str = 'atgc'.freeze
105
+ ary = str.split(//)
106
+ obj = TSeq.new(str)
107
+ obj.each_grapheme_cluster do |c|
108
+ assert_instance_of(TSeq, c)
109
+ assert_equal(TSeq.new(ary.shift), c)
110
+ end
111
+ end
112
+
113
+ def test_each_grapheme_cluster_enum
114
+ str = 'atgc'.freeze
115
+ ary = str.split(//).collect { |c| TSeq.new(c) }
116
+ obj = TSeq.new(str)
117
+ e = obj.each_grapheme_cluster
118
+ to_a = e.to_a
119
+ to_a.each { |c| assert_instance_of(TSeq, c) }
120
+ assert_equal(ary, to_a)
121
+ end
122
+ end #if "string".respond_to?(:each_grapheme_cluster)
123
+
124
+ def test_each_line
125
+ str = "aagtcgt\nttgctagc\nggtacagt\n".freeze
126
+ ary = str.each_line.to_a
127
+ obj = TSeq.new(str)
128
+ obj.each_line do |c|
129
+ assert_instance_of(TSeq, c)
130
+ assert_equal(TSeq.new(ary.shift), c)
131
+ end
132
+ end
133
+
134
+ def test_each_line_enum
135
+ str = "aagtcgt\nttgctagc\nggtacagt\n".freeze
136
+ ary = str.each_line.collect { |x| TSeq.new(x) }
137
+ obj = TSeq.new(str)
138
+ e = obj.each_line
139
+ to_a = e.to_a
140
+ to_a.each { |x| assert_instance_of(TSeq, x) }
141
+ assert_equal(ary, to_a)
142
+ end
143
+
144
+ def test_gsub
145
+ str = "aagtcgtaacaaggt".freeze
146
+ str2 = str.gsub(/aa/, "bb")
147
+ obj = TSeq.new(str)
148
+ val = obj.gsub(/aa/, "bb")
149
+ assert_instance_of(TSeq, val)
150
+ assert_equal(TSeq.new(str2), val)
151
+ end
152
+
153
+ def test_sub
154
+ str = "aagtcgtaacaaggt".freeze
155
+ str2 = str.sub(/aa/, "bb")
156
+ obj = TSeq.new(str)
157
+ val = obj.sub(/aa/, "bb")
158
+ assert_instance_of(TSeq, val)
159
+ assert_equal(TSeq.new(str2), val)
160
+ end
161
+
162
+ def test_gsub_with_block
163
+ str = "aagtcgtaacaaggtaagt".freeze
164
+ str2 = str.gsub(/a(ag)/) { |x| "bb" }
165
+ obj = TSeq.new(str)
166
+ val = obj.gsub(/a(ag)/) do |x|
167
+ assert_equal("ag", $1)
168
+ assert_equal("aag", $&)
169
+ assert_equal(TSeq.new("aag"), x)
170
+ assert_instance_of(MatchData, Regexp.last_match)
171
+ assert_instance_of(TSeq, x)
172
+ "bb"
173
+ end
174
+ assert_instance_of(TSeq, val)
175
+ assert_equal(TSeq.new(str2), val)
176
+ end
177
+
178
+ def test_sub_with_block
179
+ str = "aagtcgtaacaaggtaagt".freeze
180
+ str2 = str.sub(/a(ag)/) { |x| "bb" }
181
+ obj = TSeq.new(str)
182
+ val = obj.sub(/a(ag)/) do |x|
183
+ assert_equal("ag", $1)
184
+ assert_equal("aag", $&)
185
+ assert_equal(TSeq.new("aag"), x)
186
+ assert_instance_of(MatchData, Regexp.last_match)
187
+ assert_instance_of(TSeq, x)
188
+ "bb"
189
+ end
190
+ assert_instance_of(TSeq, val)
191
+ assert_equal(TSeq.new(str2), val)
192
+ end
193
+
194
+ def test_ljust
195
+ str = "atgc".freeze
196
+ str2 = str.ljust(20, "xyz")
197
+ obj = TSeq.new(str)
198
+ val = obj.ljust(20, "xyz")
199
+ assert_instance_of(TSeq, val)
200
+ assert_equal(TSeq.new(str2), val)
201
+ end
202
+
203
+ def test_rjust
204
+ str = "atgc".freeze
205
+ str2 = str.rjust(20, "xyz")
206
+ obj = TSeq.new(str)
207
+ val = obj.rjust(20, "xyz")
208
+ assert_instance_of(TSeq, val)
209
+ assert_equal(TSeq.new(str2), val)
210
+ end
211
+
212
+ def test_center
213
+ str = "atgc".freeze
214
+ str2 = str.center(20, "xyz")
215
+ obj = TSeq.new(str)
216
+ val = obj.center(20, "xyz")
217
+ assert_instance_of(TSeq, val)
218
+ assert_equal(TSeq.new(str2), val)
219
+ end
220
+
221
+ def test_strip
222
+ str = " at gc\n".freeze
223
+ str2 = str.strip
224
+ obj = TSeq.new(str)
225
+ val = obj.strip
226
+ assert_instance_of(TSeq, val)
227
+ assert_equal(TSeq.new(str2), val)
228
+ end
229
+
230
+ def test_lstrip
231
+ str = " at gc\n".freeze
232
+ str2 = str.lstrip
233
+ obj = TSeq.new(str)
234
+ val = obj.lstrip
235
+ assert_instance_of(TSeq, val)
236
+ assert_equal(TSeq.new(str2), val)
237
+ end
238
+
239
+ def test_rstrip
240
+ str = " at gc\n".freeze
241
+ str2 = str.rstrip
242
+ obj = TSeq.new(str)
243
+ val = obj.rstrip
244
+ assert_instance_of(TSeq, val)
245
+ assert_equal(TSeq.new(str2), val)
246
+ end
247
+
248
+ def test_split
249
+ str = "aagtcgta".freeze
250
+ ary = str.split("gt").collect { |x| TSeq.new(x) }
251
+ obj = TSeq.new(str)
252
+ val = obj.split("gt")
253
+ val.each do |x|
254
+ assert_instance_of(TSeq, x)
255
+ end
256
+ assert_equal(ary, val)
257
+ end
258
+
259
+ def test_reverse
260
+ str = "aagtttcca".freeze
261
+ str2 = str.reverse
262
+ obj = TSeq.new(str)
263
+ val = obj.reverse
264
+ assert_instance_of(TSeq, val)
265
+ assert_equal(TSeq.new(str2), val)
266
+ end
267
+
268
+ def test_squeeze
269
+ str = "aagtttcca".freeze
270
+ str2 = str.squeeze
271
+ obj = TSeq.new(str)
272
+ val = obj.squeeze
273
+ assert_instance_of(TSeq, val)
274
+ assert_equal(TSeq.new(str2), val)
275
+ end
276
+
277
+ def test_succ
278
+ str = "aagt".freeze
279
+ str2 = str.succ
280
+ obj = TSeq.new(str)
281
+ val = obj.succ
282
+ assert_instance_of(TSeq, val)
283
+ assert_equal(TSeq.new(str2), val)
284
+ end
285
+
286
+ def test_next
287
+ str = "aagt".freeze
288
+ str2 = str.next
289
+ obj = TSeq.new(str)
290
+ val = obj.next
291
+ assert_instance_of(TSeq, val)
292
+ assert_equal(TSeq.new(str2), val)
293
+ end
294
+
295
+ def test_capitalize
296
+ str = "aacgt".freeze
297
+ str2 = str.capitalize
298
+ obj = TSeq.new(str)
299
+ val = obj.capitalize
300
+ assert_instance_of(TSeq, val)
301
+ assert_equal(TSeq.new(str2), val)
302
+ end
303
+
304
+ def test_upcase
305
+ str = "aacgt".freeze
306
+ str2 = str.upcase
307
+ obj = TSeq.new(str)
308
+ val = obj.upcase
309
+ assert_instance_of(TSeq, val)
310
+ assert_equal(TSeq.new(str2), val)
311
+ end
312
+
313
+ def test_downcase
314
+ str = "AACGT".freeze
315
+ str2 = str.downcase
316
+ obj = TSeq.new(str)
317
+ val = obj.downcase
318
+ assert_instance_of(TSeq, val)
319
+ assert_equal(TSeq.new(str2), val)
320
+ end
321
+
322
+ def test_swapcase
323
+ str = "AaCgT".freeze
324
+ str2 = str.swapcase
325
+ obj = TSeq.new(str)
326
+ val = obj.swapcase
327
+ assert_instance_of(TSeq, val)
328
+ assert_equal(TSeq.new(str2), val)
329
+ end
330
+
331
+ def test_tr
332
+ str = "acggt".freeze
333
+ str2 = str.tr("cg", "xy")
334
+ obj = TSeq.new(str)
335
+ val = obj.tr("cg", "xy")
336
+ assert_instance_of(TSeq, val)
337
+ assert_equal(TSeq.new(str2), val)
338
+ end
339
+
340
+ def test_tr_s
341
+ str = "acggt".freeze
342
+ str2 = str.tr("cg", "n")
343
+ obj = TSeq.new(str)
344
+ val = obj.tr("cg", "n")
345
+ assert_instance_of(TSeq, val)
346
+ assert_equal(TSeq.new(str2), val)
347
+ end
348
+
349
+ def test_slice
350
+ str = "aagtcgta".freeze
351
+ str2 = str.slice(3, 3)
352
+ obj = TSeq.new(str)
353
+ val = obj.slice(3, 3)
354
+ assert_instance_of(TSeq, val)
355
+ assert_equal(TSeq.new(str2), val)
356
+ end
357
+
358
+ def test_slice2
359
+ str = "aagtcgta".freeze
360
+ str2 = str[3, 3]
361
+ obj = TSeq.new(str)
362
+ val = obj[3, 3]
363
+ assert_instance_of(TSeq, val)
364
+ assert_equal(TSeq.new(str2), val)
365
+ end
366
+ end #class TestSequenceCommon
367
+
368
+
369
+ class TestSequenceCommonPartition < Test::Unit::TestCase
370
+ def test_partition
371
+ str = "atgatgagttctattcatc".freeze
372
+ sep = "ttc".freeze
373
+ a0 = str.partition(sep)
374
+ a1 = [ TSeq.new(a0[0]), a0[1], TSeq.new(a0[2]) ]
375
+ obj = TSeq.new(str)
376
+ val = obj.partition(sep)
377
+ assert_instance_of(TSeq, val[0])
378
+ assert_instance_of(String, val[1])
379
+ assert_instance_of(TSeq, val[2])
380
+ assert_equal(a1, val)
381
+ end
382
+
383
+ def test_partition_sep_TSeq
384
+ str = "atgatgagttctattcatc".freeze
385
+ sep = TSeq.new("ttc").freeze
386
+ a0 = str.partition(sep)
387
+ a1 = [ TSeq.new(a0[0]), a0[1], TSeq.new(a0[2]) ]
388
+ obj = TSeq.new(str)
389
+ val = obj.partition(sep)
390
+ val.each { |x| assert_instance_of(TSeq, x) }
391
+ assert_equal(a1, val)
392
+ end
393
+
394
+ def test_partition_sep_regexp
395
+ str = "atgatgagttctattcatc".freeze
396
+ sep = /ttc/
397
+ a1 = str.partition(sep).collect { |x| TSeq.new(x) }
398
+ obj = TSeq.new(str)
399
+ val = obj.partition(sep)
400
+ val.each { |x| assert_instance_of(TSeq, x) }
401
+ assert_equal(a1, val)
402
+ end
403
+
404
+ def test_partition_nomatch
405
+ str = "atgatgagttctattcatc".freeze
406
+ sep = "x".freeze
407
+ a1 = str.partition(sep).collect { |x| TSeq.new(x) }
408
+ obj = TSeq.new(str)
409
+ val = obj.partition(sep)
410
+ val.each { |x| assert_instance_of(TSeq, x) }
411
+ assert_equal(a1, val)
412
+ end
413
+ end #class TestSequenceCommonPartition
414
+
415
+
416
+ class TestSequenceCommonRpartition < Test::Unit::TestCase
417
+ def test_rpartition
418
+ str = "atgatgagttctattcatc".freeze
419
+ sep = "ttc".freeze
420
+ a0 = str.rpartition(sep)
421
+ a1 = [ TSeq.new(a0[0]), a0[1], TSeq.new(a0[2]) ]
422
+ obj = TSeq.new(str)
423
+ val = obj.rpartition(sep)
424
+ assert_instance_of(TSeq, val[0])
425
+ assert_instance_of(String, val[1])
426
+ assert_instance_of(TSeq, val[2])
427
+ assert_equal(a1, val)
428
+ end
429
+
430
+ def test_rpartition_sep_TSeq
431
+ str = "atgatgagttctattcatc".freeze
432
+ sep = TSeq.new("ttc").freeze
433
+ a0 = str.rpartition(sep)
434
+ a1 = [ TSeq.new(a0[0]), a0[1], TSeq.new(a0[2]) ]
435
+ obj = TSeq.new(str)
436
+ val = obj.rpartition(sep)
437
+ val.each { |x| assert_instance_of(TSeq, x) }
438
+ assert_equal(a1, val)
439
+ end
440
+
441
+ def test_rpartition_sep_regexp
442
+ str = "atgatgagttctattcatc".freeze
443
+ sep = /ttc/
444
+ a1 = str.rpartition(sep).collect { |x| TSeq.new(x) }
445
+ obj = TSeq.new(str)
446
+ val = obj.rpartition(sep)
447
+ val.each { |x| assert_instance_of(TSeq, x) }
448
+ assert_equal(a1, val)
449
+ end
450
+
451
+ def test_rpartition_nomatch
452
+ str = "atgatgagttctattcatc".freeze
453
+ sep = "x".freeze
454
+ a1 = str.rpartition(sep).collect { |x| TSeq.new(x) }
455
+ obj = TSeq.new(str)
456
+ val = obj.rpartition(sep)
457
+ val.each { |x| assert_instance_of(TSeq, x) }
458
+ assert_equal(a1, val)
459
+ end
460
+ end #class TestSequenceCommonRpartition
461
+
462
+ end; end #module Bio; module TestSequenceRuby3
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bio
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - BioRuby project
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-06 00:00:00.000000000 Z
11
+ date: 2022-09-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: BioRuby is a library for bioinformatics (biology + information science).
14
14
  email: staff@bioruby.org
@@ -465,6 +465,7 @@ files:
465
465
  - test/data/sim4/simple2-A4.sim4
466
466
  - test/data/soft/GDS100_partial.soft
467
467
  - test/data/soft/GSE3457_family_partial.soft
468
+ - test/data/uniprot/P28907.uniprot
468
469
  - test/data/uniprot/p53_human.uniprot
469
470
  - test/functional/bio/sequence/test_output_embl.rb
470
471
  - test/functional/bio/test_command.rb
@@ -509,6 +510,7 @@ files:
509
510
  - test/unit/bio/db/embl/test_embl_to_bioseq.rb
510
511
  - test/unit/bio/db/embl/test_uniprot.rb
511
512
  - test/unit/bio/db/embl/test_uniprotkb.rb
513
+ - test/unit/bio/db/embl/test_uniprotkb_P28907.rb
512
514
  - test/unit/bio/db/embl/test_uniprotkb_new_part.rb
513
515
  - test/unit/bio/db/fasta/test_defline.rb
514
516
  - test/unit/bio/db/fasta/test_defline_misc.rb
@@ -557,6 +559,7 @@ files:
557
559
  - test/unit/bio/sequence/test_dblink.rb
558
560
  - test/unit/bio/sequence/test_na.rb
559
561
  - test/unit/bio/sequence/test_quality_score.rb
562
+ - test/unit/bio/sequence/test_ruby3.rb
560
563
  - test/unit/bio/sequence/test_sequence_masker.rb
561
564
  - test/unit/bio/test_alignment.rb
562
565
  - test/unit/bio/test_command.rb
@@ -616,8 +619,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
616
619
  - !ruby/object:Gem::Version
617
620
  version: '0'
618
621
  requirements: []
619
- rubyforge_project:
620
- rubygems_version: 2.7.6.2
622
+ rubygems_version: 3.1.6
621
623
  signing_key:
622
624
  specification_version: 4
623
625
  summary: Bioinformatics library