lib/bio/appl/blast/xmlparser.rb in bio-1.2.1 vs lib/bio/appl/blast/xmlparser.rb in bio-1.3.0
- old
+ new
@@ -5,11 +5,11 @@
# Mitsuteru C. Nakao <n@bioruby.org>
# Copyright:: Copyright (C) 2003
# Toshiaki Katayama <k@bioruby.org>
# License:: The Ruby License
#
-# $Id: xmlparser.rb,v 1.17 2007/04/05 23:35:39 trevor Exp $
+# $Id:$
#
# == Description
#
# A parser for blast XML report (format 7) based on the XMLParser.
# This file is automatically loaded by bio/appl/blast/report.rb if
@@ -113,38 +113,55 @@
when 'BlastOutput_query-len'
@query_len = hash[tag].to_i
end
end
- def xmlparser_parse_parameters(hash)
- labels = {
- 'matrix' => 'Parameters_matrix',
- 'expect' => 'Parameters_expect',
- 'include' => 'Parameters_include',
- 'sc-match' => 'Parameters_sc-match',
- 'sc-mismatch' => 'Parameters_sc-mismatch',
- 'gap-open' => 'Parameters_gap-open',
- 'gap-extend' => 'Parameters_gap-extend',
- 'filter' => 'Parameters_filter',
- 'pattern' => 'Parameters_pattern',
- 'entrez-query' => 'Parameters_entrez-query',
- }
- labels.each do |k,v|
+ # set parameter of the key as val
+ def xml_set_parameter(key, val)
+ #labels = {
+ # 'matrix' => 'Parameters_matrix',
+ # 'expect' => 'Parameters_expect',
+ # 'include' => 'Parameters_include',
+ # 'sc-match' => 'Parameters_sc-match',
+ # 'sc-mismatch' => 'Parameters_sc-mismatch',
+ # 'gap-open' => 'Parameters_gap-open',
+ # 'gap-extend' => 'Parameters_gap-extend',
+ # 'filter' => 'Parameters_filter',
+ # 'pattern' => 'Parameters_pattern',
+ # 'entrez-query' => 'Parameters_entrez-query',
+ #}
+ k = key.sub(/\AParameters\_/, '')
+ @parameters[k] =
case k
- when 'filter', 'matrix'
- @parameters[k] = hash[v].to_s
+ when 'expect', 'include'
+ val.to_f
+ when /\Agap\-/, /\Asc\-/
+ val.to_i
else
- @parameters[k] = hash[v].to_i
+ val
end
+ end
+
+ def xmlparser_parse_parameters(hash)
+ hash.each do |k, v|
+ xml_set_parameter(k, v)
end
end
def xmlparser_parse_iteration(tag, hash)
case tag
when 'Iteration_iter-num'
@iterations.last.num = hash[tag].to_i
when 'Iteration_message'
@iterations.last.message = hash[tag].to_s
+
+ # for new BLAST XML format
+ when 'Iteration_query-ID'
+ @iterations.last.query_id = hash[tag].to_s
+ when 'Iteration_query-def'
+ @iterations.last.query_def = hash[tag].to_s
+ when 'Iteration_query-len'
+ @iterations.last.query_len = hash[tag].to_i
end
end
def xmlparser_parse_hit(tag, hash)
hit = @iterations.last.hits.last