bio-lazyblastxml 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bio-lazyblastxml.gemspec +2 -2
- data/lib/bio/appl/blast/lazyblastxml.rb +133 -141
- data/test/test_bio-lazyblastxml.rb +10 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/bio-lazyblastxml.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bio-lazyblastxml}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["robsyme"]
|
12
|
-
s.date = %q{2011-05-
|
12
|
+
s.date = %q{2011-05-31}
|
13
13
|
s.description = %q{This is very scrappy at the moment, and will need to be seriously cleaned up. It does what I need it to do for now. I'll fix it up in the coming weeks. Promise :)}
|
14
14
|
s.email = %q{rob.syme@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -1,184 +1,176 @@
|
|
1
1
|
require "libxml"
|
2
2
|
|
3
|
-
class Enumerator
|
4
|
-
def lazy_select(&block)
|
5
|
-
Enumerator.new do |yielder|
|
6
|
-
self.each do |val|
|
7
|
-
yielder.yield(val) if block.call(val)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def lazy_reject(&block)
|
13
|
-
Enumerator.new do |yielder|
|
14
|
-
self.each do |val|
|
15
|
-
yielder.yield(val) unless block.call(val)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def lazy_map(&block)
|
21
|
-
Enumerator.new do |yielder|
|
22
|
-
self.each do |value|
|
23
|
-
yielder.yield(block.call(value))
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
3
|
module Bio
|
30
4
|
class LazyBlast
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
5
|
+
class Report
|
6
|
+
include Enumerable
|
7
|
+
attr_reader :reader, :program, :version, :db, :query_id, :query_def, :query_len, :parameters
|
35
8
|
|
36
|
-
def
|
37
|
-
|
9
|
+
def initialize(filename)
|
10
|
+
@reader = LibXML::XML::Reader.file(filename)
|
11
|
+
@nodes = Enumerator.new do |yielder|
|
12
|
+
while @reader.read
|
13
|
+
yielder << @reader if @reader.node_type == LibXML::XML::Reader::TYPE_ELEMENT
|
14
|
+
end
|
15
|
+
end
|
16
|
+
setup_report_values
|
38
17
|
end
|
39
18
|
|
40
|
-
def
|
41
|
-
|
19
|
+
def setup_report_values
|
20
|
+
@parameters = Hash.new
|
21
|
+
@nodes.each do |node|
|
22
|
+
return node if node.name == "BlastOutput_iterations"
|
23
|
+
case node.name
|
24
|
+
when 'BlastOutput_program'
|
25
|
+
@program = node.read_inner_xml
|
26
|
+
when 'BlastOutput_version'
|
27
|
+
@version = node.read_inner_xml
|
28
|
+
when 'BlastOutput_db'
|
29
|
+
@db = node.read_inner_xml
|
30
|
+
when 'BlastOutput_query-ID'
|
31
|
+
@query_id = node.read_inner_xml
|
32
|
+
when 'BlastOutput_query-def'
|
33
|
+
@query_def = node.read_inner_xml
|
34
|
+
when 'BlastOutput_query-len'
|
35
|
+
@query_len = node.read_inner_xml.to_i
|
36
|
+
when 'Parameters_matrix'
|
37
|
+
@parameters['matrix'] = node.read_inner_xml
|
38
|
+
when 'Parameters_expect'
|
39
|
+
@parameters['expect'] = node.read_inner_xml.to_i
|
40
|
+
when 'Parameters_gap-open'
|
41
|
+
@parameters['gap-open'] = node.read_inner_xml.to_i
|
42
|
+
when 'Parameters_gap-extend'
|
43
|
+
@parameters['gap-extend'] = node.read_inner_xml.to_i
|
44
|
+
when 'Parameters_filter'
|
45
|
+
@parameters['filter'] = node.read_inner_xml
|
46
|
+
end
|
47
|
+
end
|
42
48
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
class LazyBlast
|
49
|
-
class Report
|
50
|
-
include Enumerable
|
51
|
-
include Bio::LazyBlast::LazyNodeSelector
|
49
|
+
|
50
|
+
def each
|
51
|
+
@nodes.each{|node| yield Iteration.new(node) if node.name == "Iteration"}
|
52
|
+
end
|
53
|
+
alias :each_iteration :each
|
52
54
|
|
53
55
|
class Iteration
|
54
56
|
include Enumerable
|
55
|
-
|
56
|
-
attr_reader :statistics
|
57
|
-
attr_accessor :num
|
58
|
-
attr_accessor :message
|
59
|
-
attr_accessor :query_id
|
60
|
-
attr_accessor :query_def
|
61
|
-
attr_accessor :query_len
|
57
|
+
attr_reader :num, :query_id, :query_def, :query_len, :message, :parameters
|
62
58
|
|
63
|
-
def
|
64
|
-
@reader = xml_reader
|
65
|
-
hits_finished = false
|
59
|
+
def initialize(reader)
|
66
60
|
@nodes = Enumerator.new do |yielder|
|
67
|
-
|
68
|
-
yielder <<
|
61
|
+
until (reader.name == "Iteration" and reader.node_type == LibXML::XML::Reader::TYPE_END_ELEMENT) or !reader.read
|
62
|
+
yielder << reader if reader.node_type == LibXML::XML::Reader::TYPE_ELEMENT
|
69
63
|
end
|
70
64
|
end
|
65
|
+
setup_iteration_values
|
71
66
|
end
|
72
67
|
|
73
|
-
def
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
68
|
+
def setup_iteration_values
|
69
|
+
@nodes.each do |node|
|
70
|
+
return node if node.name == 'Iteration_hits'
|
71
|
+
case node.name
|
72
|
+
when 'Iteration_iter-num'
|
73
|
+
@num = node.read_inner_xml.to_i
|
74
|
+
when 'Iteration_query-ID'
|
75
|
+
@query_id = node.read_inner_xml
|
76
|
+
when 'Iteration_query-def'
|
77
|
+
@query_def = node.read_inner_xml
|
78
|
+
when 'Iteration_query-len'
|
79
|
+
@query_len = node.read_inner_xml.to_i
|
80
|
+
when 'Iteration_message'
|
81
|
+
@message = node.read_inner_xml
|
82
|
+
end
|
84
83
|
end
|
85
84
|
end
|
86
85
|
|
86
|
+
def each
|
87
|
+
@nodes.each{|node| yield Hit.new(node) if node.name == "Hit"}
|
88
|
+
end
|
87
89
|
alias :each_hit :each
|
88
90
|
|
89
91
|
class Hit
|
90
92
|
include Enumerable
|
91
|
-
|
92
|
-
attr_accessor :num
|
93
|
-
attr_accessor :hit_id
|
94
|
-
attr_accessor :len
|
95
|
-
attr_accessor :definition
|
96
|
-
attr_accessor :accession
|
93
|
+
attr_reader :num, :hit_id, :len, :definition, :accession
|
97
94
|
|
98
|
-
def
|
99
|
-
@reader = xml_reader
|
95
|
+
def initialize(reader)
|
100
96
|
@nodes = Enumerator.new do |yielder|
|
101
|
-
|
102
|
-
yielder <<
|
97
|
+
until (reader.name == "Hit" and reader.node_type == LibXML::XML::Reader::TYPE_END_ELEMENT) or !reader.read
|
98
|
+
yielder << reader if reader.node_type == LibXML::XML::Reader::TYPE_ELEMENT
|
103
99
|
end
|
104
100
|
end
|
101
|
+
setup_hit_values
|
105
102
|
end
|
106
103
|
|
107
|
-
def
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
hsp.hseq = next_value_named("Hsp_hseq").to_i
|
123
|
-
hsp.midline = next_value_named("Hsp_midline").to_i
|
124
|
-
yield hsp
|
104
|
+
def setup_hit_values
|
105
|
+
@nodes.each do |node|
|
106
|
+
return node if node.name == 'Hit_hsps'
|
107
|
+
case node.name
|
108
|
+
when 'Hit_num'
|
109
|
+
@num = node.read_inner_xml.to_i
|
110
|
+
when 'Hit_id'
|
111
|
+
@hit_id = node.read_inner_xml.to_i
|
112
|
+
when 'Hit_def'
|
113
|
+
@definition = node.read_inner_xml
|
114
|
+
when 'Hit_accession'
|
115
|
+
@accession = node.read_inner_xml
|
116
|
+
when 'Hit_len'
|
117
|
+
@len = node.read_inner_xml
|
118
|
+
end
|
125
119
|
end
|
126
120
|
end
|
127
|
-
|
121
|
+
|
122
|
+
def each
|
123
|
+
@nodes.each{|node| yield Hsp.new(node) if node.name == "Hsp"}
|
124
|
+
end
|
128
125
|
alias :each_hsp :each
|
129
126
|
|
130
127
|
class Hsp
|
131
|
-
|
132
|
-
attr_accessor :bit_score
|
133
|
-
attr_accessor :evalue
|
134
|
-
attr_accessor :query_from
|
135
|
-
attr_accessor :query_to
|
136
|
-
attr_accessor :hit_from
|
137
|
-
attr_accessor :hit_to
|
138
|
-
attr_accessor :query_frame
|
139
|
-
attr_accessor :hit_frame
|
140
|
-
attr_accessor :identity
|
141
|
-
attr_accessor :positive
|
142
|
-
attr_accessor :gaps
|
143
|
-
attr_accessor :align_len
|
144
|
-
attr_accessor :density
|
145
|
-
attr_accessor :qseq
|
146
|
-
attr_accessor :hseq
|
147
|
-
attr_accessor :midline
|
148
|
-
attr_accessor :percent_identity
|
149
|
-
attr_accessor :mismatch_count
|
150
|
-
end
|
128
|
+
attr_reader :num, :bit_score, :evalue, :query_from, :query_to, :hit_from, :hit_to, :query_frame, :hit_frame, :identity, :positive, :gaps, :align_len, :density, :qseq, :hseq, :midline, :percent_identity, :mismatch_count
|
151
129
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
130
|
+
def initialize(reader)
|
131
|
+
@nodes = Enumerator.new do |yielder|
|
132
|
+
until (reader.name == "Hsp" and reader.node_type == LibXML::XML::Reader::TYPE_END_ELEMENT) or !reader.read
|
133
|
+
yielder << reader if reader.node_type == LibXML::XML::Reader::TYPE_ELEMENT
|
134
|
+
end
|
135
|
+
end
|
136
|
+
setup_hsp_values
|
137
|
+
end
|
157
138
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
139
|
+
def setup_hsp_values
|
140
|
+
@nodes.each do |node|
|
141
|
+
case node.name
|
142
|
+
when 'Hsp_num'
|
143
|
+
@num = node.read_inner_xml.to_i
|
144
|
+
when 'Hsp_bit-score'
|
145
|
+
@bit_score = node.read_inner_xml.to_f
|
146
|
+
when 'Hsp_evalue'
|
147
|
+
@evalue = node.read_inner_xml.to_f
|
148
|
+
when 'Hsp_query-from'
|
149
|
+
@query_from = node.read_inner_xml.to_i
|
150
|
+
when 'Hsp_query-to'
|
151
|
+
@query_to = node.read_inner_xml.to_i
|
152
|
+
when 'Hsp_query-frame'
|
153
|
+
@query_frame = node.read_inner_xml.to_i
|
154
|
+
when 'Hsp_hit-frame'
|
155
|
+
@hit_frame = node.read_inner_xml.to_i
|
156
|
+
when 'Hsp_identity'
|
157
|
+
@identity = node.read_inner_xml.to_i
|
158
|
+
when 'Hsp_positive'
|
159
|
+
@positive = node.read_inner_xml.to_i
|
160
|
+
when 'Hsp_align-len'
|
161
|
+
@align_len = node.read_inner_xml.to_i
|
162
|
+
when 'Hsp_qseq'
|
163
|
+
@qseq = node.read_inner_xml
|
164
|
+
when 'Hsp_hseq'
|
165
|
+
@hseq = node.read_inner_xml
|
166
|
+
when 'Hsp_midline'
|
167
|
+
@midline = node.read_inner_xml
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
163
171
|
end
|
164
172
|
end
|
165
173
|
end
|
166
|
-
|
167
|
-
def each
|
168
|
-
find_nodes_named("Iteration").each do |reader|
|
169
|
-
iteration = Iteration.new
|
170
|
-
iteration.num = next_value_named("Iteration_iter-num").to_i
|
171
|
-
iteration.query_id = next_value_named("Iteration_query-ID")
|
172
|
-
iteration.query_def = next_value_named("Iteration_query-def")
|
173
|
-
iteration.query_len = next_value_named("Iteration_query-len").to_i
|
174
|
-
iteration.setup_hits(@reader)
|
175
|
-
|
176
|
-
yield iteration
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
alias :each_iteration :each
|
181
|
-
|
182
174
|
end
|
183
175
|
end
|
184
176
|
end
|
@@ -36,7 +36,16 @@ class TestIteration < MiniTest::Unit::TestCase
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_iteration_creation
|
39
|
-
|
39
|
+
@iteration = @report.first
|
40
|
+
assert_kind_of Bio::LazyBlast::Report::Iteration, @iteration
|
41
|
+
assert_equal 'blastp', @report.program
|
42
|
+
assert_equal 'blastp 2.2.21 [Jun-14-2009]', @report.version
|
43
|
+
assert_equal 'db.fasta', @report.db
|
44
|
+
assert_equal 'BLOSUM62', @report.parameters['matrix']
|
45
|
+
assert_equal 10, @report.parameters['expect']
|
46
|
+
assert_equal 11, @report.parameters['gap-open']
|
47
|
+
assert_equal 1, @report.parameters['gap-extend']
|
48
|
+
assert_equal 'F', @report.parameters['filter']
|
40
49
|
end
|
41
50
|
|
42
51
|
def test_example_usage
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: bio-lazyblastxml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- robsyme
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-31 00:00:00 +08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -116,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
116
|
requirements:
|
117
117
|
- - ">="
|
118
118
|
- !ruby/object:Gem::Version
|
119
|
-
hash:
|
119
|
+
hash: -3799468829096378627
|
120
120
|
segments:
|
121
121
|
- 0
|
122
122
|
version: "0"
|