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
@@ -6,7 +6,6 @@
6
6
  # Daniel Amelang <dan@amelang.net>
7
7
  # License:: The Ruby License
8
8
  #
9
- # $Id:$
10
9
  #
11
10
  # == Description
12
11
  #
@@ -22,249 +21,6 @@ require 'strscan'
22
21
  require 'bio/tree'
23
22
 
24
23
  module Bio
25
- class Tree
26
-
27
- #---
28
- # newick output
29
- #+++
30
-
31
- # default options
32
- DEFAULT_OPTIONS =
33
- { :indent => ' ' }
34
-
35
- def __get_option(key, options)
36
- if (r = options[key]) != nil then
37
- r
38
- elsif @options && (r = @options[key]) != nil then
39
- r
40
- else
41
- DEFAULT_OPTIONS[key]
42
- end
43
- end
44
- private :__get_option
45
-
46
-
47
- # formats Newick label (unquoted_label or quoted_label)
48
- def __to_newick_format_label(str, options)
49
- if __get_option(:parser, options) == :naive then
50
- return str.to_s
51
- end
52
- str = str.to_s
53
- if /([\(\)\,\:\[\]\_\'\x00-\x1f\x7f])/ =~ str then
54
- # quoted_label
55
- return "\'" + str.gsub(/\'/, "\'\'") + "\'"
56
- end
57
- # unquoted_label
58
- return str.gsub(/ /, '_')
59
- end
60
- private :__to_newick_format_label
61
-
62
- # formats leaf
63
- def __to_newick_format_leaf(node, edge, options)
64
-
65
- label = __to_newick_format_label(get_node_name(node), options)
66
-
67
- dist = get_edge_distance_string(edge)
68
-
69
- bs = get_node_bootstrap_string(node)
70
-
71
- if __get_option(:branch_length_style, options) == :disabled
72
- dist = nil
73
- end
74
-
75
- case __get_option(:bootstrap_style, options)
76
- when :disabled
77
- label + (dist ? ":#{dist}" : '')
78
- when :molphy
79
- label + (dist ? ":#{dist}" : '') + (bs ? "[#{bs}]" : '')
80
- when :traditional
81
- label + (bs ? bs : '') + (dist ? ":#{dist}" : '')
82
- else
83
- # default: same as molphy style
84
- label + (dist ? ":#{dist}" : '') + (bs ? "[#{bs}]" : '')
85
- end
86
- end
87
- private :__to_newick_format_leaf
88
-
89
- # formats leaf for NHX
90
- def __to_newick_format_leaf_NHX(node, edge, options)
91
-
92
- label = __to_newick_format_label(get_node_name(node), options)
93
-
94
- dist = get_edge_distance_string(edge)
95
-
96
- bs = get_node_bootstrap_string(node)
97
-
98
- if __get_option(:branch_length_style, options) == :disabled
99
- dist = nil
100
- end
101
-
102
- nhx = {}
103
-
104
- # bootstrap
105
- nhx[:B] = bs if bs and !(bs.empty?)
106
- # EC number
107
- nhx[:E] = node.ec_number if node.instance_eval {
108
- defined?(@ec_number) && self.ec_number
109
- }
110
- # scientific name
111
- nhx[:S] = node.scientific_name if node.instance_eval {
112
- defined?(@scientific_name) && self.scientific_name
113
- }
114
- # taxonomy id
115
- nhx[:T] = node.taxonomy_id if node.instance_eval {
116
- defined?(@taxonomy_id) && self.taxonomy_id
117
- }
118
-
119
- # :D (gene duplication or speciation)
120
- if node.instance_eval { defined?(@events) && !(self.events.empty?) } then
121
- if node.events.include?(:gene_duplication)
122
- nhx[:D] = 'Y'
123
- elsif node.events.include?(:speciation)
124
- nhx[:D] = 'N'
125
- end
126
- end
127
-
128
- # log likelihood
129
- nhx[:L] = edge.log_likelihood if edge.instance_eval {
130
- defined?(@log_likelihood) && self.log_likelihood }
131
- # width
132
- nhx[:W] = edge.width if edge.instance_eval {
133
- defined?(@width) && self.width }
134
-
135
- # merges other parameters
136
- flag = node.instance_eval { defined? @nhx_parameters }
137
- nhx.merge!(node.nhx_parameters) if flag
138
- flag = edge.instance_eval { defined? @nhx_parameters }
139
- nhx.merge!(edge.nhx_parameters) if flag
140
-
141
- nhx_string = nhx.keys.sort{ |a,b| a.to_s <=> b.to_s }.collect do |key|
142
- "#{key.to_s}=#{nhx[key].to_s}"
143
- end.join(':')
144
- nhx_string = "[&&NHX:" + nhx_string + "]" unless nhx_string.empty?
145
-
146
- label + (dist ? ":#{dist}" : '') + nhx_string
147
- end
148
- private :__to_newick_format_leaf_NHX
149
-
150
- #
151
- def __to_newick(parents, source, depth, format_leaf,
152
- options, &block)
153
- result = []
154
- if indent_string = __get_option(:indent, options) then
155
- indent0 = indent_string * depth
156
- indent = indent_string * (depth + 1)
157
- newline = "\n"
158
- else
159
- indent0 = indent = newline = ''
160
- end
161
- out_edges = self.out_edges(source)
162
- if block_given? then
163
- out_edges.sort! { |edge1, edge2| yield(edge1[1], edge2[1]) }
164
- else
165
- out_edges.sort! do |edge1, edge2|
166
- o1 = edge1[1].order_number
167
- o2 = edge2[1].order_number
168
- if o1 and o2 then
169
- o1 <=> o2
170
- else
171
- edge1[1].name.to_s <=> edge2[1].name.to_s
172
- end
173
- end
174
- end
175
- out_edges.each do |src, tgt, edge|
176
- if parents.include?(tgt) then
177
- ;;
178
- elsif self.out_degree(tgt) == 1 then
179
- result << indent + __send__(format_leaf, tgt, edge, options)
180
- else
181
- result <<
182
- __to_newick([ src ].concat(parents), tgt, depth + 1,
183
- format_leaf, options) +
184
- __send__(format_leaf, tgt, edge, options)
185
- end
186
- end
187
- indent0 + "(" + newline + result.join(',' + newline) +
188
- (result.size > 0 ? newline : '') + indent0 + ')'
189
- end
190
- private :__to_newick
191
-
192
- # Returns a newick formatted string.
193
- # If block is given, the order of the node is sorted
194
- # (as the same manner as Enumerable#sort).
195
- #
196
- # Available options:
197
- # <tt>:indent</tt>::
198
- # indent string; set false to disable (default: ' ')
199
- # <tt>:bootstrap_style</tt>::
200
- # <tt>:disabled</tt> disables bootstrap representations.
201
- # <tt>:traditional</tt> for traditional style.
202
- # <tt>:molphy</tt> for Molphy style (default).
203
- def output_newick(options = {}, &block) #:yields: node1, node2
204
- root = @root
205
- root ||= self.nodes.first
206
- return '();' unless root
207
- __to_newick([], root, 0, :__to_newick_format_leaf, options, &block) +
208
- __to_newick_format_leaf(root, Edge.new, options) +
209
- ";\n"
210
- end
211
-
212
- alias newick output_newick
213
-
214
-
215
- # Returns a NHX (New Hampshire eXtended) formatted string.
216
- # If block is given, the order of the node is sorted
217
- # (as the same manner as Enumerable#sort).
218
- #
219
- # Available options:
220
- # <tt>:indent</tt>::
221
- # indent string; set false to disable (default: ' ')
222
- #
223
- def output_nhx(options = {}, &block) #:yields: node1, node2
224
- root = @root
225
- root ||= self.nodes.first
226
- return '();' unless root
227
- __to_newick([], root, 0,
228
- :__to_newick_format_leaf_NHX, options, &block) +
229
- __to_newick_format_leaf_NHX(root, Edge.new, options) +
230
- ";\n"
231
- end
232
-
233
- # Returns formatted text (or something) of the tree
234
- # Currently supported format is: :newick, :nhx
235
- def output(format, *arg, &block)
236
- case format
237
- when :newick
238
- output_newick(*arg, &block)
239
- when :nhx
240
- output_nhx(*arg, &block)
241
- when :phylip_distance_matrix
242
- output_phylip_distance_matrix(*arg, &block)
243
- else
244
- raise 'Unknown format'
245
- end
246
- end
247
-
248
- #---
249
- # This method isn't suitable to written in this file?
250
- #+++
251
-
252
- # Generates phylip-style distance matrix as a string.
253
- # if nodes is not given, all leaves in the tree are used.
254
- # If the names of some of the given (or default) nodes
255
- # are not defined or are empty, the names are automatically generated.
256
- def output_phylip_distance_matrix(nodes = nil, options = {})
257
- nodes = self.leaves unless nodes
258
- names = nodes.collect do |x|
259
- y = get_node_name(x)
260
- y = sprintf("%x", x.__id__.abs) if y.empty?
261
- y
262
- end
263
- m = self.distance_matrix(nodes)
264
- Bio::Phylip::DistanceMatrix.generate(m, names, options)
265
- end
266
-
267
- end #class Tree
268
24
 
269
25
  #---
270
26
  # newick parser
@@ -5,14 +5,11 @@
5
5
  # GOTO Naohisa <ngoto@gen-info.osaka-u.ac.jp>
6
6
  # License:: The Ruby License
7
7
  #
8
- # $Id: pdb.rb,v 1.8 2007/04/05 23:35:40 trevor Exp $
9
8
  #
10
9
 
11
- require 'bio/db'
12
-
13
10
  # definition of the PDB class
14
11
  module Bio
15
- class PDB #< DB
12
+ class PDB
16
13
 
17
14
  autoload :ChemicalComponent, 'bio/db/pdb/chemicalcomponent'
18
15
 
@@ -6,7 +6,6 @@
6
6
  # Naohisa Goto <ng@bioruby.org>
7
7
  # License:: The Ruby License
8
8
  #
9
- # $Id: atom.rb,v 1.8 2007/04/05 23:35:41 trevor Exp $
10
9
  #
11
10
  # = Bio::PDB::Coordinate
12
11
  #
@@ -19,9 +18,11 @@
19
18
  #
20
19
 
21
20
  require 'matrix'
22
- require 'bio/db/pdb'
23
21
 
24
22
  module Bio
23
+
24
+ require 'bio/db/pdb' unless const_defined?(:PDB)
25
+
25
26
  class PDB
26
27
 
27
28
  # Bio::PDB::Coordinate is a class to store a 3D coordinate.
@@ -6,17 +6,16 @@
6
6
  # Naohisa Goto <ng@bioruby.org>
7
7
  # License:: The Ruby License
8
8
  #
9
- # $Id: chain.rb,v 1.10 2008/04/01 10:36:44 ngoto Exp $
10
9
  #
11
10
  # = Bio::PDB::Chain
12
11
  #
13
12
  # Please refer Bio::PDB::Chain.
14
13
  #
15
14
 
16
- require 'bio/db/pdb'
17
-
18
15
  module Bio
19
16
 
17
+ require 'bio/db/pdb' unless const_defined?(:PDB)
18
+
20
19
  class PDB
21
20
 
22
21
  # Bio::PDB::Chain is a class to store a chain.
@@ -5,7 +5,6 @@
5
5
  # GOTO Naohisa <ngoto@gen-info.osaka-u.ac.jp>
6
6
  # License:: The Ruby License
7
7
  #
8
- # $Id: chemicalcomponent.rb,v 1.3 2007/04/05 23:35:41 trevor Exp $
9
8
  #
10
9
  # = About Bio::PDB::ChemicalComponent
11
10
  #
@@ -17,9 +16,11 @@
17
16
  # * http://deposit.pdb.org/het_dictionary.txt
18
17
  #
19
18
 
20
- require 'bio/db/pdb/pdb'
21
19
 
22
20
  module Bio
21
+
22
+ require 'bio/db/pdb' unless const_defined?(:PDB)
23
+
23
24
  class PDB
24
25
 
25
26
  # Bio::PDB::ChemicalComponet is a parser for a entry of
@@ -6,17 +6,17 @@
6
6
  # Naohisa Goto <ng@bioruby.org>
7
7
  # License:: The Ruby License
8
8
  #
9
- # $Id: model.rb,v 1.10 2007/12/18 13:48:42 ngoto Exp $
10
9
  #
11
10
  # = Bio::PDB::Model
12
11
  #
13
12
  # Please refer Bio::PDB::Model.
14
13
  #
15
14
 
16
- require 'bio/db/pdb'
17
15
 
18
16
  module Bio
19
17
 
18
+ require 'bio/db/pdb' unless const_defined?(:PDB)
19
+
20
20
  class PDB
21
21
 
22
22
  # Bio::PDB::Model is a class to store a model.
@@ -22,11 +22,12 @@
22
22
  # This is beta version. Specs shall be changed frequently.
23
23
  #
24
24
 
25
- require 'bio/db/pdb'
26
25
  require 'bio/data/aa'
27
26
 
28
27
  module Bio
29
28
 
29
+ require 'bio/db/pdb' unless const_defined?(:PDB)
30
+
30
31
  # This is the main PDB class which takes care of parsing, annotations
31
32
  # and is the entry way to the co-ordinate data held in models.
32
33
  #
@@ -6,17 +6,17 @@
6
6
  # Naohisa Goto <ng@bioruby.org>
7
7
  # License:: The Ruby License
8
8
  #
9
- # $Id:$
10
9
  #
11
10
  # = Bio::PDB::Residue
12
11
  #
13
12
  # = Bio::PDB::Heterogen
14
13
  #
15
14
 
16
- require 'bio/db/pdb'
17
15
 
18
16
  module Bio
19
17
 
18
+ require 'bio/db/pdb' unless const_defined?(:PDB)
19
+
20
20
  class PDB
21
21
 
22
22
  # Bio::PDB::Residue is a class to store a residue.
@@ -6,7 +6,6 @@
6
6
  # Naohisa Goto <ng@bioruby.org>
7
7
  # License:: The Ruby License
8
8
  #
9
- # $Id: utils.rb,v 1.7 2007/04/05 23:35:41 trevor Exp $
10
9
  #
11
10
  # = Bio::PDB::Utils
12
11
  #
@@ -38,9 +37,12 @@
38
37
  #
39
38
 
40
39
  require 'matrix'
41
- require 'bio/db/pdb'
42
40
 
43
- module Bio; class PDB
41
+ module Bio
42
+
43
+ require 'bio/db/pdb' unless const_defined?(:PDB)
44
+
45
+ class PDB
44
46
 
45
47
  # Utility methods for PDB data.
46
48
  # The methods in this mixin should be applicalbe to all PDB objects.
@@ -395,5 +397,6 @@ module Bio; class PDB
395
397
  end
396
398
  end #module HeterogenFinder
397
399
 
398
- end; end #module Bio; class PDB
400
+ end #class PDB
401
+ end #module Bio
399
402
 
@@ -78,15 +78,27 @@ module PhyloXML
78
78
  # Initializes LibXML::Reader and reads the file until it reaches the first
79
79
  # phylogeny element.
80
80
  #
81
- # Create a new Bio::PhyloXML::Parser object.
81
+ # Example: Create a new Bio::PhyloXML::Parser object.
82
82
  #
83
83
  # p = Bio::PhyloXML::Parser.open("./phyloxml_examples.xml")
84
84
  #
85
+ # If the optional code block is given, Bio::PhyloXML object is passed to
86
+ # the block as an argument. When the block terminates, the Bio::PhyloXML
87
+ # object is automatically closed, and the open method returns the value
88
+ # of the block.
89
+ #
90
+ # Example: Get the first tree in the file.
91
+ #
92
+ # tree = Bio::PhyloXML::Parser.open("example.xml") do |px|
93
+ # px.next_tree
94
+ # end
95
+ #
85
96
  # ---
86
97
  # *Arguments*:
87
98
  # * (required) _filename_: Path to the file to parse.
88
99
  # * (optional) _validate_: Whether to validate the file against schema or not. Default value is true.
89
- # *Returns*:: Bio::PhyloXML::Parser object
100
+ # *Returns*:: (without block) Bio::PhyloXML::Parser object
101
+ # *Returns*:: (with block) the value of the block
90
102
  def self.open(filename, validate=true)
91
103
  obj = new(nil, validate)
92
104
  obj.instance_eval {
@@ -98,7 +110,16 @@ module PhyloXML
98
110
  LibXML::XML::Parser::Options::NONET })
99
111
  _skip_leader
100
112
  }
101
- obj
113
+ if block_given? then
114
+ begin
115
+ ret = yield obj
116
+ ensure
117
+ obj.close if obj and !obj.closed?
118
+ end
119
+ ret
120
+ else
121
+ obj
122
+ end
102
123
  end
103
124
 
104
125
  # Initializes LibXML::Reader and reads the file until it reaches the first
@@ -108,11 +129,17 @@ module PhyloXML
108
129
  #
109
130
  # p = Bio::PhyloXML::Parser.open_uri("http://www.phyloxml.org/examples/apaf.xml")
110
131
  #
132
+ # If the optional code block is given, Bio::PhyloXML object is passed to
133
+ # the block as an argument. When the block terminates, the Bio::PhyloXML
134
+ # object is automatically closed, and the open_uri method returns the
135
+ # value of the block.
136
+ #
111
137
  # ---
112
138
  # *Arguments*:
113
139
  # * (required) _uri_: (URI or String) URI to the data to parse
114
140
  # * (optional) _validate_: For URI reader, the "validate" option is ignored and no validation is executed.
115
- # *Returns*:: Bio::PhyloXML::Parser object
141
+ # *Returns*:: (without block) Bio::PhyloXML::Parser object
142
+ # *Returns*:: (with block) the value of the block
116
143
  def self.open_uri(uri, validate=true)
117
144
  case uri
118
145
  when URI
@@ -129,7 +156,15 @@ module PhyloXML
129
156
  @reader = XML::Reader.file(uri)
130
157
  _skip_leader
131
158
  }
132
- obj
159
+ if block_given? then
160
+ begin
161
+ ret = yield obj
162
+ ensure
163
+ obj.close if obj and !obj.closed?
164
+ end
165
+ else
166
+ obj
167
+ end
133
168
  end
134
169
 
135
170
  # Special class for closed PhyloXML::Parser object.
@@ -156,6 +191,18 @@ module PhyloXML
156
191
  nil
157
192
  end
158
193
 
194
+ # If the object is closed by using the close method or equivalent,
195
+ # returns true. Otherwise, returns false.
196
+ # ---
197
+ # *Returns*:: true or false
198
+ def closed?
199
+ if @reader.kind_of?(ClosedPhyloXMLParser) then
200
+ true
201
+ else
202
+ false
203
+ end
204
+ end
205
+
159
206
  # Initializes LibXML::Reader and reads from the IO until it reaches
160
207
  # the first phylogeny element.
161
208
  #