bio 1.4.2 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. data/.travis.yml +66 -0
  2. data/ChangeLog +989 -4524
  3. data/KNOWN_ISSUES.rdoc +67 -2
  4. data/README.rdoc +89 -23
  5. data/README_DEV.rdoc +93 -2
  6. data/RELEASE_NOTES.rdoc +167 -95
  7. data/Rakefile +199 -7
  8. data/bioruby.gemspec +27 -12
  9. data/bioruby.gemspec.erb +6 -3
  10. data/doc/ChangeLog-before-1.4.2 +5013 -0
  11. data/doc/RELEASE_NOTES-1.4.2.rdoc +132 -0
  12. data/doc/Tutorial.rd +21 -3
  13. data/doc/Tutorial.rd.html +20 -12
  14. data/etc/bioinformatics/seqdatabase.ini +13 -196
  15. data/gemfiles/Gemfile.travis-jruby1.8 +7 -0
  16. data/gemfiles/Gemfile.travis-jruby1.9 +10 -0
  17. data/gemfiles/Gemfile.travis-ruby1.8 +7 -0
  18. data/gemfiles/Gemfile.travis-ruby1.9 +10 -0
  19. data/gemfiles/modify-Gemfile.rb +28 -0
  20. data/gemfiles/prepare-gemspec.rb +25 -0
  21. data/lib/bio/alignment.rb +1 -1
  22. data/lib/bio/appl/bl2seq/report.rb +3 -3
  23. data/lib/bio/appl/blast/ddbj.rb +0 -3
  24. data/lib/bio/appl/blast/format0.rb +4 -22
  25. data/lib/bio/appl/blast/genomenet.rb +33 -16
  26. data/lib/bio/appl/blast/ncbioptions.rb +8 -3
  27. data/lib/bio/appl/blast/remote.rb +6 -5
  28. data/lib/bio/appl/blast/report.rb +10 -6
  29. data/lib/bio/appl/blast/rpsblast.rb +3 -2
  30. data/lib/bio/appl/blast/wublast.rb +3 -3
  31. data/lib/bio/command.rb +118 -36
  32. data/lib/bio/data/na.rb +1 -1
  33. data/lib/bio/db/embl/embl.rb +74 -0
  34. data/lib/bio/db/embl/format_embl.rb +0 -4
  35. data/lib/bio/db/fasta.rb +57 -45
  36. data/lib/bio/db/fasta/defline.rb +1 -1
  37. data/lib/bio/db/fasta/format_fasta.rb +0 -4
  38. data/lib/bio/db/fasta/format_qual.rb +0 -5
  39. data/lib/bio/db/fastq/format_fastq.rb +0 -1
  40. data/lib/bio/db/genbank/format_genbank.rb +0 -4
  41. data/lib/bio/db/gff.rb +41 -12
  42. data/lib/bio/db/kegg/genes.rb +3 -3
  43. data/lib/bio/db/kegg/kgml.rb +465 -64
  44. data/lib/bio/db/newick.rb +0 -244
  45. data/lib/bio/db/pdb.rb +1 -4
  46. data/lib/bio/db/pdb/atom.rb +3 -2
  47. data/lib/bio/db/pdb/chain.rb +2 -3
  48. data/lib/bio/db/pdb/chemicalcomponent.rb +3 -2
  49. data/lib/bio/db/pdb/model.rb +2 -2
  50. data/lib/bio/db/pdb/pdb.rb +2 -1
  51. data/lib/bio/db/pdb/residue.rb +2 -2
  52. data/lib/bio/db/pdb/utils.rb +7 -4
  53. data/lib/bio/db/phyloxml/phyloxml_parser.rb +52 -5
  54. data/lib/bio/feature.rb +2 -3
  55. data/lib/bio/io/flatfile/autodetection.rb +1 -1
  56. data/lib/bio/io/flatfile/buffer.rb +84 -0
  57. data/lib/bio/sequence.rb +6 -4
  58. data/lib/bio/sequence/aa.rb +3 -5
  59. data/lib/bio/sequence/adapter.rb +6 -6
  60. data/lib/bio/sequence/common.rb +3 -3
  61. data/lib/bio/sequence/compat.rb +2 -7
  62. data/lib/bio/sequence/dblink.rb +6 -5
  63. data/lib/bio/sequence/format.rb +0 -6
  64. data/lib/bio/sequence/format_raw.rb +0 -4
  65. data/lib/bio/sequence/generic.rb +3 -4
  66. data/lib/bio/sequence/na.rb +4 -6
  67. data/lib/bio/sequence/quality_score.rb +2 -0
  68. data/lib/bio/sequence/sequence_masker.rb +3 -0
  69. data/lib/bio/shell/core.rb +1 -0
  70. data/lib/bio/tree.rb +1 -2
  71. data/lib/bio/tree/output.rb +264 -0
  72. data/lib/bio/util/restriction_enzyme.rb +1 -3
  73. data/lib/bio/util/restriction_enzyme/analysis.rb +8 -5
  74. data/lib/bio/util/restriction_enzyme/analysis_basic.rb +4 -3
  75. data/lib/bio/util/restriction_enzyme/cut_symbol.rb +3 -2
  76. data/lib/bio/util/restriction_enzyme/dense_int_array.rb +3 -0
  77. data/lib/bio/util/restriction_enzyme/double_stranded.rb +3 -4
  78. data/lib/bio/util/restriction_enzyme/double_stranded/aligned_strands.rb +3 -4
  79. data/lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair.rb +3 -4
  80. data/lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair_in_enzyme_notation.rb +3 -4
  81. data/lib/bio/util/restriction_enzyme/double_stranded/cut_locations.rb +3 -4
  82. data/lib/bio/util/restriction_enzyme/double_stranded/cut_locations_in_enzyme_notation.rb +3 -4
  83. data/lib/bio/util/restriction_enzyme/range/cut_range.rb +3 -4
  84. data/lib/bio/util/restriction_enzyme/range/cut_ranges.rb +3 -4
  85. data/lib/bio/util/restriction_enzyme/range/horizontal_cut_range.rb +3 -4
  86. data/lib/bio/util/restriction_enzyme/range/sequence_range.rb +3 -4
  87. data/lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb +3 -4
  88. data/lib/bio/util/restriction_enzyme/range/sequence_range/fragment.rb +3 -4
  89. data/lib/bio/util/restriction_enzyme/range/sequence_range/fragments.rb +3 -4
  90. data/lib/bio/util/restriction_enzyme/range/vertical_cut_range.rb +3 -4
  91. data/lib/bio/util/restriction_enzyme/single_strand.rb +3 -3
  92. data/lib/bio/util/restriction_enzyme/single_strand/cut_locations_in_enzyme_notation.rb +3 -4
  93. data/lib/bio/util/restriction_enzyme/single_strand_complement.rb +3 -4
  94. data/lib/bio/util/restriction_enzyme/sorted_num_array.rb +3 -0
  95. data/lib/bio/util/restriction_enzyme/string_formatting.rb +3 -4
  96. data/lib/bio/version.rb +11 -2
  97. data/sample/seqdatabase.ini +210 -0
  98. data/test/bioruby_test_helper.rb +37 -12
  99. data/test/data/KEGG/test.kgml +37 -0
  100. data/test/data/command/echoarg2.bat +0 -0
  101. data/test/data/command/echoarg2.sh +4 -0
  102. data/test/functional/bio/test_command.rb +58 -28
  103. data/test/{functional → network}/bio/appl/blast/test_remote.rb +0 -0
  104. data/test/{functional → network}/bio/appl/test_blast.rb +0 -0
  105. data/test/{functional → network}/bio/appl/test_pts1.rb +0 -0
  106. data/test/{functional → network}/bio/io/test_ddbjrest.rb +0 -0
  107. data/test/{functional → network}/bio/io/test_ensembl.rb +0 -0
  108. data/test/{functional → network}/bio/io/test_pubmed.rb +0 -0
  109. data/test/{functional → network}/bio/io/test_soapwsdl.rb +0 -0
  110. data/test/{functional → network}/bio/io/test_togows.rb +0 -0
  111. data/test/network/bio/test_command.rb +35 -0
  112. data/test/runner.rb +16 -6
  113. data/test/unit/bio/appl/blast/test_report.rb +119 -0
  114. data/test/unit/bio/appl/blast/test_rpsblast.rb +1 -0
  115. data/test/unit/bio/data/test_na.rb +1 -1
  116. data/test/unit/bio/db/embl/test_embl.rb +2 -7
  117. data/test/unit/bio/db/embl/test_embl_rel89.rb +2 -7
  118. data/test/unit/bio/db/fasta/test_defline.rb +1 -1
  119. data/test/unit/bio/db/genbank/test_genpept.rb +1 -1
  120. data/test/unit/bio/db/kegg/test_drug.rb +1 -1
  121. data/test/unit/bio/db/kegg/test_genome.rb +1 -1
  122. data/test/unit/bio/db/kegg/test_glycan.rb +1 -1
  123. data/test/unit/bio/db/kegg/test_kgml.rb +1022 -0
  124. data/test/unit/bio/db/sanger_chromatogram/test_abif.rb +2 -1
  125. data/test/unit/bio/db/sanger_chromatogram/test_scf.rb +4 -2
  126. data/test/unit/bio/db/test_newick.rb +2 -0
  127. data/test/unit/bio/db/test_phyloxml.rb +54 -2
  128. data/test/unit/bio/db/test_phyloxml_writer.rb +15 -9
  129. data/test/unit/bio/db/test_soft.rb +1 -1
  130. data/test/unit/bio/io/flatfile/test_autodetection.rb +6 -0
  131. data/test/unit/bio/io/flatfile/test_buffer.rb +141 -0
  132. data/test/unit/bio/sequence/test_common.rb +36 -4
  133. data/test/unit/bio/sequence/test_na.rb +1 -1
  134. data/test/unit/bio/test_command.rb +9 -4
  135. data/test/unit/bio/test_sequence.rb +2 -2
  136. data/test/unit/bio/test_tree.rb +11 -11
  137. data/test/unit/bio/util/test_restriction_enzyme.rb +1 -1
  138. metadata +1428 -655
  139. data/rdoc.zsh +0 -8
@@ -21,7 +21,8 @@ module Bio
21
21
  DataPath = Pathname.new(File.join(BioRubyTestDataPath,
22
22
  'sanger_chromatogram')).cleanpath.to_s
23
23
  def self.abif
24
- File.read(File.join(DataPath, 'test_chromatogram_abif.ab1'))
24
+ fn = File.join(DataPath, 'test_chromatogram_abif.ab1')
25
+ File.open(fn, 'rb') { |f| f.read }
25
26
  end
26
27
  end #module TestAbifData
27
28
 
@@ -20,10 +20,12 @@ module Bio
20
20
  DataPath = Pathname.new(File.join(BioRubyTestDataPath,
21
21
  'sanger_chromatogram')).cleanpath.to_s
22
22
  def self.scf_version_2
23
- File.read(File.join(DataPath, 'test_chromatogram_scf_v2.scf'))
23
+ fn = File.join(DataPath, 'test_chromatogram_scf_v2.scf')
24
+ File.open(fn, "rb") { |f| f.read }
24
25
  end
25
26
  def self.scf_version_3
26
- File.read(File.join(DataPath, 'test_chromatogram_scf_v3.scf'))
27
+ fn = File.join(DataPath, 'test_chromatogram_scf_v3.scf')
28
+ File.open(fn, "rb") { |f| f.read }
27
29
  end
28
30
  end #module TestScfData
29
31
 
@@ -57,7 +57,9 @@ module Bio
57
57
 
58
58
  def test_reparse
59
59
  tree = @newick.tree
60
+ tree_text = tree.output(:newick)
60
61
  assert_equal(@newick, @newick.reparse)
62
+ assert_equal(tree_text, @newick.tree.output(:newick))
61
63
  end
62
64
 
63
65
  def test_reparse_before_lazy_parsing
@@ -83,6 +83,20 @@ end #end module TestPhyloXMLData
83
83
  assert_instance_of(Bio::PhyloXML::Parser,
84
84
  phyloxml = Bio::PhyloXML::Parser.open(filename))
85
85
  common_test_next_tree(phyloxml)
86
+ phyloxml.close
87
+ end
88
+
89
+ def test_open_with_block
90
+ filename = TestPhyloXMLData.example_xml
91
+ phyloxml_bak = nil
92
+ ret = Bio::PhyloXML::Parser.open(filename) do |phyloxml|
93
+ assert_instance_of(Bio::PhyloXML::Parser, phyloxml)
94
+ common_test_next_tree(phyloxml)
95
+ phyloxml_bak = phyloxml
96
+ "ok"
97
+ end
98
+ assert_equal("ok", ret)
99
+ assert_equal(true, phyloxml_bak.closed?)
86
100
  end
87
101
 
88
102
  def test_new
@@ -192,8 +206,8 @@ end #end module TestPhyloXMLData
192
206
 
193
207
 
194
208
  class TestPhyloXML_close < Test::Unit::TestCase
195
- def phyloxml_open
196
- Bio::PhyloXML::Parser.open(TestPhyloXMLData.example_xml)
209
+ def phyloxml_open(&block)
210
+ Bio::PhyloXML::Parser.open(TestPhyloXMLData.example_xml, &block)
197
211
  end
198
212
  private :phyloxml_open
199
213
 
@@ -203,6 +217,25 @@ end #end module TestPhyloXMLData
203
217
  assert_nil(phyloxml.close)
204
218
  end
205
219
 
220
+ def test_closed?
221
+ phyloxml = phyloxml_open
222
+ assert_equal(false, phyloxml.closed?)
223
+ phyloxml.next_tree
224
+ assert_equal(false, phyloxml.closed?)
225
+ phyloxml.close
226
+ assert_equal(true, phyloxml.closed?)
227
+ end
228
+
229
+ def test_closed_with_block
230
+ ret = phyloxml_open do |phyloxml|
231
+ assert_equal(false, phyloxml.closed?)
232
+ phyloxml.next_tree
233
+ assert_equal(false, phyloxml.closed?)
234
+ phyloxml
235
+ end
236
+ assert_equal(true, ret.closed?)
237
+ end
238
+
206
239
  def test_close_after_close
207
240
  phyloxml = phyloxml_open
208
241
  phyloxml.close
@@ -215,6 +248,25 @@ end #end module TestPhyloXMLData
215
248
  assert_raise(LibXML::XML::Error) { phyloxml.next_tree }
216
249
  end
217
250
 
251
+ def test_next_tree_after_open_with_block
252
+ phyloxml = phyloxml_open { |arg| arg }
253
+ assert_raise(LibXML::XML::Error) { phyloxml.next_tree }
254
+ end
255
+
256
+ def test_close_after_open_with_block
257
+ phyloxml = phyloxml_open { |arg| arg }
258
+ assert_raise(LibXML::XML::Error) { phyloxml.close }
259
+ end
260
+
261
+ def test_close_in_open_with_block
262
+ phyloxml = phyloxml_open do |arg|
263
+ ret = arg
264
+ assert_nil(arg.close)
265
+ ret
266
+ end
267
+ assert_raise(LibXML::XML::Error) { phyloxml.close }
268
+ end
269
+
218
270
  def test_close_does_not_affect_io
219
271
  io = File.open(TestPhyloXMLData.example_xml)
220
272
  phyloxml = Bio::PhyloXML::Parser.for_io(io)
@@ -116,12 +116,12 @@ module Bio
116
116
  filename = @writeto.file("test2.xml")
117
117
  writer = Bio::PhyloXML::Writer.new(filename)
118
118
 
119
- tree = Bio::PhyloXML::Parser.open(TestPhyloXMLWriterData.mollusca_short_xml).next_tree
119
+ tree = Bio::PhyloXML::Parser.open(TestPhyloXMLWriterData.mollusca_short_xml) { |px| px.next_tree }
120
120
 
121
121
  writer.write(tree)
122
122
 
123
123
  assert_nothing_thrown do
124
- Bio::PhyloXML::Parser.open(filename)
124
+ Bio::PhyloXML::Parser.open(filename) { |px| true }
125
125
  end
126
126
 
127
127
  #File.delete(filename)
@@ -145,7 +145,7 @@ module Bio
145
145
  tree.add_edge(root_node, node2)
146
146
  writer.write(tree)
147
147
 
148
- lines = File.open(filename).readlines()
148
+ lines = File.readlines(filename)
149
149
  assert_equal("<phyloxml xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.phyloxml.org http://www.phyloxml.org/1.10/phyloxml.xsd\" xmlns=\"http://www.phyloxml.org\">",
150
150
  lines[1].chomp)
151
151
  assert_equal(" <phylogeny rooted=\"true\">", lines[2].chomp)
@@ -164,7 +164,7 @@ module Bio
164
164
  end
165
165
 
166
166
  def test_phyloxml_examples_tree1
167
- tree = Bio::PhyloXML::Parser.open(TestPhyloXMLWriterData.example_xml).next_tree
167
+ tree = Bio::PhyloXML::Parser.open(TestPhyloXMLWriterData.example_xml) { |px| px.next_tree }
168
168
 
169
169
  filename = @writeto.file('example_tree1.xml')
170
170
  writer = Bio::PhyloXML::Writer.new(filename)
@@ -172,7 +172,7 @@ module Bio
172
172
  writer.write(tree)
173
173
 
174
174
  assert_nothing_thrown do
175
- tree2 = Bio::PhyloXML::Parser.open(filename)
175
+ tree2 = Bio::PhyloXML::Parser.open(filename) { |px| true }
176
176
  end
177
177
 
178
178
  #File.delete(filename)
@@ -185,13 +185,14 @@ module Bio
185
185
  2.times do
186
186
  @tree = phyloxml.next_tree
187
187
  end
188
+ phyloxml.close
188
189
 
189
190
  filename = @writeto.file('example_tree2.xml')
190
191
  writer = Bio::PhyloXML::Writer.new(filename)
191
192
  writer.write(@tree)
192
193
 
193
194
  assert_nothing_thrown do
194
- tree2 = Bio::PhyloXML::Parser.open(filename)
195
+ tree2 = Bio::PhyloXML::Parser.open(filename) { |px| true }
195
196
  end
196
197
 
197
198
  #File.delete(filename)
@@ -202,12 +203,13 @@ module Bio
202
203
  4.times do
203
204
  @tree = phyloxml.next_tree
204
205
  end
206
+ phyloxml.close
205
207
  #@todo tree = phyloxml[4]
206
208
  filename = @writeto.file('example_tree4.xml')
207
209
  writer = Bio::PhyloXML::Writer.new(filename)
208
210
  writer.write(@tree)
209
211
  assert_nothing_thrown do
210
- @tree2 = Bio::PhyloXML::Parser.open(filename).next_tree
212
+ @tree2 = Bio::PhyloXML::Parser.open(filename) { |px| px.next_tree }
211
213
  end
212
214
  assert_equal(@tree.name, @tree2.name)
213
215
  assert_equal(@tree.get_node_by_name('A').taxonomies[0].scientific_name, @tree2.get_node_by_name('A').taxonomies[0].scientific_name)
@@ -224,6 +226,7 @@ module Bio
224
226
  phyloxml.each do |tree|
225
227
  writer.write(tree)
226
228
  end
229
+ phyloxml.close
227
230
 
228
231
  assert_nothing_thrown do
229
232
  @phyloxml_test = Bio::PhyloXML::Parser.open(filename)
@@ -233,6 +236,8 @@ module Bio
233
236
  @tree = @phyloxml_test.next_tree
234
237
  end
235
238
 
239
+ @phyloxml_test.close
240
+
236
241
  assert_equal("x", @tree.sequence_relations[0].id_ref_0)
237
242
  assert_equal("z", @tree.sequence_relations[1].id_ref_1)
238
243
  assert_equal(nil, @tree.sequence_relations[2].distance)
@@ -285,7 +290,7 @@ module Bio
285
290
  Bio::PhyloXML::Writer.new(filename).write(tree)
286
291
 
287
292
  assert_nothing_thrown do
288
- Bio::PhyloXML::Parser.open(filename).next_tree
293
+ Bio::PhyloXML::Parser.open(filename) { |px| px.next_tree }
289
294
  end
290
295
 
291
296
  #File.delete(filename)
@@ -302,7 +307,7 @@ module Bio
302
307
  writer.write_other(phyloxml.other)
303
308
 
304
309
  assert_nothing_thrown do
305
- Bio::PhyloXML::Parser.open(filename)
310
+ Bio::PhyloXML::Parser.open(filename) { |px| true }
306
311
  end
307
312
  # The output file is not deleted since it might be used in the phyloxml
308
313
  # parser test. But since the order of tests can't be assumed, I can't
@@ -319,6 +324,7 @@ module Bio
319
324
  phyloxml.each do |tree|
320
325
  writer.write(tree)
321
326
  end
327
+ phyloxml.close
322
328
  end
323
329
 
324
330
  end
@@ -90,7 +90,7 @@ module Bio #:nodoc:
90
90
  assert_equal( @obj_dataset.database[:institute], 'NCBI NLM NIH')
91
91
 
92
92
  assert_equal( @obj_dataset.subsets.size, 8)
93
- assert_equal( @obj_dataset.subsets.keys, ["GDS100_1",
93
+ assert_equal( @obj_dataset.subsets.keys.sort, ["GDS100_1",
94
94
  "GDS100_2",
95
95
  "GDS100_3",
96
96
  "GDS100_4",
@@ -347,6 +347,12 @@ __END_OF_TEXT__
347
347
  # def test_sim4
348
348
  # end
349
349
 
350
+ def test_fastq
351
+ fn = File.join(TestDataPath, 'fastq', 'longreads_original_sanger.fastq')
352
+ text = File.read(fn, length=300)
353
+ assert_equal(Bio::Fastq, @ad.autodetect(text))
354
+ end
355
+
350
356
  def test_fastaformat
351
357
  fn = File.join(TestDataPath, 'fasta', 'example1.txt')
352
358
  text = File.read(fn)
@@ -23,6 +23,145 @@ module Bio::TestFlatFileBufferedInputStream
23
23
  TestDataPath = BioRubyTestDataPath
24
24
  TestDataFastaFormat01 = File.join(TestDataPath, 'fasta', 'example1.txt')
25
25
 
26
+ class TestBufferedInputStreamParseFileOpenArg < Test::Unit::TestCase
27
+
28
+ K = Bio::FlatFile::BufferedInputStream
29
+
30
+ def _parse_file_open_mode(mode)
31
+ K.module_eval { _parse_file_open_mode(mode) }
32
+ end
33
+ private :_parse_file_open_mode
34
+
35
+ def _parse_file_open_arg(*arg)
36
+ K.module_eval { _parse_file_open_arg(*arg) }
37
+ end
38
+ private :_parse_file_open_arg
39
+
40
+ def test_parse_file_open_mode_nil
41
+ assert_equal(nil, _parse_file_open_mode(nil))
42
+ end
43
+
44
+ def test_parse_file_open_mode_integer
45
+ assert_equal({ :fmode_integer => 127 },
46
+ _parse_file_open_mode(127))
47
+ end
48
+
49
+ def test_parse_file_open_mode_str
50
+ assert_equal({ :fmode_string => "r+b" },
51
+ _parse_file_open_mode("r+b"))
52
+ end
53
+
54
+ def test_parse_file_open_mode_str_with_ext_enc
55
+ assert_equal({ :fmode_string => "r+t",
56
+ :external_encoding => "UTF-8" },
57
+ _parse_file_open_mode("r+t:UTF-8"))
58
+ end
59
+
60
+ def test_parse_file_open_mode_str_with_enc
61
+ assert_equal({ :fmode_string => "rb",
62
+ :external_encoding => "EUC-JP",
63
+ :internal_encoding => "UTF-8" },
64
+ _parse_file_open_mode("rb:EUC-JP:UTF-8"))
65
+ end
66
+
67
+ def test_parse_file_open_arg_nil
68
+ assert_equal({}, _parse_file_open_arg(nil))
69
+ end
70
+
71
+ def test_parse_file_open_arg_integer
72
+ assert_equal({ :fmode_integer => 127 },
73
+ _parse_file_open_arg(127))
74
+ end
75
+
76
+ def test_parse_file_open_arg_str
77
+ assert_equal({ :fmode_string => "r+b" },
78
+ _parse_file_open_arg("r+b"))
79
+ end
80
+
81
+ def test_parse_file_open_arg_str_with_ext_enc
82
+ assert_equal({ :fmode_string => "r+t",
83
+ :external_encoding => "UTF-8" },
84
+ _parse_file_open_arg("r+t:UTF-8"))
85
+ end
86
+
87
+ def test_parse_file_open_arg_str_with_enc
88
+ assert_equal({ :fmode_string => "rb",
89
+ :external_encoding => "EUC-JP",
90
+ :internal_encoding => "UTF-8" },
91
+ _parse_file_open_arg("rb:EUC-JP:UTF-8"))
92
+ end
93
+
94
+ def test_parse_file_open_arg_str_perm
95
+ assert_equal({ :fmode_string => "r+b",
96
+ :perm => 0644 },
97
+ _parse_file_open_arg("r+b", 0644))
98
+ end
99
+
100
+ def test_parse_file_open_arg_int_perm
101
+ assert_equal({ :fmode_integer => 255,
102
+ :perm => 0755 },
103
+ _parse_file_open_arg(255, 0755))
104
+ end
105
+
106
+ def test_parse_file_open_arg_int_perm_opt
107
+ assert_equal({ :fmode_integer => 191,
108
+ :perm => 0600,
109
+ :textmode => true,
110
+ :internal_encoding => "EUC-JP" },
111
+ _parse_file_open_arg(191, 0600,
112
+ :textmode => true,
113
+ :internal_encoding => "EUC-JP"))
114
+ end
115
+
116
+ def test_parse_file_open_arg_int_opt
117
+ assert_equal({ :fmode_integer => 191,
118
+ :textmode => true,
119
+ :internal_encoding => "EUC-JP" },
120
+ _parse_file_open_arg(191,
121
+ :textmode => true,
122
+ :internal_encoding => "EUC-JP"))
123
+ end
124
+
125
+ def test_parse_file_open_arg_str_perm_opt
126
+ assert_equal({ :fmode_string => "a",
127
+ :perm => 0644,
128
+ :binmode => true,
129
+ :external_encoding => "UTF-8" },
130
+ _parse_file_open_arg("a", 0644,
131
+ :binmode => true,
132
+ :external_encoding => "UTF-8"))
133
+ end
134
+
135
+ def test_parse_file_open_arg_str_opt
136
+ assert_equal({ :fmode_string => "a",
137
+ :binmode => true,
138
+ :external_encoding => "UTF-8" },
139
+ _parse_file_open_arg("a",
140
+ :binmode => true,
141
+ :external_encoding => "UTF-8"))
142
+ end
143
+
144
+ def test_parse_file_open_arg_opt
145
+ assert_equal({ :fmode_string => "r",
146
+ :binmode => true,
147
+ :external_encoding => "UTF-8" },
148
+ _parse_file_open_arg(:mode => "r",
149
+ :binmode => true,
150
+ :external_encoding => "UTF-8"))
151
+ end
152
+
153
+ def test_parse_file_open_arg_opt_with_integer_mode
154
+ assert_equal({ :fmode_integer => 123,
155
+ :perm => 0600,
156
+ :textmode => true,
157
+ :external_encoding => "EUC-JP" },
158
+ _parse_file_open_arg(:mode => 123,
159
+ :perm => 0600,
160
+ :textmode => true,
161
+ :external_encoding => "EUC-JP"))
162
+ end
163
+ end #class TestBufferedInputStreamParseFileOpenArg
164
+
26
165
  class TestBufferedInputStreamClassMethod < Test::Unit::TestCase
27
166
 
28
167
  def test_self_for_io
@@ -52,6 +191,7 @@ module Bio::TestFlatFileBufferedInputStream
52
191
  class TestBufferedInputStream < Test::Unit::TestCase
53
192
  def setup
54
193
  io = File.open(TestDataFastaFormat01)
194
+ io.binmode
55
195
  path = TestDataFastaFormat01
56
196
  @obj = Bio::FlatFile::BufferedInputStream.new(io, path)
57
197
  end
@@ -80,6 +220,7 @@ module Bio::TestFlatFileBufferedInputStream
80
220
  def test_pos=()
81
221
  str = @obj.gets
82
222
  assert_equal(0, @obj.pos = 0)
223
+ assert_equal(str, @obj.gets)
83
224
  end
84
225
 
85
226
  def test_eof_false_first
@@ -239,6 +239,10 @@ module Bio; module TestSequenceCommon
239
239
  assert(rseqs[1] != rseqs[2])
240
240
  end
241
241
 
242
+ end #class TestSequenceCommonRandomize
243
+
244
+ class TestSequenceCommonRandomizeChi2 < Test::Unit::TestCase
245
+
242
246
  def chi2(hist, f, k)
243
247
  chi2 = 0
244
248
  (0...k).each do |i|
@@ -250,7 +254,7 @@ module Bio; module TestSequenceCommon
250
254
 
251
255
  # chi-square test for distribution of chi2 values from
252
256
  # distribution of index('a')
253
- def randomize_equiprobability
257
+ def randomize_equiprobability_chi2
254
258
  # Reference: http://www.geocities.jp/m_hiroi/light/pystat04.html
255
259
  seq = TSequence.new('ccccgggtta') # length must be 10
256
260
  k = 10
@@ -280,10 +284,38 @@ module Bio; module TestSequenceCommon
280
284
  chi2_chi2 = chi2(chi2_hist, chi2_f, k)
281
285
  #$stderr.puts chi2_chi2
282
286
 
287
+ chi2_chi2
288
+ end
289
+ private :randomize_equiprobability_chi2
290
+
291
+ def randomize_equiprobability(&block)
283
292
  ## chi-square test, freedom 9, significance level 5%
284
- #assert_operator(16.919, :>, chi2_chi2, "test of chi2 < 16.919 failed (#{chi2_chi2})")
293
+ #critical_value = 16.919
294
+ #significance_level_message = "5%"
295
+ #
285
296
  # chi-square test, freedom 9, significance level 1%
286
- assert_operator(21.666, :>, chi2_chi2, "test of chi2 < 21.666 failed (#{chi2_chi2})")
297
+ critical_value = 21.666
298
+ significance_level_message = "1%"
299
+
300
+ # max trial times till the test sucess
301
+ max_trial = 10
302
+
303
+ values =[]
304
+ max_trial.times do |i|
305
+ chi2_chi2 = randomize_equiprobability_chi2(&block)
306
+ values.push chi2_chi2
307
+ # immediately breaks if the test succeeds
308
+ break if chi2_chi2 < critical_value
309
+ $stderr.print "Bio::Sequence::Common#randomize test of chi2 (=#{chi2_chi2}) < #{critical_value} failed (expected #{significance_level_message} by chance)"
310
+ if values.size < max_trial then
311
+ $stderr.puts ", retrying."
312
+ else
313
+ $stderr.puts " #{values.size} consecutive times!"
314
+ end
315
+ end
316
+
317
+ assert_operator(values[-1], :<, critical_value,
318
+ "test of chi2 < #{critical_value} failed #{values.size} times consecutively (#{values.inspect})")
287
319
  end
288
320
  private :randomize_equiprobability
289
321
 
@@ -319,7 +351,7 @@ module Bio; module TestSequenceCommon
319
351
  # end
320
352
  #end
321
353
 
322
- end
354
+ end #class TestSequenceCommonRandomizeChi2
323
355
 
324
356
 
325
357
  class TestSequenceCommonSubseq < Test::Unit::TestCase