31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/scbi_blast/blast_xml_result.rb', line 31
def initialize(input)
@querys = []
lines=[]
if input.is_a?(Array)
lines=input
else
if File.exists?(input)
fich = File.open(input,'r')
lines = fich.readlines
fich.close
end
end
if !lines.empty?
data = Nokogiri::XML(lines.join)
data.root.xpath('//Iteration').each do |iteration|
query_id = iteration.xpath('Iteration_query-ID').text
full_query_length = iteration.xpath('Iteration_query-len').text
query_def = iteration.xpath('Iteration_query-def').text
if query_def =~ /^([^\s]+)/
query_def=$1
end
query = BlastQuery.new(query_id)
query.query_def = query_def
query.full_query_length = full_query_length
@querys.push query
hits = iteration.xpath('Iteration_hits/Hit')
if !hits.nil?
hits.each do |h|
subject_id=h.xpath('Hit_id').text
acc =h.xpath('Hit_accession').text
full_subject_length = h.xpath('Hit_len').text.to_i
hit_def=h.xpath('Hit_def').text
if hit_def=='No definition line'
hit_def =subject_id
end
hsps = h.xpath('Hit_hsps/Hsp')
hsps.each do |hsp|
q_beg=hsp.xpath('Hsp_query-from').text.to_i
q_end=hsp.xpath('Hsp_query-to').text.to_i
s_beg=hsp.xpath('Hsp_hit-from').text.to_i
s_end=hsp.xpath('Hsp_hit-to').text.to_i
hit = BlastHit.new(q_beg,q_end,s_beg,s_end)
hit.align_len=hsp.xpath('Hsp_align-len').text.to_i
hit.ident=(hsp.xpath('Hsp_identity').text.to_f/hit.align_len)*100
hit.gaps=hsp.xpath('Hsp_gaps').text.to_i
hit.mismatches=hsp.xpath('Hsp_midline').text.count(' ').to_i - hit.gaps
hit.e_val=hsp.xpath('Hsp_evalue').text.to_f
hit.e_val = (hit.e_val*1000).round/1000.0
hit.bit_score=hsp.xpath('Hsp_bit-score').text.to_f
hit.bit_score = (hit.bit_score*100).round/100.0
hit.score = hsp.xpath('Hsp_score').text.to_f
hit.q_frame = hsp.xpath('Hsp_query-frame').text.to_i
hit.s_frame =hsp.xpath('Hsp_hit-frame').text.to_i
hit.q_seq = hsp.xpath('Hsp_qseq').text
hit.s_seq = hsp.xpath('Hsp_hseq').text
hit.subject_id= subject_id
hit.full_subject_length=full_subject_length
hit.definition=hit_def
hit.acc=acc
query.add_hit(hit)
end
end
end
end
end
end
|