bio 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. data/ChangeLog +3421 -0
  2. data/KNOWN_ISSUES.rdoc +88 -0
  3. data/README.rdoc +252 -0
  4. data/README_DEV.rdoc +285 -0
  5. data/Rakefile +143 -0
  6. data/bin/bioruby +0 -0
  7. data/bin/br_biofetch.rb +0 -0
  8. data/bin/br_bioflat.rb +12 -1
  9. data/bin/br_biogetseq.rb +0 -0
  10. data/bin/br_pmfetch.rb +4 -3
  11. data/bioruby.gemspec +477 -0
  12. data/bioruby.gemspec.erb +117 -0
  13. data/doc/Changes-0.7.rd +7 -0
  14. data/doc/Changes-1.3.rdoc +239 -0
  15. data/doc/Tutorial.rd +296 -184
  16. data/doc/Tutorial.rd.html +1031 -0
  17. data/doc/Tutorial.rd.ja +111 -45
  18. data/doc/Tutorial.rd.ja.html +2225 -0
  19. data/doc/bioruby.css +281 -0
  20. data/extconf.rb +2 -0
  21. data/lib/bio.rb +29 -4
  22. data/lib/bio/appl/blast.rb +306 -121
  23. data/lib/bio/appl/blast/ddbj.rb +142 -0
  24. data/lib/bio/appl/blast/format0.rb +35 -25
  25. data/lib/bio/appl/blast/format8.rb +2 -2
  26. data/lib/bio/appl/blast/genomenet.rb +263 -0
  27. data/lib/bio/appl/blast/ncbioptions.rb +220 -0
  28. data/lib/bio/appl/blast/remote.rb +106 -0
  29. data/lib/bio/appl/blast/report.rb +260 -9
  30. data/lib/bio/appl/blast/rexml.rb +12 -5
  31. data/lib/bio/appl/blast/rpsblast.rb +277 -0
  32. data/lib/bio/appl/blast/wublast.rb +133 -12
  33. data/lib/bio/appl/blast/xmlparser.rb +35 -18
  34. data/lib/bio/appl/blat/report.rb +46 -5
  35. data/lib/bio/appl/emboss.rb +62 -13
  36. data/lib/bio/appl/fasta.rb +9 -11
  37. data/lib/bio/appl/genscan/report.rb +3 -3
  38. data/lib/bio/appl/hmmer.rb +1 -1
  39. data/lib/bio/appl/hmmer/report.rb +10 -10
  40. data/lib/bio/appl/paml/baseml.rb +95 -0
  41. data/lib/bio/appl/paml/baseml/report.rb +32 -0
  42. data/lib/bio/appl/paml/codeml.rb +242 -0
  43. data/lib/bio/appl/paml/codeml/rates.rb +67 -0
  44. data/lib/bio/appl/paml/codeml/report.rb +67 -0
  45. data/lib/bio/appl/paml/common.rb +348 -0
  46. data/lib/bio/appl/paml/common_report.rb +38 -0
  47. data/lib/bio/appl/paml/yn00.rb +103 -0
  48. data/lib/bio/appl/paml/yn00/report.rb +32 -0
  49. data/lib/bio/appl/psort.rb +2 -2
  50. data/lib/bio/appl/pts1.rb +5 -5
  51. data/lib/bio/appl/tmhmm/report.rb +10 -1
  52. data/lib/bio/command.rb +297 -41
  53. data/lib/bio/compat/features.rb +157 -0
  54. data/lib/bio/compat/references.rb +128 -0
  55. data/lib/bio/db/biosql/biosql_to_biosequence.rb +67 -0
  56. data/lib/bio/db/biosql/sequence.rb +508 -0
  57. data/lib/bio/db/embl/common.rb +28 -12
  58. data/lib/bio/db/embl/embl.rb +107 -9
  59. data/lib/bio/db/embl/embl_to_biosequence.rb +85 -0
  60. data/lib/bio/db/embl/format_embl.rb +190 -0
  61. data/lib/bio/db/embl/sptr.rb +15 -16
  62. data/lib/bio/db/fantom.rb +6 -8
  63. data/lib/bio/db/fasta.rb +10 -507
  64. data/lib/bio/db/fasta/defline.rb +532 -0
  65. data/lib/bio/db/fasta/fasta_to_biosequence.rb +63 -0
  66. data/lib/bio/db/fasta/format_fasta.rb +97 -0
  67. data/lib/bio/db/genbank/common.rb +25 -8
  68. data/lib/bio/db/genbank/format_genbank.rb +187 -0
  69. data/lib/bio/db/genbank/genbank.rb +36 -1
  70. data/lib/bio/db/genbank/genbank_to_biosequence.rb +86 -0
  71. data/lib/bio/db/gff.rb +1791 -119
  72. data/lib/bio/db/kegg/glycan.rb +2 -6
  73. data/lib/bio/db/lasergene.rb +3 -3
  74. data/lib/bio/db/medline.rb +4 -1
  75. data/lib/bio/db/newick.rb +10 -10
  76. data/lib/bio/db/pdb/chain.rb +6 -2
  77. data/lib/bio/db/pdb/pdb.rb +12 -3
  78. data/lib/bio/db/rebase.rb +7 -8
  79. data/lib/bio/db/soft.rb +3 -3
  80. data/lib/bio/feature.rb +1 -88
  81. data/lib/bio/io/biosql/biodatabase.rb +64 -0
  82. data/lib/bio/io/biosql/bioentry.rb +29 -0
  83. data/lib/bio/io/biosql/bioentry_dbxref.rb +11 -0
  84. data/lib/bio/io/biosql/bioentry_path.rb +12 -0
  85. data/lib/bio/io/biosql/bioentry_qualifier_value.rb +10 -0
  86. data/lib/bio/io/biosql/bioentry_reference.rb +10 -0
  87. data/lib/bio/io/biosql/bioentry_relationship.rb +10 -0
  88. data/lib/bio/io/biosql/biosequence.rb +11 -0
  89. data/lib/bio/io/biosql/comment.rb +7 -0
  90. data/lib/bio/io/biosql/config/database.yml +20 -0
  91. data/lib/bio/io/biosql/dbxref.rb +13 -0
  92. data/lib/bio/io/biosql/dbxref_qualifier_value.rb +12 -0
  93. data/lib/bio/io/biosql/location.rb +32 -0
  94. data/lib/bio/io/biosql/location_qualifier_value.rb +11 -0
  95. data/lib/bio/io/biosql/ontology.rb +10 -0
  96. data/lib/bio/io/biosql/reference.rb +9 -0
  97. data/lib/bio/io/biosql/seqfeature.rb +32 -0
  98. data/lib/bio/io/biosql/seqfeature_dbxref.rb +11 -0
  99. data/lib/bio/io/biosql/seqfeature_path.rb +11 -0
  100. data/lib/bio/io/biosql/seqfeature_qualifier_value.rb +20 -0
  101. data/lib/bio/io/biosql/seqfeature_relationship.rb +11 -0
  102. data/lib/bio/io/biosql/taxon.rb +12 -0
  103. data/lib/bio/io/biosql/taxon_name.rb +9 -0
  104. data/lib/bio/io/biosql/term.rb +27 -0
  105. data/lib/bio/io/biosql/term_dbxref.rb +11 -0
  106. data/lib/bio/io/biosql/term_path.rb +12 -0
  107. data/lib/bio/io/biosql/term_relationship.rb +13 -0
  108. data/lib/bio/io/biosql/term_relationship_term.rb +11 -0
  109. data/lib/bio/io/biosql/term_synonym.rb +10 -0
  110. data/lib/bio/io/das.rb +7 -7
  111. data/lib/bio/io/ddbjxml.rb +57 -0
  112. data/lib/bio/io/ensembl.rb +2 -2
  113. data/lib/bio/io/fetch.rb +28 -14
  114. data/lib/bio/io/flatfile.rb +17 -853
  115. data/lib/bio/io/flatfile/autodetection.rb +545 -0
  116. data/lib/bio/io/flatfile/buffer.rb +237 -0
  117. data/lib/bio/io/flatfile/index.rb +17 -7
  118. data/lib/bio/io/flatfile/indexer.rb +30 -12
  119. data/lib/bio/io/flatfile/splitter.rb +297 -0
  120. data/lib/bio/io/hinv.rb +442 -0
  121. data/lib/bio/io/keggapi.rb +2 -2
  122. data/lib/bio/io/ncbirest.rb +733 -0
  123. data/lib/bio/io/pubmed.rb +34 -80
  124. data/lib/bio/io/registry.rb +2 -2
  125. data/lib/bio/io/sql.rb +178 -357
  126. data/lib/bio/io/togows.rb +458 -0
  127. data/lib/bio/location.rb +106 -11
  128. data/lib/bio/pathway.rb +120 -14
  129. data/lib/bio/reference.rb +115 -101
  130. data/lib/bio/sequence.rb +164 -183
  131. data/lib/bio/sequence/adapter.rb +108 -0
  132. data/lib/bio/sequence/common.rb +22 -45
  133. data/lib/bio/sequence/compat.rb +2 -2
  134. data/lib/bio/sequence/dblink.rb +54 -0
  135. data/lib/bio/sequence/format.rb +254 -77
  136. data/lib/bio/sequence/format_raw.rb +23 -0
  137. data/lib/bio/shell.rb +3 -1
  138. data/lib/bio/shell/core.rb +2 -2
  139. data/lib/bio/shell/plugin/entry.rb +33 -4
  140. data/lib/bio/shell/plugin/ncbirest.rb +64 -0
  141. data/lib/bio/shell/plugin/togows.rb +40 -0
  142. data/lib/bio/shell/rails/vendor/plugins/{generators → bioruby/generators}/bioruby/bioruby_generator.rb +0 -0
  143. data/lib/bio/shell/rails/vendor/plugins/{generators → bioruby/generators}/bioruby/templates/_classes.rhtml +0 -0
  144. data/lib/bio/shell/rails/vendor/plugins/{generators → bioruby/generators}/bioruby/templates/_log.rhtml +0 -0
  145. data/lib/bio/shell/rails/vendor/plugins/{generators → bioruby/generators}/bioruby/templates/_methods.rhtml +0 -0
  146. data/lib/bio/shell/rails/vendor/plugins/{generators → bioruby/generators}/bioruby/templates/_modules.rhtml +0 -0
  147. data/lib/bio/shell/rails/vendor/plugins/{generators → bioruby/generators}/bioruby/templates/_variables.rhtml +0 -0
  148. data/lib/bio/shell/rails/vendor/plugins/{generators → bioruby/generators}/bioruby/templates/bioruby-bg.gif +0 -0
  149. data/lib/bio/shell/rails/vendor/plugins/{generators → bioruby/generators}/bioruby/templates/bioruby-gem.png +0 -0
  150. data/lib/bio/shell/rails/vendor/plugins/{generators → bioruby/generators}/bioruby/templates/bioruby-link.gif +0 -0
  151. data/lib/bio/shell/rails/vendor/plugins/{generators → bioruby/generators}/bioruby/templates/bioruby.css +0 -0
  152. data/lib/bio/shell/rails/vendor/plugins/{generators → bioruby/generators}/bioruby/templates/bioruby.rhtml +0 -0
  153. data/lib/bio/shell/rails/vendor/plugins/{generators → bioruby/generators}/bioruby/templates/bioruby_controller.rb +0 -0
  154. data/lib/bio/shell/rails/vendor/plugins/{generators → bioruby/generators}/bioruby/templates/bioruby_helper.rb +0 -0
  155. data/lib/bio/shell/rails/vendor/plugins/{generators → bioruby/generators}/bioruby/templates/commands.rhtml +0 -0
  156. data/lib/bio/shell/rails/vendor/plugins/{generators → bioruby/generators}/bioruby/templates/history.rhtml +0 -0
  157. data/lib/bio/shell/rails/vendor/plugins/{generators → bioruby/generators}/bioruby/templates/index.rhtml +0 -0
  158. data/lib/bio/shell/rails/vendor/plugins/{generators → bioruby/generators}/bioruby/templates/spinner.gif +0 -0
  159. data/lib/bio/tree.rb +4 -2
  160. data/lib/bio/util/color_scheme.rb +2 -2
  161. data/lib/bio/util/contingency_table.rb +2 -2
  162. data/lib/bio/util/restriction_enzyme.rb +2 -2
  163. data/lib/bio/util/restriction_enzyme/single_strand.rb +6 -5
  164. data/lib/bio/version.rb +25 -0
  165. data/rdoc.zsh +8 -0
  166. data/sample/any2fasta.rb +0 -0
  167. data/sample/biofetch.rb +0 -0
  168. data/sample/dbget +0 -0
  169. data/sample/demo_sequence.rb +158 -0
  170. data/sample/enzymes.rb +0 -0
  171. data/sample/fasta2tab.rb +0 -0
  172. data/sample/fastagrep.rb +72 -0
  173. data/sample/fastasort.rb +54 -0
  174. data/sample/fsplit.rb +0 -0
  175. data/sample/gb2fasta.rb +2 -3
  176. data/sample/gb2tab.rb +0 -0
  177. data/sample/gbtab2mysql.rb +0 -0
  178. data/sample/genes2nuc.rb +0 -0
  179. data/sample/genes2pep.rb +0 -0
  180. data/sample/genes2tab.rb +0 -0
  181. data/sample/genome2rb.rb +0 -0
  182. data/sample/genome2tab.rb +0 -0
  183. data/sample/goslim.rb +0 -0
  184. data/sample/gt2fasta.rb +0 -0
  185. data/sample/na2aa.rb +34 -0
  186. data/sample/pmfetch.rb +0 -0
  187. data/sample/pmsearch.rb +0 -0
  188. data/sample/ssearch2tab.rb +0 -0
  189. data/sample/tfastx2tab.rb +0 -0
  190. data/sample/vs-genes.rb +0 -0
  191. data/setup.rb +1596 -0
  192. data/test/data/blast/blastp-multi.m7 +188 -0
  193. data/test/data/command/echoarg2.bat +1 -0
  194. data/test/data/paml/codeml/control_file.txt +30 -0
  195. data/test/data/paml/codeml/output.txt +78 -0
  196. data/test/data/paml/codeml/rates +217 -0
  197. data/test/data/rpsblast/misc.rpsblast +193 -0
  198. data/test/data/soft/GDS100_partial.soft +0 -0
  199. data/test/data/soft/GSE3457_family_partial.soft +0 -0
  200. data/test/functional/bio/appl/test_pts1.rb +115 -0
  201. data/test/functional/bio/io/test_ensembl.rb +123 -80
  202. data/test/functional/bio/io/test_togows.rb +267 -0
  203. data/test/functional/bio/sequence/test_output_embl.rb +51 -0
  204. data/test/functional/bio/test_command.rb +301 -0
  205. data/test/runner.rb +17 -1
  206. data/test/unit/bio/appl/blast/test_ncbioptions.rb +112 -0
  207. data/test/unit/bio/appl/blast/test_report.rb +753 -35
  208. data/test/unit/bio/appl/blast/test_rpsblast.rb +398 -0
  209. data/test/unit/bio/appl/paml/codeml/test_rates.rb +45 -0
  210. data/test/unit/bio/appl/paml/codeml/test_report.rb +45 -0
  211. data/test/unit/bio/appl/paml/test_codeml.rb +174 -0
  212. data/test/unit/bio/appl/test_blast.rb +135 -4
  213. data/test/unit/bio/appl/test_fasta.rb +2 -2
  214. data/test/unit/bio/appl/test_pts1.rb +1 -64
  215. data/test/unit/bio/db/embl/test_common.rb +15 -15
  216. data/test/unit/bio/db/embl/test_embl.rb +4 -4
  217. data/test/unit/bio/db/embl/test_embl_rel89.rb +5 -5
  218. data/test/unit/bio/db/embl/test_embl_to_bioseq.rb +203 -0
  219. data/test/unit/bio/db/embl/test_sptr.rb +38 -1
  220. data/test/unit/bio/db/pdb/test_pdb.rb +2 -2
  221. data/test/unit/bio/db/test_gff.rb +1151 -25
  222. data/test/unit/bio/db/test_medline.rb +127 -0
  223. data/test/unit/bio/db/test_nexus.rb +5 -1
  224. data/test/unit/bio/db/test_prosite.rb +4 -4
  225. data/test/unit/bio/io/flatfile/test_autodetection.rb +375 -0
  226. data/test/unit/bio/io/flatfile/test_buffer.rb +251 -0
  227. data/test/unit/bio/io/flatfile/test_splitter.rb +369 -0
  228. data/test/unit/bio/io/test_ddbjxml.rb +8 -3
  229. data/test/unit/bio/io/test_fastacmd.rb +5 -5
  230. data/test/unit/bio/io/test_flatfile.rb +357 -106
  231. data/test/unit/bio/io/test_soapwsdl.rb +2 -2
  232. data/test/unit/bio/io/test_togows.rb +161 -0
  233. data/test/unit/bio/sequence/test_common.rb +210 -11
  234. data/test/unit/bio/sequence/test_compat.rb +3 -3
  235. data/test/unit/bio/sequence/test_dblink.rb +58 -0
  236. data/test/unit/bio/sequence/test_na.rb +2 -2
  237. data/test/unit/bio/test_command.rb +111 -50
  238. data/test/unit/bio/test_feature.rb +29 -1
  239. data/test/unit/bio/test_location.rb +566 -6
  240. data/test/unit/bio/test_pathway.rb +91 -65
  241. data/test/unit/bio/test_reference.rb +67 -13
  242. data/test/unit/bio/util/restriction_enzyme/analysis/test_calculated_cuts.rb +3 -3
  243. data/test/unit/bio/util/restriction_enzyme/analysis/test_cut_ranges.rb +3 -3
  244. data/test/unit/bio/util/restriction_enzyme/analysis/test_sequence_range.rb +3 -3
  245. data/test/unit/bio/util/restriction_enzyme/double_stranded/test_aligned_strands.rb +4 -3
  246. data/test/unit/bio/util/restriction_enzyme/double_stranded/test_cut_location_pair.rb +3 -3
  247. data/test/unit/bio/util/restriction_enzyme/double_stranded/test_cut_location_pair_in_enzyme_notation.rb +3 -3
  248. data/test/unit/bio/util/restriction_enzyme/double_stranded/test_cut_locations.rb +3 -3
  249. data/test/unit/bio/util/restriction_enzyme/double_stranded/test_cut_locations_in_enzyme_notation.rb +3 -3
  250. data/test/unit/bio/util/restriction_enzyme/single_strand/test_cut_locations_in_enzyme_notation.rb +3 -3
  251. data/test/unit/bio/util/restriction_enzyme/test_analysis.rb +3 -3
  252. data/test/unit/bio/util/restriction_enzyme/test_cut_symbol.rb +4 -4
  253. data/test/unit/bio/util/restriction_enzyme/test_double_stranded.rb +3 -3
  254. data/test/unit/bio/util/restriction_enzyme/test_single_strand.rb +3 -3
  255. data/test/unit/bio/util/restriction_enzyme/test_single_strand_complement.rb +3 -3
  256. data/test/unit/bio/util/restriction_enzyme/test_string_formatting.rb +3 -3
  257. data/test/unit/bio/util/test_restriction_enzyme.rb +3 -3
  258. metadata +202 -167
  259. data/test/unit/bio/appl/blast/test_xmlparser.rb +0 -388
@@ -4,7 +4,7 @@
4
4
  # Copyright:: Copyright (C) 2005 Mitsuteru Nakao <n@bioruby.org>
5
5
  # License:: The Ruby License
6
6
  #
7
- # $Id: test_ddbjxml.rb,v 1.4 2007/04/05 23:35:43 trevor Exp $
7
+ # $Id:$
8
8
  #
9
9
 
10
10
  require 'pathname'
@@ -21,8 +21,9 @@ class TestDDBJXMLConstants < Test::Unit::TestCase
21
21
 
22
22
  def test_constants
23
23
  constants = ["DDBJ", "TxSearch", "ClustalW", "PML", "Gib", "Fasta",
24
- "BASE_URI", "SRS", "SERVER_URI", "Gtop", "GetEntry", "Blast"].sort
25
- assert_equal(constants, Bio::DDBJ::XML.constants.sort)
24
+ "BASE_URI", "SRS", "SERVER_URI", "Gtop", "GetEntry",
25
+ "Blast", "RequestManager"].sort
26
+ assert_equal(constants, Bio::DDBJ::XML.constants.sort.collect{|x| x.to_s})
26
27
  end
27
28
 
28
29
  def test_base_url
@@ -69,6 +70,10 @@ class TestDDBJXMLConstants < Test::Unit::TestCase
69
70
  assert_equal("http://xml.nig.ac.jp/wsdl/TxSearch.wsdl", Bio::DDBJ::XML::TxSearch::SERVER_URI)
70
71
  end
71
72
 
73
+ def test_requestmanager_server_url
74
+ assert_equal("http://xml.nig.ac.jp/wsdl/RequestManager.wsdl", Bio::DDBJ::XML::RequestManager::SERVER_URI)
75
+ end
76
+
72
77
  end
73
78
 
74
79
 
@@ -4,7 +4,7 @@
4
4
  # Copyright:: Copyright (C) 2006 Mitsuteru Nakao <n@bioruby.org>
5
5
  # License:: The Ruby License
6
6
  #
7
- # $Id: test_fastacmd.rb,v 1.3 2007/04/05 23:35:43 trevor Exp $
7
+ # $Id:$
8
8
  #
9
9
 
10
10
  require 'pathname'
@@ -20,11 +20,11 @@ module Bio
20
20
  class TestFastacmd < Test::Unit::TestCase
21
21
 
22
22
  def setup
23
- @obj = Bio::Blast::Fastacmd.new("/tmp/test")
23
+ @obj = Bio::Blast::Fastacmd.new('/dev/null')
24
24
  end
25
25
 
26
26
  def test_database
27
- assert_equal("/tmp/test", @obj.database)
27
+ assert_equal('/dev/null', @obj.database)
28
28
  end
29
29
 
30
30
  def test_fastacmd
@@ -32,9 +32,9 @@ class TestFastacmd < Test::Unit::TestCase
32
32
  end
33
33
 
34
34
  def test_methods
35
- method_list = ['get_by_id', 'fetch', 'each_entry', 'each']
35
+ method_list = [ :get_by_id, :fetch, :each_entry, :each ]
36
36
  method_list.each do |method|
37
- assert(@obj.methods.include?(method))
37
+ assert(@obj.respond_to?(method))
38
38
  end
39
39
  end
40
40
 
@@ -9,7 +9,7 @@
9
9
  #
10
10
 
11
11
  require 'pathname'
12
- libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 5, 'lib')).cleanpath.to_s
12
+ libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4, 'lib')).cleanpath.to_s
13
13
  $:.unshift(libpath) unless $:.include?(libpath)
14
14
 
15
15
  require 'test/unit'
@@ -23,159 +23,410 @@ module TestFlatFile
23
23
 
24
24
  bioruby_root = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4)).cleanpath.to_s
25
25
  TestDataPath = Pathname.new(File.join(bioruby_root, 'test', 'data')).cleanpath.to_s
26
- TestDataFastaFormat01 = File.join(TestDataPath, 'fasta', 'example1.txt')
26
+ TestData01 = File.join(TestDataPath, 'fasta', 'example1.txt')
27
+
28
+ TestData01Ent1def =
29
+ "At1g02580 mRNA (2291 bp) UTR's and CDS"
30
+ TestData01Ent4def =
31
+ 'At1g65300: mRNA 837bp (shortened from start)'
32
+ TestData01Ent4naseq = Bio::Sequence::NA.new <<__END_OF_SEQ__
33
+ ttcatctttacctcttcctattgttgcgaatgcagctgcaccagtcg
34
+ gatttgatggtcctatgtttcaatatcataatcaaaatcagcaaaagccggttcaattccaatatcaggctcttta
35
+ tgatttttatgatcagattccaaagaaaattcatggttttaatatgaatatgaataaggattcgaatcaaagtatg
36
+ gttttggatttgaatcaaaatcttaatgatggagaggacgagggcattccttgcatggacaacaacaactaccacc
37
+ ccgaaatcgattgtctcgctaccgtcaccactgcccccactgatgtttgtgctcctaacatcaccaatgatctcta
38
+ g
39
+ __END_OF_SEQ__
40
+
41
+ # test Bio::FlatFile class method
42
+ class TestFlatFileClassMethod < Test::Unit::TestCase
27
43
 
28
- class TestBufferedInputStreamClassMethod < Test::Unit::TestCase
29
- def test_self_for_io
30
- io = File.open(TestDataFastaFormat01)
31
- obj = Bio::FlatFile::BufferedInputStream.for_io(io)
32
- assert_instance_of(Bio::FlatFile::BufferedInputStream, obj)
33
- assert_equal(TestDataFastaFormat01, obj.path)
44
+ def setup
45
+ @filename = TestData01
46
+ @klass = Bio::FastaFormat
47
+ end
48
+
49
+ # test template for Bio::FlatFile.open
50
+ def open_TestData01(*arg)
51
+ assert_instance_of(Bio::FlatFile,
52
+ ff = Bio::FlatFile.open(*arg))
53
+ assert_equal(@klass, ff.dbclass)
54
+ assert_nil(ff.close)
55
+ end
56
+ private :open_TestData01
57
+
58
+ # test template for Bio::FlatFile.open with block
59
+ def open_with_block_TestData01(*arg)
60
+ ret = Bio::FlatFile.open(*arg) do |ff|
61
+ assert_instance_of(Bio::FlatFile, ff)
62
+ assert_equal(@klass, ff.dbclass)
63
+ ff.each do |e|
64
+ assert_instance_of(@klass, e)
65
+ assert_instance_of(String, ff.entry_raw)
66
+ end
67
+ 'test return value'
68
+ end
69
+ assert_equal('test return value', ret)
70
+ end
71
+ private :open_with_block_TestData01
72
+
73
+ def test_open_0arg
74
+ assert_raise(ArgumentError) { Bio::FlatFile.open }
75
+ end
76
+
77
+ def test_open_1arg_nil
78
+ assert_raise(ArgumentError) { Bio::FlatFile.open(nil) }
79
+ end
80
+
81
+ def test_open_1arg_class
82
+ assert_raise(ArgumentError) { Bio::FlatFile.open(Bio::GenBank) }
83
+ end
84
+
85
+ def test_open_1arg_filename
86
+ open_TestData01(@filename)
87
+ end
88
+
89
+ def test_open_1arg_io
90
+ io = File.open(@filename)
91
+ open_TestData01(io)
92
+ assert(io.closed?)
93
+ end
94
+
95
+ def test_open_1arg_with_block
96
+ open_with_block_TestData01(@filename)
97
+ end
98
+
99
+ def test_open_1arg_io_with_block
100
+ io = File.open(@filename)
101
+ open_with_block_TestData01(io)
102
+ # When IO object is given, the IO is NOT automatically closed.
103
+ assert_equal(false, io.closed?)
104
+ assert_nothing_raised { io.close }
105
+ end
106
+
107
+ def test_open_2arg_autodetect
108
+ open_TestData01(nil, @filename)
109
+ end
110
+
111
+ def test_open_2arg_autodetect_with_block
112
+ open_with_block_TestData01(nil, @filename)
113
+ end
114
+
115
+ def test_open_2arg_autodetect_io
116
+ io = File.open(@filename)
117
+ open_TestData01(nil, io)
118
+ assert(io.closed?)
119
+ end
120
+
121
+ def test_open_2arg_autodetect_io_with_block
122
+ io = File.open(@filename)
123
+ open_with_block_TestData01(nil, io)
124
+ # When IO object is given, the IO is NOT automatically closed.
125
+ assert_equal(false, io.closed?)
126
+ assert_nothing_raised { io.close }
127
+ end
128
+
129
+ def test_open_2arg_class
130
+ open_TestData01(@klass, @filename)
131
+ end
132
+
133
+ def test_open_2arg_class_with_block
134
+ open_with_block_TestData01(@klass, @filename)
135
+ end
136
+
137
+ def test_open_2arg_class_io
138
+ io = File.open(@filename)
139
+ open_TestData01(@klass, io)
140
+ assert(io.closed?)
141
+ end
142
+
143
+ def test_open_2arg_class_io_with_block
144
+ io = File.open(@filename)
145
+ open_with_block_TestData01(@klass, io)
146
+ # When IO object is given, the IO is NOT automatically closed.
147
+ assert_equal(false, io.closed?)
148
+ assert_nothing_raised { io.close }
149
+ end
150
+
151
+ def test_open_2arg_filename_mode
152
+ open_TestData01(@filename, 'r')
153
+ end
154
+
155
+ def test_open_2arg_filename_mode_with_block
156
+ open_with_block_TestData01(@filename, 'r')
157
+ end
158
+
159
+ def test_open_3arg
160
+ open_TestData01(nil, @filename, 'r')
161
+ open_TestData01(@klass, @filename, 'r')
162
+ open_TestData01(@filename, File::RDONLY, 0)
163
+ end
164
+
165
+ def test_open_3arg_with_block
166
+ open_with_block_TestData01(nil, @filename, 'r')
167
+ open_with_block_TestData01(@klass, @filename, 'r')
168
+ open_with_block_TestData01(@filename, File::RDONLY, 0)
34
169
  end
35
170
 
36
- def test_self_open_file
37
- obj = Bio::FlatFile::BufferedInputStream.open_file(TestDataFastaFormat01)
38
- assert_instance_of(Bio::FlatFile::BufferedInputStream, obj)
39
- assert_equal(TestDataFastaFormat01, obj.path)
171
+ def test_open_4arg
172
+ open_TestData01(nil, @filename, File::RDONLY, 0)
173
+ open_TestData01(Bio::FastaFormat,
174
+ @filename, File::RDONLY, 0)
175
+
176
+ open_with_block_TestData01(nil, @filename, File::RDONLY, 0)
177
+ open_with_block_TestData01(Bio::FastaFormat,
178
+ @filename, File::RDONLY, 0)
179
+ end
180
+
181
+ # test template for Bio::FlatFile.auto
182
+ def auto_TestData01(*arg)
183
+ assert_instance_of(Bio::FlatFile,
184
+ ff = Bio::FlatFile.auto(*arg))
185
+ assert_equal(@klass, ff.dbclass)
186
+ assert_nil(ff.close)
187
+ end
188
+ private :auto_TestData01
189
+
190
+ # test template for Bio::FlatFile.auto with block
191
+ def auto_with_block_TestData01(*arg)
192
+ ret = Bio::FlatFile.auto(*arg) do |ff|
193
+ assert_instance_of(Bio::FlatFile, ff)
194
+ assert_equal(@klass, ff.dbclass)
195
+ ff.each do |e|
196
+ assert_instance_of(@klass, e)
197
+ assert_instance_of(String, ff.entry_raw)
198
+ end
199
+ 'test return value'
200
+ end
201
+ assert_equal('test return value', ret)
202
+ end
203
+ private :auto_with_block_TestData01
204
+
205
+ def test_auto_0arg
206
+ assert_raise(ArgumentError) { Bio::FlatFile.auto }
207
+ end
208
+
209
+ def test_auto_1arg_filename
210
+ auto_TestData01(@filename)
211
+ end
212
+
213
+ def test_auto_1arg_io
214
+ io = File.open(@filename)
215
+ auto_TestData01(io)
216
+ assert(io.closed?)
217
+ end
218
+
219
+ def test_auto_1arg_with_block
220
+ auto_with_block_TestData01(@filename)
221
+ end
222
+
223
+ def test_auto_1arg_io_with_block
224
+ io = File.open(@filename)
225
+ auto_with_block_TestData01(io)
226
+ # When IO object is given, the IO is NOT automatically closed.
227
+ assert_equal(false, io.closed?)
228
+ assert_nothing_raised { io.close }
229
+ end
230
+
231
+ def test_auto_2arg_filename_mode
232
+ auto_TestData01(@filename, 'r')
233
+ end
234
+
235
+ def test_auto_2arg_filename_mode_with_block
236
+ auto_with_block_TestData01(@filename, 'r')
237
+ end
238
+
239
+ def test_auto_3arg
240
+ auto_TestData01(@filename, File::RDONLY, 0)
40
241
  end
41
242
 
42
- def test_self_open_file_with_block
43
- obj2 = nil
44
- Bio::FlatFile::BufferedInputStream.open_file(TestDataFastaFormat01) do |obj|
45
- assert_instance_of(Bio::FlatFile::BufferedInputStream, obj)
46
- assert_equal(TestDataFastaFormat01, obj.path)
47
- obj2 = obj
243
+ def test_auto_3arg_with_block
244
+ auto_with_block_TestData01(@filename, File::RDONLY, 0)
245
+ end
246
+
247
+ def test_to_a
248
+ assert_instance_of(Array,
249
+ a = Bio::FlatFile.to_a(@filename))
250
+ assert_equal(5, a.size)
251
+ assert_instance_of(Bio::FastaFormat, a[3])
252
+ assert_equal(TestData01Ent4def,
253
+ a[3].definition)
254
+
255
+ assert_equal(TestData01Ent4naseq, a[3].naseq)
256
+ end
257
+
258
+ def test_foreach
259
+ Bio::FlatFile.foreach(@filename) do |ent|
260
+ assert_instance_of(Bio::FastaFormat, ent)
48
261
  end
49
- assert_raise(IOError) { obj2.close }
50
262
  end
51
- end #class TestBufferedInputStreamClassMethod
52
263
 
53
- class TestBufferedInputStream < Test::Unit::TestCase
264
+ def test_new_2arg_nil
265
+ io = File.open(@filename)
266
+ assert_instance_of(Bio::FlatFile,
267
+ ff = Bio::FlatFile.new(nil, io))
268
+ assert_equal(@klass, ff.dbclass)
269
+ assert_nil(ff.close)
270
+ end
271
+
272
+ def test_new_2arg_class
273
+ io = File.open(@filename)
274
+ assert_instance_of(Bio::FlatFile,
275
+ ff = Bio::FlatFile.new(@klass, io))
276
+ assert_equal(@klass, ff.dbclass)
277
+ assert_nil(ff.close)
278
+ end
279
+
280
+ end #class TestFlatFileClassMethod
281
+
282
+ # test Bio::FlatFile instance methods
283
+ class TestFlatFileFastaFormat < Test::Unit::TestCase
54
284
  def setup
55
- io = File.open(TestDataFastaFormat01)
56
- path = TestDataFastaFormat01
57
- @obj = Bio::FlatFile::BufferedInputStream.new(io, path)
285
+ @klass = Bio::FastaFormat
286
+ @filename = TestData01
287
+ @ff = Bio::FlatFile.open(@klass, @filename)
58
288
  end
59
289
 
60
290
  def test_to_io
61
- assert_kind_of(IO, @obj.to_io)
291
+ assert_instance_of(File, @ff.to_io)
62
292
  end
63
293
 
64
- def test_close
65
- assert_nil(@obj.close)
294
+ def test_path
295
+ assert_equal(@filename, @ff.path)
66
296
  end
67
297
 
68
- def test_rewind
69
- @obj.prefetch_gets
70
- @obj.rewind
71
- assert_equal('', @obj.prefetch_buffer)
298
+ def test_next_entry
299
+ assert_instance_of(@klass, ent = @ff.next_entry)
300
+ assert_equal(TestData01Ent1def, ent.definition)
301
+ assert_instance_of(@klass, ent = @ff.next_entry)
302
+ assert_instance_of(@klass, ent = @ff.next_entry)
303
+ assert_instance_of(@klass, ent = @ff.next_entry)
304
+ assert_equal(TestData01Ent4def, ent.definition)
305
+ assert_equal(TestData01Ent4naseq, ent.naseq)
72
306
  end
73
307
 
74
- def test_pos
75
- @obj.gets
76
- @obj.gets
77
- @obj.prefetch_gets
78
- assert_equal(117, @obj.pos) #the number depends on original data
308
+ def test_entry_raw
309
+ 4.times { @ff.next_entry }
310
+ assert_instance_of(String, str = @ff.entry_raw)
311
+ assert_equal(TestData01Ent4def, @klass.new(str).definition)
312
+ assert_equal(TestData01Ent4naseq, @klass.new(str).naseq)
79
313
  end
80
314
 
81
- def test_pos=()
82
- str = @obj.gets
83
- assert_equal(0, @obj.pos = 0)
315
+ def test_entry_pos_flag
316
+ # default is nil
317
+ assert_equal(nil, @ff.entry_pos_flag)
318
+ # set as true
319
+ assert_equal(true, @ff.entry_pos_flag = true)
320
+ assert_equal(true, @ff.entry_pos_flag)
84
321
  end
85
-
86
- def test_eof_false_first
87
- assert_equal(false, @obj.eof?)
322
+
323
+ def test_start_pos_ended_pos_not_recorded
324
+ # default is nil
325
+ assert_equal(nil, @ff.entry_start_pos)
326
+ #
327
+ @ff.entry_pos_flag = false
328
+ @ff.next_entry
329
+ # nil if not recorded
330
+ assert_equal(nil, @ff.entry_start_pos)
331
+ assert_equal(nil, @ff.entry_ended_pos)
332
+ @ff.next_entry
333
+ # nil if not recorded
334
+ assert_equal(nil, @ff.entry_start_pos)
335
+ assert_equal(nil, @ff.entry_ended_pos)
88
336
  end
89
337
 
90
- def test_eof_false_after_prefetch
91
- while @obj.prefetch_gets; nil; end
92
- assert_equal(false, @obj.eof?)
338
+ def test_start_pos
339
+ @ff.entry_pos_flag = true
340
+ @ff.next_entry
341
+ assert_equal(0, @ff.entry_start_pos)
342
+ @ff.next_entry
343
+ # On Windows, the values might be different.
344
+ assert_equal(2367, @ff.entry_start_pos)
93
345
  end
94
346
 
95
- def test_eof_true
96
- while @obj.gets; nil; end
97
- assert_equal(true, @obj.eof?)
347
+ def test_ended_pos
348
+ @ff.entry_pos_flag = true
349
+ @ff.next_entry
350
+ # On Windows, the values might be different.
351
+ assert_equal(2367, @ff.entry_ended_pos)
352
+ @ff.next_entry
353
+ # On Windows, the values might be different.
354
+ assert_equal(3244, @ff.entry_ended_pos)
98
355
  end
99
356
 
100
- def test_gets
101
- @obj.gets
102
- @obj.gets
103
- assert_equal("gagcaaatcgaaaaggagagatttctgcatatcaagagaaaattcgagctgagatacattccaagtgtggctactc", @obj.gets.chomp)
357
+ def test_each_entry
358
+ i = 0
359
+ @ff.each_entry do |ent|
360
+ assert_instance_of(@klass, ent)
361
+ i += 1
362
+ if i == 4 then
363
+ assert_equal(TestData01Ent4def, ent.definition)
364
+ assert_equal(TestData01Ent4naseq, ent.naseq)
365
+ end
366
+ end
104
367
  end
105
368
 
106
- def test_gets_equal_prefetch_gets
107
- @obj.prefetch_gets
108
- str = @obj.prefetch_gets
109
- @obj.prefetch_gets
110
- @obj.gets
111
- assert_equal(@obj.gets, str)
369
+ # each is an alias of each_entry
370
+ def test_each
371
+ assert_nothing_raised { @ff.each {} }
112
372
  end
113
373
 
114
- def test_ungets
115
- @obj.gets
116
- @obj.gets
117
- str1 = @obj.gets
118
- str2 = @obj.gets
119
- assert_nil(@obj.ungets(str2))
120
- assert_nil(@obj.ungets(str1))
121
- assert_equal(str1, @obj.gets)
122
- assert_equal(str2, @obj.gets)
374
+ def test_rewind
375
+ @ff.next_entry
376
+ assert_not_equal(0, @ff.pos)
377
+ assert_equal(0, @ff.rewind)
378
+ assert_equal(0, @ff.pos)
123
379
  end
124
380
 
125
- def test_getc
126
- assert_equal(?>, @obj.getc)
381
+ def test_close
382
+ assert_nil(@ff.close)
127
383
  end
128
384
 
129
- def test_getc_after_prefetch
130
- @obj.prefetch_gets
131
- assert_equal(?>, @obj.getc)
385
+ def test_pos
386
+ assert_equal(0, @ff.pos)
387
+ @ff.next_entry
388
+ assert_not_equal(0, @ff.pos)
132
389
  end
133
390
 
134
- def test_ungetc
135
- c = @obj.getc
136
- assert_nil(@obj.ungetc(c))
137
- assert_equal(c, @obj.getc)
391
+ def test_eof?
392
+ 5.times { @ff.next_entry }
393
+ assert_equal(true, @ff.eof?)
138
394
  end
139
395
 
140
- def test_ungetc_after_prefetch
141
- str = @obj.prefetch_gets
142
- c = @obj.getc
143
- assert_nil(@obj.ungetc(c))
144
- assert_equal(str, @obj.gets)
396
+ def test_raw
397
+ # default false
398
+ assert_equal(false, @ff.raw)
399
+ # changes to true
400
+ assert_equal(true, @ff.raw = true)
401
+ @ff.each do |ent|
402
+ assert_instance_of(String, ent)
403
+ end
145
404
  end
146
405
 
147
- def test_prefetch_buffer
148
- str = @obj.prefetch_gets
149
- str += @obj.prefetch_gets
150
- assert_equal(str, @obj.prefetch_buffer)
406
+ def test_dbclass
407
+ assert_equal(@klass, @ff.dbclass)
151
408
  end
152
409
 
153
- def test_prefetch_gets
154
- @obj.prefetch_gets
155
- @obj.prefetch_gets
156
- @obj.gets
157
- str = @obj.prefetch_gets
158
- @obj.gets
159
- assert_equal(str, @obj.gets)
410
+ def test_dbclass_eq
411
+ klass = Bio::FastaNumericFormat
412
+ assert_equal(klass, @ff.dbclass = klass)
413
+ assert_equal(klass, @ff.dbclass)
160
414
  end
161
415
 
162
- def test_prefetch_gets_with_arg
163
- # test @obj.gets
164
- str = @obj.prefetch_gets("\n>")
165
- assert_equal(str, @obj.gets("\n>"))
166
- # test using IO object
167
- io = @obj.to_io
168
- io.rewind
169
- assert_equal(str, io.gets("\n>"))
416
+ def test_dbclass_nil
417
+ assert_equal(nil, @ff.dbclass = nil)
418
+ assert_equal(nil, @ff.dbclass)
419
+ assert_raise(Bio::FlatFile::UnknownDataFormatError) { @ff.next_entry }
170
420
  end
171
421
 
172
- def test_skip_spaces
173
- @obj.gets('CDS')
174
- assert_nil(@obj.skip_spaces)
175
- assert_equal(?a, @obj.getc)
422
+ def test_autodetect
423
+ @ff.dbclass = nil
424
+ assert_equal(@klass, @ff.autodetect)
425
+ assert_equal(@klass, @ff.dbclass)
176
426
  end
177
-
178
- end #class TestBufferedInputStream
427
+
428
+ end #class TestFlatFileFastaFormat
429
+
179
430
 
180
431
  class TestFlatFileWithCustomClass < Test::Unit::TestCase
181
432