scbi_blast 0.0.33 → 0.0.34
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +2 -0
- data/Rakefile +1 -1
- data/lib/scbi_blast/batch_blast.rb +1 -1
- data/lib/scbi_blast/blast_hit.rb +50 -2
- data/lib/scbi_blast/blast_query.rb +38 -3
- data/lib/scbi_blast/blast_result.rb +89 -0
- data/lib/scbi_blast/blast_simplexml_result.rb +8 -38
- data/lib/scbi_blast/blast_streamxml_result.rb +181 -0
- data/lib/scbi_blast/blast_table_result.rb +7 -39
- data/lib/scbi_blast.rb +3 -1
- data/test/test_scbi_blast.rb +40 -7
- metadata +17 -4
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -14,8 +14,10 @@ test/empty_blast.xml
|
|
14
14
|
test/blast.txt
|
15
15
|
lib/scbi_blast/blast_hit.rb
|
16
16
|
lib/scbi_blast/blast_query.rb
|
17
|
+
lib/scbi_blast/blast_result.rb
|
17
18
|
lib/scbi_blast/blast_table_result.rb
|
18
19
|
lib/scbi_blast/blast_xml_result.rb
|
19
20
|
lib/scbi_blast/blast_simplexml_result.rb
|
21
|
+
lib/scbi_blast/blast_streamxml_result.rb
|
20
22
|
lib/scbi_blast/batch_blast.rb
|
21
23
|
lib/scbi_blast/dust_masker.rb
|
data/Rakefile
CHANGED
@@ -14,7 +14,7 @@ $hoe = Hoe.spec 'scbi_blast' do
|
|
14
14
|
self.developer 'Dario Guerrero & Almudena Bocinos', 'dariogf@gmail.com, alkoke@gmail.com'
|
15
15
|
# self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
16
16
|
self.rubyforge_name = self.name # TODO this is default value
|
17
|
-
|
17
|
+
self.extra_deps = [['xml-simple','>= 1.0.12']]
|
18
18
|
|
19
19
|
end
|
20
20
|
|
data/lib/scbi_blast/blast_hit.rb
CHANGED
@@ -25,11 +25,16 @@ class BlastHit
|
|
25
25
|
|
26
26
|
# initializes a new hit
|
27
27
|
def initialize(q_beg,q_end,s_beg,s_end)
|
28
|
-
|
28
|
+
set_limits(q_beg,q_end,s_beg,s_end)
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_limits(q_beg,q_end,s_beg,s_end)
|
32
|
+
# puts "Set limits #{[q_beg,q_end,s_beg,s_end].join(',')}"
|
29
33
|
@q_beg = q_beg.to_i-1 #blast indexes are 1 based
|
30
34
|
@q_end = q_end.to_i-1
|
31
35
|
@s_beg = s_beg.to_i-1
|
32
36
|
@s_end = s_end.to_i-1
|
37
|
+
# puts "Set limits2 #{[@q_beg,@q_end,@s_beg,@s_end].join(',')}"
|
33
38
|
|
34
39
|
@reversed = false
|
35
40
|
|
@@ -41,7 +46,9 @@ class BlastHit
|
|
41
46
|
@s_end = s_beg.to_i-1
|
42
47
|
@reversed = true
|
43
48
|
end
|
44
|
-
|
49
|
+
# puts "Set limits3 #{[@q_beg,@q_end,@s_beg,@s_end].join(',')}"
|
50
|
+
# puts "Set limits4 #{[q_beg,q_end,s_beg,s_end].join(',')}"
|
51
|
+
|
45
52
|
end
|
46
53
|
|
47
54
|
# some accessors
|
@@ -125,6 +132,47 @@ class BlastHit
|
|
125
132
|
def size
|
126
133
|
return (@q_end-@q_beg+1)
|
127
134
|
end
|
135
|
+
|
136
|
+
def compare?(hit)
|
137
|
+
res=true
|
138
|
+
|
139
|
+
res &&=( @q_beg==hit.q_beg)
|
140
|
+
res &&=( @q_end==hit.q_end)
|
141
|
+
res &&=( @s_beg==hit.s_beg)
|
142
|
+
res &&=( @s_end==hit.s_end)
|
143
|
+
|
144
|
+
res &&=( @subject_id==hit.subject_id)
|
145
|
+
res &&=( @align_len==hit.align_len)
|
146
|
+
res &&=( @gaps==hit.gaps)
|
147
|
+
res &&=( @mismatches==hit.mismatches)
|
148
|
+
|
149
|
+
|
150
|
+
res &&=( @reversed==hit.reversed)
|
151
|
+
res &&=( @score==hit.score)
|
152
|
+
res &&=( @acc==hit.acc)
|
153
|
+
res &&=( @definition==hit.definition)
|
154
|
+
|
155
|
+
|
156
|
+
res &&=( @q_frame==hit.q_frame)
|
157
|
+
res &&=( @s_frame==hit.s_frame)
|
158
|
+
res &&=( @full_subject_length==hit.full_subject_length)
|
159
|
+
res &&=( @ident==hit.ident)
|
160
|
+
|
161
|
+
|
162
|
+
res &&=( @e_val==hit.e_val)
|
163
|
+
res &&=( @bit_score==hit.bit_score)
|
164
|
+
res &&=( @q_seq==hit.q_seq)
|
165
|
+
res &&=( @s_seq==hit.s_seq)
|
166
|
+
|
167
|
+
if !res
|
168
|
+
puts "Hits not equal:"
|
169
|
+
puts inspect
|
170
|
+
puts "="*20
|
171
|
+
puts hit.inspect
|
172
|
+
end
|
173
|
+
|
174
|
+
return res
|
175
|
+
end
|
128
176
|
|
129
177
|
# readers and accessor for properties
|
130
178
|
attr_accessor :q_beg, :q_end, :s_beg, :s_end
|
@@ -42,9 +42,9 @@ class BlastQuery
|
|
42
42
|
|
43
43
|
# inspect query values with all hits
|
44
44
|
def inspect
|
45
|
-
res = "\n * Query #{@query_id} :"
|
45
|
+
res = "\n * Query #{@query_id}, #{@query_def}, #{@full_query_length} :"
|
46
46
|
res += "subject_id ident align_len mismatches gaps q_beg q_end s_beg s_end e_val bit_score reversed\n\n"
|
47
|
-
@hits.each{ |h| res+= h.inspect+"\n" }
|
47
|
+
@hits.each{ |h| res+= "=="+h.inspect+"\n" }
|
48
48
|
|
49
49
|
return res
|
50
50
|
end
|
@@ -72,6 +72,41 @@ class BlastQuery
|
|
72
72
|
end until (res2.count == res.count)
|
73
73
|
|
74
74
|
|
75
|
+
return res
|
76
|
+
end
|
77
|
+
|
78
|
+
def compare?(query)
|
79
|
+
res=true
|
80
|
+
|
81
|
+
|
82
|
+
# same hits
|
83
|
+
res &&=( @hits.count==query.hits.count)
|
84
|
+
|
85
|
+
# if !res
|
86
|
+
# puts "Queries not equal:"
|
87
|
+
# puts inspect
|
88
|
+
# puts "="*20
|
89
|
+
# puts query.inspect
|
90
|
+
# end
|
91
|
+
|
92
|
+
if res
|
93
|
+
@hits.each_with_index do |h,i|
|
94
|
+
res &&= h.compare?(query.hits[i])
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# if !res
|
99
|
+
# puts "Queries hits not equal:"
|
100
|
+
# puts inspect
|
101
|
+
# puts "="*20
|
102
|
+
# puts query.inspect
|
103
|
+
# end
|
104
|
+
|
105
|
+
res &&=( @query_id==query.query_id)
|
106
|
+
res &&=( @query_def==query.query_def)
|
107
|
+
res &&=( @full_query_length==query.full_query_length)
|
108
|
+
|
109
|
+
|
75
110
|
return res
|
76
111
|
end
|
77
112
|
|
@@ -86,7 +121,7 @@ private
|
|
86
121
|
merged_ids.push hit.definition if !merged_ids.nil? && (!merged_ids.include?(hit.definition))
|
87
122
|
|
88
123
|
# find overlapping hits
|
89
|
-
c=merged_hits.find{|
|
124
|
+
c=merged_hits.find{|c2| hit.query_overlaps?(c2)}
|
90
125
|
|
91
126
|
if (c.nil?)
|
92
127
|
# add new hit
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# Copyright (c) 2010 Dario Guerrero & Almudena Bocinos
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# 'Software'), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
|
23
|
+
require "blast_query.rb"
|
24
|
+
require "blast_hit.rb"
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
# Extracts results from blast table's file and uses it to create instances of "BlastQuery" and "BlastHit"
|
29
|
+
class BlastResult
|
30
|
+
|
31
|
+
attr_accessor :querys
|
32
|
+
|
33
|
+
# Parser initialization
|
34
|
+
def initialize(input)
|
35
|
+
|
36
|
+
@querys = []
|
37
|
+
|
38
|
+
# if input.is_a?(Array)
|
39
|
+
# lines=input
|
40
|
+
# else
|
41
|
+
# fich = File.open(input,'r')
|
42
|
+
# lines = fich.readlines
|
43
|
+
# fich.close
|
44
|
+
# end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
# inspect results
|
49
|
+
def inspect
|
50
|
+
res = "Blast results:\n"
|
51
|
+
res+= '-'*20
|
52
|
+
res+= "\nQuerys: #{@querys.count}\n"
|
53
|
+
@querys.each{|q| res+=q.inspect+"\n"}
|
54
|
+
return res
|
55
|
+
end
|
56
|
+
|
57
|
+
# find query by name
|
58
|
+
def find_query(querys,name_q)
|
59
|
+
# newq = querys.find{|q| ( q.find{|h| (h.subject_id)})}
|
60
|
+
new_q=nil
|
61
|
+
|
62
|
+
if !querys.empty?
|
63
|
+
new_q=querys.find{|q| (q.query_id==name_q)}
|
64
|
+
end
|
65
|
+
|
66
|
+
return new_q
|
67
|
+
end
|
68
|
+
|
69
|
+
# check if there are querys
|
70
|
+
def empty?
|
71
|
+
return @querys.empty?
|
72
|
+
end
|
73
|
+
|
74
|
+
# get query count
|
75
|
+
def size
|
76
|
+
@querys.size
|
77
|
+
end
|
78
|
+
|
79
|
+
def compare?(results)
|
80
|
+
res = true
|
81
|
+
|
82
|
+
@querys.each_with_index do |q,i|
|
83
|
+
res &&= q.compare?(results.querys[i])
|
84
|
+
end
|
85
|
+
|
86
|
+
return res
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -27,12 +27,12 @@ require 'xmlsimple'
|
|
27
27
|
|
28
28
|
# Extracts results from a blast results in XML
|
29
29
|
# format and uses it to create instances of "BlastQuery" and "BlastHit"
|
30
|
-
class BlastSimplexmlResult
|
30
|
+
class BlastSimplexmlResult < BlastResult
|
31
31
|
|
32
32
|
# Parser initialization
|
33
33
|
def initialize(input)
|
34
|
+
super(input)
|
34
35
|
|
35
|
-
@querys = []
|
36
36
|
lines=[]
|
37
37
|
if input.is_a?(Array)
|
38
38
|
lines=input
|
@@ -44,8 +44,11 @@ class BlastSimplexmlResult
|
|
44
44
|
else
|
45
45
|
raise "File #{input} doesn't exists"
|
46
46
|
end
|
47
|
-
|
48
47
|
end
|
48
|
+
parse(lines)
|
49
|
+
end
|
50
|
+
|
51
|
+
def parse(lines)
|
49
52
|
|
50
53
|
# puts "lines length #{lines.length}"
|
51
54
|
if !lines.empty?
|
@@ -59,12 +62,13 @@ class BlastSimplexmlResult
|
|
59
62
|
# puts JSON::pretty_generate(iteration)
|
60
63
|
|
61
64
|
query_id = iteration['Iteration_query-ID'][0]
|
62
|
-
full_query_length = iteration['Iteration_query-len'][0]
|
65
|
+
full_query_length = iteration['Iteration_query-len'][0].to_i
|
63
66
|
query_def = iteration['Iteration_query-def'][0]
|
64
67
|
|
65
68
|
if query_def =~ /^([^\s]+)/
|
66
69
|
query_def=$1
|
67
70
|
end
|
71
|
+
|
68
72
|
|
69
73
|
#@query_def = iteration['Iteration_query-def'][0]
|
70
74
|
|
@@ -135,38 +139,4 @@ class BlastSimplexmlResult
|
|
135
139
|
#inspect
|
136
140
|
end
|
137
141
|
|
138
|
-
|
139
|
-
|
140
|
-
def inspect
|
141
|
-
|
142
|
-
res = "Blast results:\n"
|
143
|
-
res+= '-'*20
|
144
|
-
res+= "\nQuerys: #{@querys.count}\n"
|
145
|
-
@querys.each{|q| res+=q.inspect+"\n"}
|
146
|
-
return res
|
147
|
-
end
|
148
|
-
|
149
|
-
# finds a query by name
|
150
|
-
def find_query(querys,name_q)
|
151
|
-
# newq = querys.find{|q| ( q.find{|h| (h.subject_id)})}
|
152
|
-
new_q=nil
|
153
|
-
|
154
|
-
if !querys.empty?
|
155
|
-
new_q=querys.find{|q| (q.query_id==name_q)}
|
156
|
-
end
|
157
|
-
|
158
|
-
return new_q
|
159
|
-
end
|
160
|
-
|
161
|
-
# check if there are querys
|
162
|
-
def empty?
|
163
|
-
return @querys.empty?
|
164
|
-
end
|
165
|
-
|
166
|
-
# get num of querys
|
167
|
-
def size
|
168
|
-
@querys.size
|
169
|
-
end
|
170
|
-
|
171
|
-
attr_accessor :querys
|
172
142
|
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
require "blast_query.rb"
|
2
|
+
require "blast_hit.rb"
|
3
|
+
|
4
|
+
require 'rexml/document'
|
5
|
+
require 'rexml/streamlistener'
|
6
|
+
|
7
|
+
include REXML
|
8
|
+
include REXML::StreamListener
|
9
|
+
|
10
|
+
# Extracts results from a blast results in XML
|
11
|
+
# format and uses it to create instances of "BlastQuery" and "BlastHit"
|
12
|
+
class BlastStreamxmlResult < BlastResult
|
13
|
+
|
14
|
+
# Parser initialization
|
15
|
+
def initialize(input)
|
16
|
+
super(input)
|
17
|
+
|
18
|
+
lines=[]
|
19
|
+
|
20
|
+
# some variables for tracking the state of the parse
|
21
|
+
@current_query = nil
|
22
|
+
@current_hit = nil
|
23
|
+
@current_element = nil
|
24
|
+
@current_hit_subject_id=''
|
25
|
+
@current_hit_acc=''
|
26
|
+
@current_hit_full_subject_length=0
|
27
|
+
@current_hit_hit_def=''
|
28
|
+
|
29
|
+
# @state = nil # (values :in_query,:in_hit)
|
30
|
+
|
31
|
+
|
32
|
+
if input.is_a?(Array)
|
33
|
+
lines=input.join("\n")
|
34
|
+
do_parse(lines)
|
35
|
+
|
36
|
+
elsif !input.strip.empty?
|
37
|
+
|
38
|
+
if File.exists?(input)
|
39
|
+
lines= File.open(input,'r')
|
40
|
+
# @lines = fich.readlines
|
41
|
+
# fich.close
|
42
|
+
do_parse(lines)
|
43
|
+
lines.close
|
44
|
+
else
|
45
|
+
raise "File #{input} doesn't exists"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def tag_start(name, attributes)
|
53
|
+
# puts "+#{name}: #{attributes}"
|
54
|
+
case name
|
55
|
+
when 'Iteration'
|
56
|
+
@current_query= BlastQuery.new(-1)
|
57
|
+
|
58
|
+
when 'Hit'
|
59
|
+
@current_hit_subject_id=''
|
60
|
+
@current_hit_acc=''
|
61
|
+
@current_hit_full_subject_length=0
|
62
|
+
@current_hit_hit_def=''
|
63
|
+
|
64
|
+
when 'Hsp'
|
65
|
+
@current_hit = BlastHit.new(0,0,0,0)
|
66
|
+
|
67
|
+
# populate results from hit
|
68
|
+
@current_hit.subject_id=@current_hit_subject_id
|
69
|
+
@current_hit.full_subject_length=@current_hit_full_subject_length
|
70
|
+
@current_hit.definition=@current_hit_hit_def
|
71
|
+
@current_hit.acc=@current_hit_acc
|
72
|
+
else
|
73
|
+
@current_element = name
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
def tag_end(name)
|
79
|
+
|
80
|
+
case name
|
81
|
+
when 'Iteration'
|
82
|
+
@querys.push @current_query
|
83
|
+
@current_query=nil
|
84
|
+
when 'Hit'
|
85
|
+
@current_hit_subject_id=''
|
86
|
+
@current_hit_acc=''
|
87
|
+
@current_hit_full_subject_length=0
|
88
|
+
@current_hit_hit_def=''
|
89
|
+
@current_hit=nil
|
90
|
+
|
91
|
+
when 'Hsp'
|
92
|
+
@current_hit.set_limits(@current_hit.q_beg,@current_hit.q_end,@current_hit.s_beg,@current_hit.s_end)
|
93
|
+
|
94
|
+
@current_query.hits.push @current_hit
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
@current_element=nil
|
99
|
+
# puts "-#{name}"
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
def text(text)
|
104
|
+
|
105
|
+
case @current_element
|
106
|
+
|
107
|
+
# values for querys
|
108
|
+
when 'Iteration_query-ID'
|
109
|
+
@current_query.query_id=text
|
110
|
+
when 'Iteration_query-len'
|
111
|
+
@current_query.full_query_length=text.to_i
|
112
|
+
when 'Iteration_query-def'
|
113
|
+
@current_query.query_def=text
|
114
|
+
|
115
|
+
# values for hits
|
116
|
+
when 'Hit_id'
|
117
|
+
@current_hit_subject_id=text
|
118
|
+
when 'Hit_accession'
|
119
|
+
@current_hit_acc=text
|
120
|
+
when 'Hit_len'
|
121
|
+
@current_hit_full_subject_length=text.to_i
|
122
|
+
when 'Hit_def'
|
123
|
+
@current_hit_hit_def=text
|
124
|
+
if @current_hit_hit_def=='No definition line'
|
125
|
+
@current_hit_hit_def =@current_hit_subject_id
|
126
|
+
end
|
127
|
+
|
128
|
+
# values for HSPs
|
129
|
+
|
130
|
+
|
131
|
+
when 'Hsp_query-from'
|
132
|
+
# puts "QBEG1:#{text.to_i}"
|
133
|
+
@current_hit.q_beg=text.to_i
|
134
|
+
# puts "QBEG2:#{@current_hit.q_beg},#{text.to_i}"
|
135
|
+
when 'Hsp_query-to'
|
136
|
+
@current_hit.q_end=text.to_i
|
137
|
+
when 'Hsp_hit-from'
|
138
|
+
@current_hit.s_beg=text.to_i
|
139
|
+
when 'Hsp_hit-to'
|
140
|
+
@current_hit.s_end=text.to_i
|
141
|
+
when 'Hsp_align-len'
|
142
|
+
@current_hit.align_len=text.to_i
|
143
|
+
@current_hit.ident=(@current_hit.ident/@current_hit.align_len)*100
|
144
|
+
when 'Hsp_identity'
|
145
|
+
|
146
|
+
@current_hit.ident=(text.to_f)
|
147
|
+
# @current_hit.ident=(text.to_f/@current_hit.align_len)*100
|
148
|
+
# percent calculation now goes to align-len
|
149
|
+
when 'Hsp_gaps'
|
150
|
+
@current_hit.gaps=text.to_i
|
151
|
+
when 'Hsp_midline'
|
152
|
+
@current_hit.mismatches= text.count(' ').to_i - @current_hit.gaps
|
153
|
+
when 'Hsp_evalue'
|
154
|
+
@current_hit.e_val=text.to_f
|
155
|
+
@current_hit.e_val = (@current_hit.e_val*1000).round/1000.0
|
156
|
+
when 'Hsp_bit-score'
|
157
|
+
@current_hit.bit_score=text.to_f
|
158
|
+
@current_hit.bit_score = (@current_hit.bit_score*100).round/100.0
|
159
|
+
when 'Hsp_score'
|
160
|
+
@current_hit.score =text.to_f
|
161
|
+
when 'Hsp_query-frame'
|
162
|
+
@current_hit.q_frame = text.to_i
|
163
|
+
when 'Hsp_hit-frame'
|
164
|
+
@current_hit.s_frame =text.to_i
|
165
|
+
|
166
|
+
when 'Hsp_qseq'
|
167
|
+
@current_hit.q_seq = text
|
168
|
+
when 'Hsp_hseq'
|
169
|
+
@current_hit.s_seq = text
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
# reset the current element so we don't pick up empty text
|
174
|
+
@current_element = nil
|
175
|
+
end
|
176
|
+
|
177
|
+
def do_parse(lines)
|
178
|
+
Document.parse_stream(lines, self)
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
@@ -24,14 +24,13 @@ require "blast_query.rb"
|
|
24
24
|
require "blast_hit.rb"
|
25
25
|
|
26
26
|
|
27
|
-
|
28
27
|
# Extracts results from blast table's file and uses it to create instances of "BlastQuery" and "BlastHit"
|
29
|
-
class BlastTableResult
|
28
|
+
class BlastTableResult < BlastResult
|
30
29
|
|
31
30
|
# Parser initialization
|
32
31
|
def initialize(input)
|
33
32
|
|
34
|
-
|
33
|
+
super(input)
|
35
34
|
|
36
35
|
|
37
36
|
if input.is_a?(Array)
|
@@ -44,7 +43,10 @@ class BlastTableResult
|
|
44
43
|
fich.close
|
45
44
|
|
46
45
|
end
|
47
|
-
|
46
|
+
parse(lines)
|
47
|
+
end
|
48
|
+
|
49
|
+
def parse(lines)
|
48
50
|
query_name=''
|
49
51
|
|
50
52
|
lines.each do |line|
|
@@ -57,9 +59,9 @@ class BlastTableResult
|
|
57
59
|
elsif line =~ /^#\s0\shits\sfound$/
|
58
60
|
@querys.push BlastQuery.new(query_name)
|
59
61
|
end
|
62
|
+
|
60
63
|
# 0 hits found
|
61
64
|
|
62
|
-
|
63
65
|
else
|
64
66
|
params = line.split(/\t+/)
|
65
67
|
|
@@ -168,38 +170,4 @@ class BlastTableResult
|
|
168
170
|
|
169
171
|
end
|
170
172
|
|
171
|
-
|
172
|
-
# inspect results
|
173
|
-
def inspect
|
174
|
-
res = "Blast results:\n"
|
175
|
-
res+= '-'*20
|
176
|
-
res+= "\nQuerys: #{@querys.count}\n"
|
177
|
-
@querys.each{|q| res+=q.inspect+"\n"}
|
178
|
-
return res
|
179
|
-
end
|
180
|
-
|
181
|
-
# find query by name
|
182
|
-
def find_query(querys,name_q)
|
183
|
-
# newq = querys.find{|q| ( q.find{|h| (h.subject_id)})}
|
184
|
-
new_q=nil
|
185
|
-
|
186
|
-
if !querys.empty?
|
187
|
-
new_q=querys.find{|q| (q.query_id==name_q)}
|
188
|
-
end
|
189
|
-
|
190
|
-
return new_q
|
191
|
-
end
|
192
|
-
|
193
|
-
# check if there are querys
|
194
|
-
def empty?
|
195
|
-
|
196
|
-
return @querys.empty?
|
197
|
-
end
|
198
|
-
|
199
|
-
# get query count
|
200
|
-
def size
|
201
|
-
@querys.size
|
202
|
-
end
|
203
|
-
|
204
|
-
attr_accessor :querys
|
205
173
|
end
|
data/lib/scbi_blast.rb
CHANGED
@@ -26,12 +26,14 @@ require 'batch_blast'
|
|
26
26
|
require 'dust_masker'
|
27
27
|
require 'blast_query'
|
28
28
|
# require 'blast_xml_result'
|
29
|
+
require 'blast_result'
|
29
30
|
require 'blast_simplexml_result'
|
31
|
+
require 'blast_streamxml_result'
|
30
32
|
require 'blast_hit'
|
31
33
|
require 'blast_table_result'
|
32
34
|
|
33
35
|
module ScbiBlast
|
34
|
-
VERSION = '0.0.
|
36
|
+
VERSION = '0.0.34'
|
35
37
|
end
|
36
38
|
|
37
39
|
|
data/test/test_scbi_blast.rb
CHANGED
@@ -17,15 +17,48 @@ class TestScbiBlast < Test::Unit::TestCase
|
|
17
17
|
puts res.inspect
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
def test_querys
|
21
|
+
res = BlastSimplexmlResult.new(File.join(File.dirname(__FILE__),'blast.xml'))
|
22
22
|
# puts "BLAST.XML"
|
23
23
|
# puts res.inspect
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
assert_equal(2,res.querys.count)
|
25
|
+
assert_equal(2,res.querys[0].hits.count)
|
26
|
+
assert_equal(2,res.querys[1].hits.count)
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_streamxml
|
31
|
+
file='blast.xml'
|
32
|
+
|
33
|
+
resStream = BlastStreamxmlResult.new(File.join(File.dirname(__FILE__),file))
|
34
|
+
resSimple = BlastSimplexmlResult.new(File.join(File.dirname(__FILE__),file))
|
35
|
+
|
36
|
+
# res = BlastStreamxmlResult.new(File.join(File.dirname(__FILE__),'db_1.xml'))
|
37
|
+
# puts "BLAST.XML"
|
38
|
+
# puts res.inspect
|
39
|
+
assert_equal(2,resStream.querys.count)
|
40
|
+
assert_equal(2,resStream.querys[0].hits.count)
|
41
|
+
assert_equal(2,resStream.querys[1].hits.count)
|
42
|
+
|
43
|
+
assert(resStream.compare?(resSimple))
|
44
|
+
|
45
|
+
resStream.querys.each_with_index do |q,i|
|
46
|
+
q2=resSimple.querys[i]
|
47
|
+
|
48
|
+
q.hits.each_with_index do |h,i2|
|
49
|
+
h2=q2.hits[i2]
|
50
|
+
assert(h.compare?(h2),"Hits not equal: #{h.inspect},#{h2.inspect}")
|
51
|
+
end
|
52
|
+
|
53
|
+
assert_equal(q.query_id,q2.query_id)
|
54
|
+
assert_equal(q.query_def,q2.query_def)
|
55
|
+
assert_equal(q.full_query_length , q2.full_query_length)
|
56
|
+
|
57
|
+
assert(q.compare?(q2),"Query not equal: #{q.inspect},#{q2.inspect}")
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
29
62
|
|
30
63
|
def test_hits
|
31
64
|
assert true
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: scbi_blast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.34
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Dario Guerrero & Almudena Bocinos
|
@@ -10,19 +10,30 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2012-04-30 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: xml-simple
|
17
17
|
prerelease: false
|
18
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.12
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: hoe
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
19
30
|
none: false
|
20
31
|
requirements:
|
21
32
|
- - ">="
|
22
33
|
- !ruby/object:Gem::Version
|
23
34
|
version: 2.8.0
|
24
35
|
type: :development
|
25
|
-
version_requirements: *
|
36
|
+
version_requirements: *id002
|
26
37
|
description: |-
|
27
38
|
scbi_blast is a ruby gem to handle blast+ executions without the need of temporary files,
|
28
39
|
it has been developed at [SCBI](http://www.scbi.uma.es) by Almudena Bocinos & Dario Guerrero.
|
@@ -53,9 +64,11 @@ files:
|
|
53
64
|
- test/blast.txt
|
54
65
|
- lib/scbi_blast/blast_hit.rb
|
55
66
|
- lib/scbi_blast/blast_query.rb
|
67
|
+
- lib/scbi_blast/blast_result.rb
|
56
68
|
- lib/scbi_blast/blast_table_result.rb
|
57
69
|
- lib/scbi_blast/blast_xml_result.rb
|
58
70
|
- lib/scbi_blast/blast_simplexml_result.rb
|
71
|
+
- lib/scbi_blast/blast_streamxml_result.rb
|
59
72
|
- lib/scbi_blast/batch_blast.rb
|
60
73
|
- lib/scbi_blast/dust_masker.rb
|
61
74
|
homepage: http://www.scbi.uma.es/downloads
|