bio 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +954 -0
- data/KNOWN_ISSUES.rdoc +40 -5
- data/README.rdoc +36 -35
- data/RELEASE_NOTES.rdoc +87 -59
- data/bioruby.gemspec +24 -2
- data/doc/RELEASE_NOTES-1.4.1.rdoc +104 -0
- data/doc/Tutorial.rd +162 -200
- data/doc/Tutorial.rd.html +149 -146
- data/lib/bio.rb +1 -0
- data/lib/bio/appl/blast.rb +1 -1
- data/lib/bio/appl/blast/ddbj.rb +26 -34
- data/lib/bio/appl/blast/genomenet.rb +21 -11
- data/lib/bio/db/embl/sptr.rb +193 -21
- data/lib/bio/db/fasta.rb +1 -1
- data/lib/bio/db/fastq.rb +14 -0
- data/lib/bio/db/fastq/format_fastq.rb +2 -2
- data/lib/bio/db/genbank/ddbj.rb +1 -2
- data/lib/bio/db/genbank/format_genbank.rb +1 -1
- data/lib/bio/db/medline.rb +1 -0
- data/lib/bio/db/newick.rb +3 -1
- data/lib/bio/db/pdb/pdb.rb +9 -9
- data/lib/bio/db/pdb/residue.rb +2 -2
- data/lib/bio/io/ddbjrest.rb +344 -0
- data/lib/bio/io/ncbirest.rb +121 -1
- data/lib/bio/location.rb +2 -2
- data/lib/bio/reference.rb +3 -4
- data/lib/bio/shell/plugin/entry.rb +7 -3
- data/lib/bio/shell/plugin/ncbirest.rb +5 -1
- data/lib/bio/util/restriction_enzyme.rb +3 -0
- data/lib/bio/util/restriction_enzyme/dense_int_array.rb +195 -0
- data/lib/bio/util/restriction_enzyme/range/sequence_range.rb +7 -7
- data/lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb +57 -18
- data/lib/bio/util/restriction_enzyme/range/sequence_range/fragment.rb +2 -2
- data/lib/bio/util/restriction_enzyme/sorted_num_array.rb +219 -0
- data/lib/bio/version.rb +1 -1
- data/sample/test_restriction_enzyme_long.rb +4403 -0
- data/test/data/fasta/EFTU_BACSU.fasta +8 -0
- data/test/data/genbank/CAA35997.gp +48 -0
- data/test/data/genbank/SCU49845.gb +167 -0
- data/test/data/litdb/1717226.litdb +13 -0
- data/test/data/pir/CRAB_ANAPL.pir +6 -0
- data/test/functional/bio/appl/blast/test_remote.rb +93 -0
- data/test/functional/bio/appl/test_blast.rb +61 -0
- data/test/functional/bio/io/test_ddbjrest.rb +47 -0
- data/test/functional/bio/test_command.rb +3 -3
- data/test/unit/bio/db/embl/test_sptr.rb +6 -6
- data/test/unit/bio/db/embl/test_uniprot_new_part.rb +208 -0
- data/test/unit/bio/db/genbank/test_common.rb +274 -0
- data/test/unit/bio/db/genbank/test_genbank.rb +401 -0
- data/test/unit/bio/db/genbank/test_genpept.rb +81 -0
- data/test/unit/bio/db/pdb/test_pdb.rb +3287 -11
- data/test/unit/bio/db/test_fasta.rb +34 -12
- data/test/unit/bio/db/test_fastq.rb +26 -0
- data/test/unit/bio/db/test_litdb.rb +95 -0
- data/test/unit/bio/db/test_medline.rb +1 -0
- data/test/unit/bio/db/test_nbrf.rb +82 -0
- data/test/unit/bio/db/test_newick.rb +22 -4
- data/test/unit/bio/test_reference.rb +35 -0
- data/test/unit/bio/util/restriction_enzyme/test_dense_int_array.rb +201 -0
- data/test/unit/bio/util/restriction_enzyme/test_sorted_num_array.rb +281 -0
- metadata +44 -38
@@ -140,6 +140,40 @@ END
|
|
140
140
|
assert_equal(data, @obj.entry)
|
141
141
|
end
|
142
142
|
|
143
|
+
def test_entry_overrun
|
144
|
+
data =<<END
|
145
|
+
>gi|55416190|gb|AAV50057.1| NADH dehydrogenase subunit 2 [Dasyurus hallucatus]
|
146
|
+
MSPYVLMILTLSLFIGTCLTIFSNHWFTAWMGLEINTLAIIPLMTAPNNPRSTEAATKYFLTQATASMLMMFAIIYNAWS
|
147
|
+
TNQWALPQLSDDWISLLMTVALAIKLGLAPFHFWVPEVTQGIPLLTGMILLTWQKIAPTAILFQIAPYLNMKFLVILAIL
|
148
|
+
STLVGGWGGLNQTHLRKILAYSSIAHMGWMIIIVQINPTLSIFTLTIYVMATLTTFLTLNLSNSTKIKSLGNLWNKSATA
|
149
|
+
TIIIFLTLLSLGGLPPLTGFMPKWLILQELINNGNIITATMMALSALLNLFFYMRLIYASSLTMFPSINNSKMQWYNNSM
|
150
|
+
KTTTLIPTATVISSLLLPLTPLFVTLY
|
151
|
+
END
|
152
|
+
assert_equal(data, @obj.entry_overrun)
|
153
|
+
end
|
154
|
+
|
155
|
+
class DummyFactory
|
156
|
+
def query(str)
|
157
|
+
@query_str = str
|
158
|
+
"DummyFactoryResult#{str.length}"
|
159
|
+
end
|
160
|
+
attr_reader :query_str
|
161
|
+
end #class DummyFactory
|
162
|
+
|
163
|
+
def test_query
|
164
|
+
data =<<END
|
165
|
+
>gi|55416189|gb|AAV50056.1| NADH dehydrogenase subunit 1 [Dasyurus hallucatus]
|
166
|
+
MFTINLLIYIIPILLAVAFLTLIERKMLGYMQFRKGPNIVGPYGLLQPFADAVKLFTKEPLRPLTSSISIFIIAPILALT
|
167
|
+
IALTIWTPLPMPNTLLDLNLGLIFILSLSGLSVYSILWSGWASNSKYALIGALRAVAQTISYEVSLAIILLSIMLINGSF
|
168
|
+
TLKTLSITQENLWLIITTWPLAMMWYISTLAETNRAPFDLTEGESELVSGFNVEYAAGPFAMFFLAEYANIIAMNAITTI
|
169
|
+
LFLGPSLTPNLSHLNTLSFMLKTLLLTMVFLWVRASYPRFRYDQLMHLLWKNFLPMTLAMCLWFISLPIALSCIPPQL
|
170
|
+
END
|
171
|
+
|
172
|
+
factory = DummyFactory.new
|
173
|
+
assert_equal("DummyFactoryResult401", @obj.query(factory))
|
174
|
+
assert_equal(data, factory.query_str)
|
175
|
+
end
|
176
|
+
|
143
177
|
def test_entry_id
|
144
178
|
assert_equal('gi|55416189', @obj.entry_id)
|
145
179
|
end
|
@@ -194,16 +228,4 @@ END
|
|
194
228
|
|
195
229
|
end # class TestFastaFormat
|
196
230
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
class TestFastaDefinition < Test::Unit::TestCase
|
201
|
-
|
202
|
-
def setup
|
203
|
-
end
|
204
|
-
|
205
|
-
def test_defline
|
206
|
-
end
|
207
|
-
end # class TestFastaDefinition
|
208
|
-
|
209
231
|
end
|
@@ -278,6 +278,20 @@ _9_
|
|
278
278
|
end
|
279
279
|
end
|
280
280
|
|
281
|
+
def test_to_s
|
282
|
+
ids = IDLINES.dup
|
283
|
+
seqs = SEQS.dup
|
284
|
+
qstrs = QUALITY_STRINGS.dup
|
285
|
+
ent = []
|
286
|
+
while !ids.empty?
|
287
|
+
ent.push "@#{ids.shift}\n#{seqs.shift}\n+\n#{qstrs.shift}\n"
|
288
|
+
end
|
289
|
+
@ff.each do |e|
|
290
|
+
assert_equal(ent.shift, e.to_s)
|
291
|
+
end
|
292
|
+
assert(ent.empty?)
|
293
|
+
end
|
294
|
+
|
281
295
|
def test_definition
|
282
296
|
ids = IDLINES.dup
|
283
297
|
@ff.each do |e|
|
@@ -369,6 +383,18 @@ _9_
|
|
369
383
|
end
|
370
384
|
end
|
371
385
|
|
386
|
+
def test_to_biosequence_and_output
|
387
|
+
@ff.each_with_index do |e, i|
|
388
|
+
id_line = IDLINES[i]
|
389
|
+
seq_line = SEQS[i]
|
390
|
+
qual_line = QUALITY_STRINGS[i]
|
391
|
+
# Changed default width to nil (no wrapping)
|
392
|
+
expected = "@#{id_line}\n#{seq_line}\n+\n#{qual_line}\n"
|
393
|
+
actual = e.to_biosequence.output(:fastq_sanger)
|
394
|
+
assert_equal(expected, actual)
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
372
398
|
def test_roundtrip
|
373
399
|
@ff.each_with_index do |e, i|
|
374
400
|
str_orig = @ff.entry_raw
|
@@ -0,0 +1,95 @@
|
|
1
|
+
#
|
2
|
+
# test/unit/bio/db/litdb.rb - Unit test for Bio::LITDB
|
3
|
+
#
|
4
|
+
# Copyright:: Copyright (C) 2010 Kazuhiro Hayashi <k.hayashi.info@gmail.com>
|
5
|
+
# License:: The Ruby License
|
6
|
+
#
|
7
|
+
|
8
|
+
# loading helper routine for testing bioruby
|
9
|
+
require 'pathname'
|
10
|
+
load Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 3,
|
11
|
+
'bioruby_test_helper.rb')).cleanpath.to_s
|
12
|
+
|
13
|
+
# libraries needed for the tests
|
14
|
+
require 'test/unit'
|
15
|
+
require 'bio/db/litdb'
|
16
|
+
require 'bio/reference'
|
17
|
+
|
18
|
+
module Bio
|
19
|
+
class TestBioLITDB < Test::Unit::TestCase
|
20
|
+
|
21
|
+
def setup
|
22
|
+
filename = File.join(BioRubyTestDataPath, 'litdb', '1717226.litdb')
|
23
|
+
@obj = Bio::LITDB.new(File.read(filename))
|
24
|
+
end
|
25
|
+
|
26
|
+
# it return the reference infromation formatted as part of a Bio::Reference object.
|
27
|
+
def test_reference
|
28
|
+
expected =
|
29
|
+
{:authors=>
|
30
|
+
["Boyd, L.A.",
|
31
|
+
"Adam, L.",
|
32
|
+
"Pelcher, L.E.",
|
33
|
+
"McHughen, A.",
|
34
|
+
"Hirji, R.",
|
35
|
+
" Selvaraj, G."],
|
36
|
+
|
37
|
+
:issue=>"1",
|
38
|
+
:journal=>"Gene",
|
39
|
+
:pages=>"45-52",
|
40
|
+
:title=>
|
41
|
+
"Characterization of an Escherichia coli gene encoding betaine aldehyde dehydrogenase (BADH). Structural similarity to mammalian ALDHs and a plant BADH.",
|
42
|
+
:volume=>"103",
|
43
|
+
:year=>"(1991)"}
|
44
|
+
litdb_ref = @obj.reference
|
45
|
+
actual = {:authors=>litdb_ref.authors,
|
46
|
+
:journal=> litdb_ref.journal,
|
47
|
+
:pages=> litdb_ref.pages,
|
48
|
+
:volume=>litdb_ref.volume,
|
49
|
+
:year=>litdb_ref.year,
|
50
|
+
:issue=>litdb_ref.issue,
|
51
|
+
:title=>litdb_ref.title
|
52
|
+
}
|
53
|
+
assert_equal(expected, actual)
|
54
|
+
end
|
55
|
+
|
56
|
+
#access to the each field with field_fetch method.
|
57
|
+
#most methods are the same as values of Bio::Refence object.
|
58
|
+
def test_entry_id
|
59
|
+
assert_equal("1717226", @obj.entry_id)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_title
|
63
|
+
expected = "Characterization of an Escherichia coli gene encoding betaine aldehyde dehydrogenase (BADH). Structural similarity to mammalian ALDHs and a plant BADH."
|
64
|
+
assert_equal(expected, @obj.title)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_field
|
68
|
+
assert_equal("q (sequence analysis)", @obj.field)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_journal
|
72
|
+
assert_equal("Gene", @obj.journal)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_volume
|
76
|
+
assert_equal("Vol.103, No.1, 45-52 (1991)", @obj.volume)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_keyword
|
80
|
+
expected = ["*Betaine Aldehyde Dehydrogenase",
|
81
|
+
"*betB Gene;E.coli",
|
82
|
+
"Seq Determination;1854bp;491AAs",
|
83
|
+
"Hydropathy Plot;*EC1.2.1.8",
|
84
|
+
"Seq Comparison"]
|
85
|
+
assert_equal(expected, @obj.keyword)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_author
|
89
|
+
expected = "Boyd,L.A.;Adam,L.;Pelcher,L.E.;McHughen,A.;Hirji,R.; Selvaraj,G."
|
90
|
+
assert_equal(expected, @obj.author)
|
91
|
+
end
|
92
|
+
|
93
|
+
end #class TestBioLITDB
|
94
|
+
end #module Bio
|
95
|
+
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#
|
2
|
+
# test/unit/bio/db/test_nbrf.rb - Unit test for Bio::NBRF
|
3
|
+
#
|
4
|
+
# Copyright:: Copyright (C) 2010 Kazuhiro Hayashi <k.hayashi.info@gmail.com>
|
5
|
+
# License:: The Ruby License
|
6
|
+
#
|
7
|
+
|
8
|
+
# loading helper routine for testing bioruby
|
9
|
+
require 'pathname'
|
10
|
+
load Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 3,
|
11
|
+
'bioruby_test_helper.rb')).cleanpath.to_s
|
12
|
+
|
13
|
+
# libraries needed for the tests
|
14
|
+
require 'test/unit'
|
15
|
+
require 'bio/db/nbrf'
|
16
|
+
|
17
|
+
#some condition is not covered with it. This unit test need a nucleotide acid sequence.
|
18
|
+
#I can't find a nucleic acid sequence in PIR format
|
19
|
+
module Bio
|
20
|
+
class TestBioNBRF < Test::Unit::TestCase
|
21
|
+
|
22
|
+
def setup
|
23
|
+
filename = File.join(BioRubyTestDataPath, 'pir', 'CRAB_ANAPL.pir')
|
24
|
+
@obj = Bio::NBRF.new(File.read(filename))
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def test_entry
|
29
|
+
expected = <<END_OF_EXPECTED_ENTRY
|
30
|
+
>P1;CRAB_ANAPL
|
31
|
+
ALPHA CRYSTALLIN B CHAIN (ALPHA(B)-CRYSTALLIN).
|
32
|
+
MDITIHNPLI RRPLFSWLAP SRIFDQIFGE HLQESELLPA SPSLSPFLMR
|
33
|
+
SPIFRMPSWL ETGLSEMRLE KDKFSVNLDV KHFSPEELKV KVLGDMVEIH
|
34
|
+
GKHEERQDEH GFIAREFNRK YRIPADVDPL TITSSLSLDG VLTVSAPRKQ
|
35
|
+
SDVPERSIPI TREEKPAIAG AQRK*
|
36
|
+
END_OF_EXPECTED_ENTRY
|
37
|
+
assert_equal(expected, @obj.entry)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_seq_class
|
41
|
+
assert_equal(Bio::Sequence::AA, @obj.seq_class)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_seq
|
45
|
+
expected = "MDITIHNPLIRRPLFSWLAPSRIFDQIFGEHLQESELLPASPSLSPFLMRSPIFRMPSWLETGLSEMRLEKDKFSVNLDVKHFSPEELKVKVLGDMVEIHGKHEERQDEHGFIAREFNRKYRIPADVDPLTITSSLSLDGVLTVSAPRKQSDVPERSIPITREEKPAIAGAQRK"
|
46
|
+
assert_equal(expected, @obj.seq)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_length
|
50
|
+
assert_equal(174, @obj.length)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_naseq
|
54
|
+
assert_raise(RuntimeError){ @obj.naseq} #@obj is a protein sequence. the method must output error.
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_nalen
|
58
|
+
assert_raise(RuntimeError){ @obj.nalen} #@obj is a protein sequence. the method must output error.
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_aaseq
|
62
|
+
expected = "MDITIHNPLIRRPLFSWLAPSRIFDQIFGEHLQESELLPASPSLSPFLMRSPIFRMPSWLETGLSEMRLEKDKFSVNLDVKHFSPEELKVKVLGDMVEIHGKHEERQDEHGFIAREFNRKYRIPADVDPLTITSSLSLDGVLTVSAPRKQSDVPERSIPITREEKPAIAGAQRK"
|
63
|
+
assert_equal(expected, @obj.aaseq)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_aalen
|
67
|
+
assert_equal(174, @obj.aalen)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_to_nbrf
|
71
|
+
expected =<<EOS
|
72
|
+
>aaa;ABCD
|
73
|
+
this is a fake entry.
|
74
|
+
atgc*
|
75
|
+
EOS
|
76
|
+
nbrf = {:seq_type=>"aaa", :seq=>"atgc", :width=>7, :entry_id=>"ABCD", :definition=>"this is a fake entry."}
|
77
|
+
assert_equal(expected, Bio::NBRF.to_nbrf(nbrf))
|
78
|
+
end
|
79
|
+
|
80
|
+
end #class TestBioNBRF
|
81
|
+
end #module Bio
|
82
|
+
|
@@ -39,9 +39,12 @@ module Bio
|
|
39
39
|
)[0.1250];
|
40
40
|
END_OF_TREE_STRING
|
41
41
|
|
42
|
+
def setup
|
43
|
+
@newick = Bio::Newick.new(TREE_STRING)
|
44
|
+
end
|
45
|
+
|
42
46
|
def test_string_tree
|
43
|
-
|
44
|
-
tree = newick.tree
|
47
|
+
tree = @newick.tree
|
45
48
|
assert_equal(3, tree.children(tree.root).size)
|
46
49
|
assert_equal(9, tree.descendents(tree.root).size)
|
47
50
|
assert_equal(6, tree.leaves.size)
|
@@ -52,6 +55,18 @@ module Bio
|
|
52
55
|
assert_equal("HexFLZ83", leaf.name)
|
53
56
|
end
|
54
57
|
|
58
|
+
def test_reparse
|
59
|
+
tree = @newick.tree
|
60
|
+
assert_equal(@newick, @newick.reparse)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_reparse_before_lazy_parsing
|
64
|
+
# not to use @newick to guarantee that the Newick object
|
65
|
+
# is before lazy parsing.
|
66
|
+
newick = Bio::Newick.new(TREE_STRING)
|
67
|
+
assert_equal(newick, newick.reparse)
|
68
|
+
end
|
69
|
+
|
55
70
|
end #class TestNewick
|
56
71
|
|
57
72
|
class TestNewick2 < Test::Unit::TestCase
|
@@ -72,9 +87,12 @@ module Bio
|
|
72
87
|
)root;
|
73
88
|
END_OF_TREE_STRING
|
74
89
|
|
90
|
+
def setup
|
91
|
+
@newick = Bio::Newick.new(TREE_STRING)
|
92
|
+
end
|
93
|
+
|
75
94
|
def test_string_tree
|
76
|
-
|
77
|
-
tree = newick.tree
|
95
|
+
tree = @newick.tree
|
78
96
|
assert_equal('root', tree.root.name)
|
79
97
|
assert_equal([
|
80
98
|
"this is test",
|
@@ -85,6 +85,11 @@ module Bio
|
|
85
85
|
assert_equal(str, @obj.affiliations)
|
86
86
|
end
|
87
87
|
|
88
|
+
def test_pubmed_url
|
89
|
+
assert_equal("http://www.ncbi.nlm.nih.gov/pubmed/12345678",
|
90
|
+
@obj.pubmed_url)
|
91
|
+
end
|
92
|
+
|
88
93
|
def test_format_general
|
89
94
|
str = 'Hoge, J.P., Fuga, F.B. (2001). "Title of the study." Theor. J. Hoge 12:123-145.'
|
90
95
|
assert_equal(str, @obj.format)
|
@@ -201,6 +206,36 @@ __END__
|
|
201
206
|
|
202
207
|
end
|
203
208
|
|
209
|
+
class TestReference_noURL < Test::Unit::TestCase
|
210
|
+
def setup
|
211
|
+
hash = {
|
212
|
+
'authors' => [ "Hoge, J.P.", "Fuga, F.B." ],
|
213
|
+
'title' => "Title of the study.",
|
214
|
+
'journal' => "Theor. J. Hoge",
|
215
|
+
'volume' => 12,
|
216
|
+
'issue' => 3,
|
217
|
+
'pages' => "123-145",
|
218
|
+
'year' => 2001,
|
219
|
+
'pubmed' => 12345678,
|
220
|
+
'medline' => 98765432,
|
221
|
+
'abstract' => "Hoge fuga. hoge fuga.",
|
222
|
+
'mesh' => ['Hoge'],
|
223
|
+
'affiliations' => ['Tokyo']
|
224
|
+
}
|
225
|
+
@obj = Bio::Reference.new(hash)
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_url
|
229
|
+
assert_equal(nil, @obj.url)
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_format_endnote
|
233
|
+
str = "%0 Journal Article\n%A Hoge, J.P.\n%A Fuga, F.B.\n%D 2001\n%T Title of the study.\n%J Theor. J. Hoge\n%V 12\n%N 3\n%P 123-145\n%M 12345678\n%U http://www.ncbi.nlm.nih.gov/pubmed/12345678\n%X Hoge fuga. hoge fuga.\n%K Hoge\n%+ Tokyo"
|
234
|
+
assert_equal(str, @obj.format('endnote'))
|
235
|
+
assert_equal(str, @obj.endnote)
|
236
|
+
end
|
237
|
+
end #class TestReference_noURL
|
238
|
+
|
204
239
|
class TestReferences < Test::Unit::TestCase
|
205
240
|
|
206
241
|
class NullStderr
|
@@ -0,0 +1,201 @@
|
|
1
|
+
#
|
2
|
+
# test/unit/bio/util/restriction_enzyme/test_dense_int_array.rb - Unit test for Bio::RestrictionEnzyme::DenseIntArray
|
3
|
+
#
|
4
|
+
# Copyright:: Copyright (C) 2011
|
5
|
+
# 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__), ['..'] * 4,
|
12
|
+
'bioruby_test_helper.rb')).cleanpath.to_s
|
13
|
+
|
14
|
+
# libraries needed for the tests
|
15
|
+
require 'test/unit'
|
16
|
+
require 'bio/util/restriction_enzyme'
|
17
|
+
require 'bio/util/restriction_enzyme/dense_int_array'
|
18
|
+
|
19
|
+
module Bio
|
20
|
+
module TestRestrictionEnzyme
|
21
|
+
|
22
|
+
class TestDenseIntArray < Test::Unit::TestCase
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@klass = Bio::RestrictionEnzyme::DenseIntArray
|
26
|
+
@obj = @klass[ -1, 11, 12, 13, 14, 15, 50, 60 ]
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_self_bracket
|
30
|
+
assert_equal([ -1, 11, 12, 13, 14, 15, 50, 60 ], @obj.to_a)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_self_new
|
34
|
+
a = @klass.new
|
35
|
+
assert_instance_of(Bio::RestrictionEnzyme::DenseIntArray, a)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_dup
|
39
|
+
assert_equal(@obj.to_a, @obj.dup.to_a)
|
40
|
+
d_obj = @obj.instance_eval { internal_data }
|
41
|
+
d_dup = @obj.dup.instance_eval { internal_data }
|
42
|
+
assert(d_obj == d_dup)
|
43
|
+
assert_not_equal(d_obj.__id__, d_dup.__id__)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_internal_data
|
47
|
+
d = @obj.instance_eval { internal_data }
|
48
|
+
r = @klass::MutableRange
|
49
|
+
expected = [ r.new(-1, -1), r.new(11, 15),
|
50
|
+
r.new(50, 50), r.new(60, 60) ]
|
51
|
+
assert_equal(expected, d)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_internal_data_eq
|
55
|
+
r = @klass::MutableRange
|
56
|
+
d = [ r.new(-2, -2), r.new(50, 50), r.new(65, 70) ]
|
57
|
+
@obj.instance_eval { self.internal_data = d }
|
58
|
+
assert_equal(70, @obj.last)
|
59
|
+
assert_equal([-2, 50, 65, 66, 67, 68, 69, 70], @obj.to_a)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_bracket
|
63
|
+
assert_equal(-1, @obj[0])
|
64
|
+
assert_equal(13, @obj[3])
|
65
|
+
assert_equal(60, @obj[-1])
|
66
|
+
assert_equal([-1, 11, 12], @obj[0..2])
|
67
|
+
assert_equal([14, 15, 50], @obj[4,3])
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_bracket_eq
|
71
|
+
assert_raise(NotImplementedError) {
|
72
|
+
@obj[3] = 999
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_each
|
77
|
+
expected_values = [ -1, 11, 12, 13, 14, 15, 50, 60 ]
|
78
|
+
@obj.each do |i|
|
79
|
+
assert_equal(expected_values.shift, i)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_reverse_each
|
84
|
+
expected_values = [ -1, 11, 12, 13, 14, 15, 50, 60 ]
|
85
|
+
@obj.reverse_each do |i|
|
86
|
+
assert_equal(expected_values.pop, i)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_plus
|
91
|
+
obj2 = @klass[ 9, 10, 11, 12, 30 ]
|
92
|
+
assert_equal([ -1, 9, 10, 11, 12, 13, 14, 15, 30, 50, 60 ],
|
93
|
+
(@obj + obj2).to_a)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_plus_error
|
97
|
+
assert_raise(TypeError) {
|
98
|
+
@obj + 2
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_eqeq
|
103
|
+
obj2 = @klass[ -1, 11, 12, 13, 14, 15, 50, 60 ]
|
104
|
+
assert_equal(true, @obj == obj2)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_eqeq_self
|
108
|
+
assert_equal(true, @obj == @obj)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_eqeq_false
|
112
|
+
obj2 = @klass[ 2, 3, 14, 15 ]
|
113
|
+
assert_equal(false, @obj == obj2)
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_eqeq_other
|
117
|
+
obj2 = 'test'
|
118
|
+
assert_equal(false, @obj == obj2)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_concat
|
122
|
+
ary = [ 61, 62, -2, 14, 15 ]
|
123
|
+
expected = [ -1, 11, 12, 13, 14, 15, 50, 60, 61, 62, -2, 14, 15 ]
|
124
|
+
# checks if the method returns self
|
125
|
+
assert_equal(@obj, @obj.concat(ary))
|
126
|
+
# checks the value
|
127
|
+
assert_equal(expected, @obj.to_a)
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_push
|
131
|
+
expected = [ -1, 11, 12, 13, 14, 15, 50, 60, 61, 62, -2, 14, 15 ]
|
132
|
+
# checks if the method returns self
|
133
|
+
assert_equal(@obj, @obj.push(61, 62, -2, 14, 15))
|
134
|
+
# checks the value
|
135
|
+
assert_equal(expected, @obj.to_a)
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_unshift
|
139
|
+
assert_raise(NotImplementedError) { @obj.unshift(-5, -2) }
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_ltlt
|
143
|
+
expected = [ -1, 11, 12, 13, 14, 15, 50, 60, 61 ]
|
144
|
+
# checks if the method returns self
|
145
|
+
assert_equal(@obj, @obj << 61)
|
146
|
+
# checks the value
|
147
|
+
assert_equal(expected, @obj.to_a)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_ltlt_larger
|
151
|
+
expected = [ -1, 11, 12, 13, 14, 15, 50, 60, 70 ]
|
152
|
+
# checks if the method returns self
|
153
|
+
assert_equal(@obj, @obj << 70)
|
154
|
+
# checks the value
|
155
|
+
assert_equal(expected, @obj.to_a)
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_ltlt_middle
|
159
|
+
expected = [ -1, 11, 12, 13, 14, 15, 50, 60, 30 ]
|
160
|
+
# checks if the method returns self
|
161
|
+
assert_equal(@obj, @obj << 30)
|
162
|
+
# checks the value
|
163
|
+
assert_equal(expected, @obj.to_a)
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_include?
|
167
|
+
assert_equal(true, @obj.include?(13))
|
168
|
+
assert_equal(false, @obj.include?(999))
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_size
|
172
|
+
assert_equal(8, @obj.size)
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_length
|
176
|
+
assert_equal(8, @obj.length)
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_delete
|
180
|
+
assert_raise(NotImplementedError) { @obj.delete(11) }
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_sort!
|
184
|
+
assert_equal(@obj, @obj.sort!)
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_uniq!
|
188
|
+
assert_equal(@obj, @obj.uniq!)
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_to_a
|
192
|
+
expected = [ -1, 11, 12, 13, 14, 15, 50, 60 ]
|
193
|
+
assert_equal(expected, @obj.to_a)
|
194
|
+
end
|
195
|
+
|
196
|
+
end #class TestDenseIntArray
|
197
|
+
|
198
|
+
end #module TestRestrictionEnzyme
|
199
|
+
end #module Bio
|
200
|
+
|
201
|
+
|