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
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gem "rake"
4
+
5
+ ## disabled because of build error on Travis
6
+ #gem "libxml-ruby"
7
+
@@ -0,0 +1,10 @@
1
+ source :rubygems
2
+
3
+ gem "rake"
4
+
5
+ ## disabled because of build error on Travis
6
+ #gem "libxml-ruby"
7
+
8
+ ## disabled because of "uninitialized constant XML::SaxParser" error
9
+ #gem "soap4r-ruby1.9"
10
+
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gem "rake"
4
+
5
+ gem "xmlparser"
6
+ gem "libxml-ruby"
7
+
@@ -0,0 +1,10 @@
1
+ source :rubygems
2
+
3
+ gem "rake"
4
+
5
+ gem "xmlparser"
6
+ gem "libxml-ruby"
7
+
8
+ ## disabled because of "uninitialized constant XML::SaxParser" error
9
+ #gem "soap4r-ruby1.9"
10
+
@@ -0,0 +1,28 @@
1
+ #
2
+
3
+ require 'pathname'
4
+
5
+ envname_default_task = 'BIORUBY_RAKE_DEFAULT_TASK'
6
+
7
+ gem_dir = Pathname.new(File.join(File.dirname(__FILE__), '..')).realpath
8
+
9
+ case t = ENV[envname_default_task]
10
+ when 'gem-test'
11
+ # do nothing
12
+ else
13
+ $stderr.print "#{$0}: skipped: ENV[#{envname_default_task}]=#{t.inspect}\n"
14
+ exit(0)
15
+ end
16
+
17
+ target = ENV['BUNDLE_GEMFILE']
18
+ unless target then
19
+ $stderr.puts("Error: env BUNDLE_GEMFILE is not set.")
20
+ end
21
+
22
+ File.open(target, 'a') do |w|
23
+ $stderr.puts "Add a line to #{target}"
24
+ $stderr.puts "gem 'bio', :path => '#{gem_dir}'"
25
+ w.puts ""
26
+ w.puts "gem 'bio', :path => '#{gem_dir}'"
27
+ end
28
+
@@ -0,0 +1,25 @@
1
+ #
2
+
3
+ require 'pathname'
4
+ require 'fileutils'
5
+
6
+ envname_default_task = 'BIORUBY_RAKE_DEFAULT_TASK'
7
+
8
+ gem_dir = Pathname.new(File.join(File.dirname(__FILE__), '..')).realpath
9
+
10
+ case t = ENV[envname_default_task]
11
+ when 'gem-test'
12
+ # do nothing
13
+ else
14
+ $stderr.print "#{$0}: skipped: ENV[#{envname_default_task}]=#{t.inspect}\n"
15
+ exit(0)
16
+ end
17
+
18
+ $stderr.puts "cd #{gem_dir}"
19
+ Dir.chdir(gem_dir)
20
+
21
+ args = [ 'bioruby.gemspec', '.gemspec' ]
22
+
23
+ $stderr.puts(['cp', *args].join(" "))
24
+ FileUtils.cp(*args)
25
+
@@ -2319,7 +2319,7 @@ module Bio
2319
2319
 
2320
2320
  # prepare temporary file
2321
2321
  def _prepare_tempfile(str = nil)
2322
- tf_in = Tempfile.open(str ? 'alignment_i' :'alignment_o')
2322
+ tf_in = Tempfile.open(str ? 'alignment_i' : 'alignment_o')
2323
2323
  tf_in.print str if str
2324
2324
  tf_in.close(false)
2325
2325
  tf_in
@@ -4,7 +4,6 @@
4
4
  # Copyright:: Copyright (C) 2005 Naohisa Goto <ng@bioruby.org>
5
5
  # License:: The Ruby License
6
6
  #
7
- # $Id:$
8
7
  #
9
8
  # Bio::Blast::Bl2seq::Report is a NCBI bl2seq (BLAST 2 sequences) output parser.
10
9
  #
@@ -15,9 +14,10 @@
15
14
  # lib/bio/appl/blast/format0.rb.
16
15
  #
17
16
 
18
- require 'bio/appl/blast/format0'
19
-
20
17
  module Bio
18
+
19
+ require 'bio/appl/blast' unless const_defined?(:Blast)
20
+
21
21
  class Blast
22
22
 
23
23
  class Bl2seq
@@ -4,10 +4,7 @@
4
4
  # Copyright:: Copyright (C) 2008 Naohisa Goto <ng@bioruby.org>
5
5
  # License:: The Ruby License
6
6
  #
7
- # $Id:$
8
- #
9
7
 
10
- require 'bio/appl/blast/remote'
11
8
  require 'bio/io/ddbjrest'
12
9
 
13
10
  module Bio::Blast::Remote
@@ -4,8 +4,6 @@
4
4
  # Copyright:: Copyright (C) 2003-2006 GOTO Naohisa <ng@bioruby.org>
5
5
  # License:: The Ruby License
6
6
  #
7
- # $Id:$
8
- #
9
7
  # == Description
10
8
  #
11
9
  # NCBI BLAST default (-m 0 option) output parser.
@@ -19,18 +17,15 @@
19
17
  # * http://www.ncbi.nlm.nih.gov/blast/
20
18
  #
21
19
 
22
- begin
23
- require 'strscan'
24
- rescue LoadError
25
- end
20
+ require 'strscan'
26
21
  require 'singleton'
27
22
 
28
- #--
29
- #require 'bio/db'
30
- #++
31
23
  require 'bio/io/flatfile'
32
24
 
33
25
  module Bio
26
+
27
+ require 'bio/appl/blast' unless const_defined?(:Blast)
28
+
34
29
  class Blast
35
30
  module Default #:nodoc:
36
31
 
@@ -73,19 +68,6 @@ module Bio
73
68
  # Returns whole entry as a string.
74
69
  def to_s; @entry; end
75
70
 
76
- #:stopdoc:
77
- # prevent using StringScanner_R (in old version of strscan)
78
- if !defined?(StringScanner) then
79
- def initialize(*arg)
80
- raise 'couldn\'t load strscan.so'
81
- end #def
82
- elsif StringScanner.name == 'StringScanner_R' then
83
- def initialize(*arg)
84
- raise 'cannot use StringScanner_R'
85
- end #def
86
- end
87
- #:startdoc:
88
-
89
71
  # Defines attributes which delegate to @f0dbstat objects.
90
72
  def self.delegate_to_f0dbstat(*names)
91
73
  names.each do |x|
@@ -7,14 +7,12 @@
7
7
  # Copyright:: Copyright (C) 2008 Naohisa Goto <ng@bioruby.org>
8
8
  # License:: The Ruby License
9
9
  #
10
- # $Id:$
11
10
  #
12
11
 
13
12
  require 'net/http'
14
13
  require 'uri'
15
14
  require 'bio/command'
16
15
  require 'shellwords'
17
- require 'bio/appl/blast/remote'
18
16
 
19
17
  module Bio::Blast::Remote
20
18
 
@@ -58,6 +56,11 @@ module Bio::Blast::Remote
58
56
  # tblastn | AA | genes-nt, genome, vgenes.nuc
59
57
  # ----------+-------+---------------------------------------------------
60
58
  #
59
+ # === BLAST options
60
+ #
61
+ # Options are basically the same as those of the blastall command
62
+ # in NCBI BLAST. See http://www.genome.jp/tools-bin/show_man?blast2
63
+ #
61
64
  # == See also
62
65
  #
63
66
  # * Bio::Blast
@@ -158,7 +161,8 @@ module Bio::Blast::Remote
158
161
  host = Host
159
162
  #host = "blast.genome.jp"
160
163
  #path = "/sit-bin/nph-blast"
161
- path = "/sit-bin/blast" #2005.08.12
164
+ #path = "/sit-bin/blast" #2005.08.12
165
+ path = "/tools-bin/blast" #2012.01.12
162
166
 
163
167
  options = make_command_line_options
164
168
  opt = Bio::Blast::NCBIOptions.new(options)
@@ -221,9 +225,9 @@ module Bio::Blast::Remote
221
225
  @output = result.body
222
226
  # waiting for BLAST finished
223
227
  while /Your job ID is/ =~ @output and
224
- /Your result will be displayed here\<br\>/ =~ @output
225
- if /This page will be reloaded automatically in\s*((\d+)\s*min\.)?\s*(\d+)\s*sec\./ =~ @output then
226
- reloadtime = $2.to_i * 60 + $3.to_i
228
+ /Your result will be displayed here\.?\<br\>/i =~ @output
229
+ if /This page will be reloaded automatically in\s*((\d+)\s*min\.)?\s*((\d+)\s*sec\.)?/ =~ @output then
230
+ reloadtime = $2.to_i * 60 + $4.to_i
227
231
  reloadtime = 300 if reloadtime > 300
228
232
  reloadtime = 1 if reloadtime < 1
229
233
  else
@@ -238,14 +242,23 @@ module Bio::Blast::Remote
238
242
  end
239
243
  end
240
244
 
241
- # workaround 2005.08.12 + 2011.01.27
242
- if /\<A +HREF=\"(http\:\/\/[\-\.a-z0-9]+\.genome\.jp(\/tmp\/[^\"]+))\"\>Show all result\<\/A\>/i =~ @output.to_s then
243
- @output = Bio::Command.read_uri($1)
244
- txt = @output.to_s.split(/\<pre\>/)[1]
245
- raise 'cannot understand response' unless txt
246
- txt.sub!(/\<\/pre\>.*\z/m, '')
247
- txt.sub!(/.*^ \-{20,}\s*/m, '')
248
- @output = txt.gsub(/\&lt\;/, '<')
245
+ # workaround 2005.08.12 + 2011.01.27 + 2011.7.22
246
+ if /\<A +HREF=\"(http\:\/\/[\-\.a-z0-9]+\.genome\.jp)?(\/tmp\/[^\"]+)\"\>Show all result\<\/A\>/i =~ @output.to_s then
247
+ all_prefix = $1
248
+ all_path = $2
249
+ all_prefix = "http://#{Host}" if all_prefix.to_s.empty?
250
+ all_uri = all_prefix + all_path
251
+ @output = Bio::Command.read_uri(all_uri)
252
+ case all_path
253
+ when /\.txt\z/
254
+ ; # don't touch the data
255
+ else
256
+ txt = @output.to_s.split(/\<pre\>/)[1]
257
+ raise 'cannot understand response' unless txt
258
+ txt.sub!(/\<\/pre\>.*\z/m, '')
259
+ txt.sub!(/.*^ \-{20,}\s*/m, '')
260
+ @output = txt
261
+ end
249
262
  else
250
263
  raise 'cannot understand response'
251
264
  end
@@ -254,10 +267,14 @@ module Bio::Blast::Remote
254
267
  # for -m 0 (NCBI BLAST default) output, html tags are removed.
255
268
  if opt_m.to_i == 0 then
256
269
  #@output_bak = @output
257
- txt = @output.gsub(/^\s*\<img +src\=\"\/Fig\/arrow\_top\.gif\"\>.+$\r?\n/, '')
270
+ txt = @output.sub!(/^\<select .*/, '')
271
+ #txt.gsub!(/^\s*\<img +src\=\"\/Fig\/arrow\_top\.gif\"\>.+$\r?\n/, '')
258
272
  txt.gsub!(/^.+\<\/form\>$/, '')
259
- txt.gsub!(/^\<form *method\=\"POST\" name\=\"clust\_check\"\>.+$\r?\n/, '')
273
+ #txt.gsub!(/^\<form *method\=\"POST\" name\=\"clust\_check\"\>.+$\r?\n/, '')
274
+ txt.gsub!(/\<a href\=\"\/tmp[^\"]\>\&uarr\;\&nbsp\;Top\<\/a\>/, '')
260
275
  txt.gsub!(/\<[^\>\<]+\>/m, '')
276
+ txt.gsub!(/\&gt\;/, '>')
277
+ txt.gsub!(/\&lt\;/, '<')
261
278
  @output = txt
262
279
  end
263
280
 
@@ -13,10 +13,13 @@
13
13
  # It is internally used in Bio::Blast and some other classes.
14
14
  #
15
15
 
16
- require 'bio/appl/blast'
17
16
  require 'shellwords'
18
17
 
19
- class Bio::Blast
18
+ module Bio
19
+
20
+ require 'bio/appl/blast' unless const_defined?(:Blast)
21
+
22
+ class Blast
20
23
 
21
24
  # A class to parse and store NCBI-tools style command-line options.
22
25
  # It is internally used in Bio::Blast and some other classes.
@@ -217,4 +220,6 @@ class Bio::Blast
217
220
 
218
221
  end #class NCBIOptions
219
222
 
220
- end #class Bio::Blast
223
+ end #class Blast
224
+
225
+ end #module Bio
@@ -4,12 +4,12 @@
4
4
  # Copyright:: Copyright (C) 2008 Naohisa Goto <ng@bioruby.org>
5
5
  # License:: The Ruby License
6
6
  #
7
- # $Id:$
8
- #
9
7
 
10
- require 'bio/appl/blast'
8
+ module Bio
9
+
10
+ require 'bio/appl/blast' unless const_defined?(:Blast)
11
11
 
12
- class Bio::Blast
12
+ class Blast
13
13
 
14
14
  # Bio::Blast::Remote is a namespace for Remote Blast factory.
15
15
  module Remote
@@ -102,5 +102,6 @@ class Bio::Blast
102
102
 
103
103
  end #module Remote
104
104
 
105
- end #class Bio::Blast
105
+ end #class Blast
106
106
 
107
+ end #module Bio
@@ -4,16 +4,13 @@
4
4
  # Copyright:: Copyright (C) 2003 Toshiaki Katayama <k@bioruby.org>
5
5
  # License:: The Ruby License
6
6
  #
7
- # $Id:$
8
- #
9
7
 
10
- require 'bio/appl/blast'
11
- require 'bio/appl/blast/xmlparser'
12
- require 'bio/appl/blast/rexml'
13
- require 'bio/appl/blast/format8'
14
8
  require 'bio/io/flatfile'
15
9
 
16
10
  module Bio
11
+
12
+ require 'bio/appl/blast' unless const_defined?(:Blast)
13
+
17
14
  class Blast
18
15
 
19
16
  # = Bio::Blast::Report
@@ -43,6 +40,13 @@ class Blast
43
40
  #
44
41
  class Report
45
42
 
43
+ #--
44
+ # require lines moved here to avoid circular require
45
+ #++
46
+ require 'bio/appl/blast/xmlparser'
47
+ require 'bio/appl/blast/rexml'
48
+ require 'bio/appl/blast/format8'
49
+
46
50
  # for Bio::FlatFile support (only for XML data)
47
51
  DELIMITER = RS = "</BlastOutput>\n"
48
52
 
@@ -4,7 +4,6 @@
4
4
  # Copyright:: Copyright (C) 2008 Naohisa Goto <ng@bioruby.org>
5
5
  # License:: The Ruby License
6
6
  #
7
- # $Id:$
8
7
  #
9
8
  # == Description
10
9
  #
@@ -22,10 +21,12 @@
22
21
  # * http://www.ncbi.nlm.nih.gov/Structure/cdd/cdd_help.shtml
23
22
  #
24
23
 
25
- require 'bio/appl/blast/format0'
26
24
  require 'bio/io/flatfile'
27
25
 
28
26
  module Bio
27
+
28
+ require 'bio/appl/blast' unless const_defined?(:Blast)
29
+
29
30
  class Blast
30
31
 
31
32
  # NCBI RPS Blast (Reversed Position Specific Blast) namespace.
@@ -4,7 +4,6 @@
4
4
  # Copyright:: Copyright (C) 2003, 2008 Naohisa GOTO <ng@bioruby.org>
5
5
  # License:: The Ruby License
6
6
  #
7
- # $Id:$
8
7
  #
9
8
  # == Description
10
9
  #
@@ -21,9 +20,10 @@
21
20
  # * http://www.ebi.ac.uk/blast2/
22
21
  #
23
22
 
24
- require 'bio/appl/blast/format0'
25
-
26
23
  module Bio
24
+
25
+ require 'bio/appl/blast' unless const_defined?(:Blast)
26
+
27
27
  class Blast
28
28
  module WU #:nodoc:
29
29
 
@@ -232,19 +232,37 @@ module Command
232
232
  # * (required) _cmd_: Array containing String objects
233
233
  # * (optional) _options_: Hash
234
234
  # *Returns*:: (undefined)
235
- def call_command_popen(cmd, options = {})
235
+ def call_command_popen(cmd, options = {}, &block)
236
236
  if RUBY_VERSION >= "1.9.0" then
237
- # For Ruby 1.9 or later, using command line array with options.
238
- dir = options[:chdir]
239
- cmd = safe_command_line_array(cmd)
240
- if dir then
241
- cmd = cmd + [ { :chdir => dir } ]
242
- end
243
- r = IO.popen(cmd, "r+") do |io|
244
- yield io
237
+ if RUBY_ENGINE == 'jruby' then
238
+ _call_command_popen_jruby19(cmd, options, &block)
239
+ else
240
+ _call_command_popen_ruby19(cmd, options, &block)
245
241
  end
246
- return r
242
+ else
243
+ _call_command_popen_ruby18(cmd, options, &block)
247
244
  end
245
+ end
246
+
247
+ # This method is internally called from the call_command method.
248
+ # In normal case, use call_command, and do not call this method directly.
249
+ #
250
+ # Executes the program via IO.popen.
251
+ # A block must be given. An IO object is passed to the block.
252
+ #
253
+ # See the document of call_command for available options.
254
+ #
255
+ # The method is written for Ruby 1.8.
256
+ #
257
+ # In Ruby 1.8, although shell unsafe characters are escaped,
258
+ # if inescapable characters exists, it raises RuntimeError.
259
+ #
260
+ # ---
261
+ # *Arguments*:
262
+ # * (required) _cmd_: Array containing String objects
263
+ # * (optional) _options_: Hash
264
+ # *Returns*:: (undefined)
265
+ def _call_command_popen_ruby18(cmd, options = {})
248
266
  # For Ruby 1.8, using command line string.
249
267
  str = make_command_line(cmd)
250
268
  # processing options
@@ -267,6 +285,66 @@ module Command
267
285
  yield io
268
286
  end
269
287
  end
288
+ private :_call_command_popen_ruby18
289
+
290
+ # This method is internally called from the call_command method.
291
+ # In normal case, use call_command, and do not call this method directly.
292
+ #
293
+ # Executes the program via IO.popen.
294
+ # A block must be given. An IO object is passed to the block.
295
+ #
296
+ # See the document of call_command for available options.
297
+ #
298
+ # The method can be run only on Ruby (MRI) 1.9 or later versions.
299
+ #
300
+ # ---
301
+ # *Arguments*:
302
+ # * (required) _cmd_: Array containing String objects
303
+ # * (optional) _options_: Hash
304
+ # *Returns*:: (undefined)
305
+ def _call_command_popen_ruby19(cmd, options = {})
306
+ # For Ruby 1.9 or later, using command line array with options.
307
+ dir = options[:chdir]
308
+ cmd = safe_command_line_array(cmd)
309
+ if dir then
310
+ cmd = cmd + [ { :chdir => dir } ]
311
+ end
312
+ r = IO.popen(cmd, "r+") do |io|
313
+ yield io
314
+ end
315
+ return r
316
+ end
317
+ private :_call_command_popen_ruby19
318
+
319
+ # This method is internally called from the call_command method.
320
+ # In normal case, use call_command, and do not call this method directly.
321
+ #
322
+ # Executes the program via IO.popen.
323
+ # A block must be given. An IO object is passed to the block.
324
+ #
325
+ # See the document of call_command for available options.
326
+ #
327
+ # The method is written for the workaround of the JRuby bugs:
328
+ # * {JRUBY-6195}[http://jira.codehaus.org/browse/JRUBY-6195] Process.spawn
329
+ # (and related methods) ignore option hash
330
+ # * {JRUBY-6818}[http://jira.codehaus.org/browse/JRUBY-6818] Kernel.exec,
331
+ # Process.spawn (and IO.popen etc.) raise error when program is an array
332
+ # containing two strings
333
+ # This method may be removed after the bugs are resolved.
334
+ #
335
+ # ---
336
+ # *Arguments*:
337
+ # * (required) _cmd_: Array containing String objects
338
+ # * (optional) _options_: Hash
339
+ # *Returns*:: (undefined)
340
+ def _call_command_popen_jruby19(cmd, options = {}, &block)
341
+ if !options.empty? or cmd.size == 1 then
342
+ _call_command_popen_ruby18(cmd, options, &block)
343
+ else
344
+ _call_command_popen_ruby19(cmd, options, &block)
345
+ end
346
+ end
347
+ private :_call_command_popen_jruby19
270
348
 
271
349
  # This method is internally called from the call_command method.
272
350
  # In normal case, use call_command, and do not call this method directly.
@@ -547,33 +625,37 @@ module Command
547
625
  # BioRuby library internal use only.
548
626
  class Tmpdir
549
627
 
550
- # Returns finalizer object for Tmpdir class.
551
- # Internal use only. Users should not call this method directly.
552
- #
553
- # Acknowledgement: The essense of the code is taken from tempfile.rb
554
- # in Ruby 1.8.7.
628
+ # Internal use only. Users should not use this class directly.
555
629
  #
556
- # ---
557
- # *Arguments*:
558
- # * (required) _data_: Array containing internal data
559
- # *Returns*:: Proc object
560
- def self.callback(data)
561
- pid = $$
562
- lambda {
563
- path, = *data
564
- if pid == $$
565
- $stderr.print "removing ", path, " ..." if $DEBUG
566
- if path and !path.empty? and
567
- File.directory?(path) and
568
- !File.symlink?(path) then
569
- Bio::Command.remove_entry_secure(path)
570
- $stderr.print "done\n" if $DEBUG
571
- else
572
- $stderr.print "skipped\n" if $DEBUG
573
- end
630
+ # Bio::Command::Tmpdir::Remover is a class to remove temporary
631
+ # directory.
632
+ #
633
+ # Acknowledgement: The essense of the code is taken from tempfile.rb
634
+ # in Ruby trunk (svn 34413) and in Ruby 1.8.7.
635
+ class Remover
636
+ # Internal use only. Users should not call this method.
637
+ def initialize(data)
638
+ @pid = $$
639
+ @data = data
640
+ end
641
+
642
+ # Internal use only. Users should not call this method.
643
+ def call(*args)
644
+ return if @pid != $$
645
+
646
+ path, = *@data
647
+
648
+ STDERR.print "removing ", path, "..." if $DEBUG
649
+ if path and !path.empty? and
650
+ File.directory?(path) and
651
+ !File.symlink?(path) then
652
+ Bio::Command.remove_entry_secure(path)
653
+ $stderr.print "done\n" if $DEBUG
654
+ else
655
+ $stderr.print "skipped\n" if $DEBUG
574
656
  end
575
- }
576
- end
657
+ end
658
+ end #class Remover
577
659
 
578
660
  # Creates a new Tmpdir object.
579
661
  # The arguments are the same as Bio::Command.mktmpdir.
@@ -585,7 +667,7 @@ module Command
585
667
  # *Returns*:: Tmpdir object
586
668
  def initialize(prefix_suffix = nil, tmpdir = nil)
587
669
  @data = []
588
- @clean_proc = self.class.callback(@data)
670
+ @clean_proc = Remover.new(@data)
589
671
  ObjectSpace.define_finalizer(self, @clean_proc)
590
672
  @data.push(@path = Bio::Command.mktmpdir(prefix_suffix, tmpdir).freeze)
591
673
  end