line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# BioPerl module for Bio::SearchIO::psl |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Please direct questions and support issues to |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Cared for by Jason Stajich |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# Copyright Jason Stajich |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# You may distribute this module under the same terms as perl itself |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# POD documentation - main docs before the code |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Bio::SearchIO::psl - A parser for PSL output (UCSC) |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Bio::SearchIO; |
21
|
|
|
|
|
|
|
my $parser = Bio::SearchIO->new(-file => 'file.psl', |
22
|
|
|
|
|
|
|
-format => 'psl'); |
23
|
|
|
|
|
|
|
while( my $result = $parser->next_result ) { |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
This is a SearchIO driver for PSL format. |
29
|
|
|
|
|
|
|
PSL format is documented here: |
30
|
|
|
|
|
|
|
http://genome.ucsc.edu/goldenPath/help/customTrack.html#PSL |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
By default it assumes PSL output came from BLAT you can override that |
33
|
|
|
|
|
|
|
by specifying -program_name =E 'BLASTZ' when initializing the |
34
|
|
|
|
|
|
|
SearchIO object. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 FEEDBACK |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 Mailing Lists |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
User feedback is an integral part of the evolution of this and other |
41
|
|
|
|
|
|
|
Bioperl modules. Send your comments and suggestions preferably to |
42
|
|
|
|
|
|
|
the Bioperl mailing list. Your participation is much appreciated. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
bioperl-l@bioperl.org - General discussion |
45
|
|
|
|
|
|
|
http://bioperl.org/wiki/Mailing_lists - About the mailing lists |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 Support |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Please direct usage questions or support issues to the mailing list: |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
I |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
rather than to the module maintainer directly. Many experienced and |
54
|
|
|
|
|
|
|
reponsive experts will be able look at the problem and quickly |
55
|
|
|
|
|
|
|
address it. Please include a thorough description of the problem |
56
|
|
|
|
|
|
|
with code and data examples if at all possible. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 Reporting Bugs |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Report bugs to the Bioperl bug tracking system to help us keep track |
61
|
|
|
|
|
|
|
of the bugs and their resolution. Bug reports can be submitted via the |
62
|
|
|
|
|
|
|
web: |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
https://github.com/bioperl/bioperl-live/issues |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 AUTHOR - Jason Stajich |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Email jason-at-bioperl-dot-org |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 APPENDIX |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
The rest of the documentation details each of the object methods. |
73
|
|
|
|
|
|
|
Internal methods are usually preceded with a _ |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Let the code begin... |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
package Bio::SearchIO::psl; |
80
|
1
|
|
|
1
|
|
3
|
use vars qw(%MAPPING %MODEMAP $DEFAULT_WRITER_CLASS $DefaultProgramName); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
56
|
|
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
83
|
1
|
|
|
1
|
|
288
|
use Bio::Search::HSP::HSPFactory; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
84
|
1
|
|
|
1
|
|
292
|
use Bio::Search::Hit::HitFactory; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
19
|
|
85
|
1
|
|
|
1
|
|
289
|
use Bio::Search::Result::ResultFactory; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
83
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$DefaultProgramName = 'BLAT'; |
88
|
|
|
|
|
|
|
$DEFAULT_WRITER_CLASS = 'Bio::SearchIO::Writer::HitTableWriter'; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# mapping of terms to Bioperl hash keys |
91
|
|
|
|
|
|
|
%MODEMAP = ( |
92
|
|
|
|
|
|
|
'PSLOutput' => 'result', |
93
|
|
|
|
|
|
|
'Result' => 'result', |
94
|
|
|
|
|
|
|
'Hit' => 'hit', |
95
|
|
|
|
|
|
|
'Hsp' => 'hsp' |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
%MAPPING = ( |
99
|
|
|
|
|
|
|
'Hsp_bit-score' => 'HSP-bits', |
100
|
|
|
|
|
|
|
'Hsp_score' => 'HSP-score', |
101
|
|
|
|
|
|
|
'Hsp_evalue' => 'HSP-evalue', |
102
|
|
|
|
|
|
|
'Hsp_query-from' => 'HSP-query_start', |
103
|
|
|
|
|
|
|
'Hsp_query-to' => 'HSP-query_end', |
104
|
|
|
|
|
|
|
'Hsp_hit-from' => 'HSP-hit_start', |
105
|
|
|
|
|
|
|
'Hsp_hit-to' => 'HSP-hit_end', |
106
|
|
|
|
|
|
|
'Hsp_positive' => 'HSP-conserved', |
107
|
|
|
|
|
|
|
'Hsp_identity' => 'HSP-identical', |
108
|
|
|
|
|
|
|
'Hsp_mismatches' => 'HSP-mismatches', |
109
|
|
|
|
|
|
|
'Hsp_qgapblocks' => 'HSP-query_gapblocks', |
110
|
|
|
|
|
|
|
'Hsp_hgapblocks' => 'HSP-hit_gapblocks', |
111
|
|
|
|
|
|
|
'Hsp_gaps' => 'HSP-hsp_gaps', |
112
|
|
|
|
|
|
|
'Hsp_hitgaps' => 'HSP-hit_gaps', |
113
|
|
|
|
|
|
|
'Hsp_querygaps' => 'HSP-query_gaps', |
114
|
|
|
|
|
|
|
'Hsp_align-len' => 'HSP-hsp_length', |
115
|
|
|
|
|
|
|
'Hsp_query-frame' => 'HSP-query_frame', |
116
|
|
|
|
|
|
|
'Hsp_hit-frame' => 'HSP-hit_frame', |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
'Hit_id' => 'HIT-name', |
119
|
|
|
|
|
|
|
'Hit_len' => 'HIT-length', |
120
|
|
|
|
|
|
|
'Hit_accession' => 'HIT-accession', |
121
|
|
|
|
|
|
|
'Hit_def' => 'HIT-description', |
122
|
|
|
|
|
|
|
'Hit_signif' => 'HIT-significance', |
123
|
|
|
|
|
|
|
'Hit_score' => 'HIT-score', |
124
|
|
|
|
|
|
|
'Hit_bits' => 'HIT-bits', |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
'PSLOutput_program' => 'RESULT-algorithm_name', |
127
|
|
|
|
|
|
|
'PSLOutput_version' => 'RESULT-algorithm_version', |
128
|
|
|
|
|
|
|
'PSLOutput_query-def' => 'RESULT-query_name', |
129
|
|
|
|
|
|
|
'PSLOutput_query-len' => 'RESULT-query_length', |
130
|
|
|
|
|
|
|
'PSLOutput_query-acc' => 'RESULT-query_accession', |
131
|
|
|
|
|
|
|
'PSLOutput_querydesc' => 'RESULT-query_description', |
132
|
|
|
|
|
|
|
'PSLOutput_db' => 'RESULT-database_name', |
133
|
|
|
|
|
|
|
'PSLOutput_db-len' => 'RESULT-database_entries', |
134
|
|
|
|
|
|
|
'PSLOutput_db-let' => 'RESULT-database_letters', |
135
|
|
|
|
|
|
|
); |
136
|
|
|
|
|
|
|
|
137
|
1
|
|
|
1
|
|
4
|
use base qw(Bio::SearchIO); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1336
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 new |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Title : new |
142
|
|
|
|
|
|
|
Usage : my $obj = Bio::SearchIO::psl->new(); |
143
|
|
|
|
|
|
|
Function: Builds a new Bio::SearchIO::psl object |
144
|
|
|
|
|
|
|
Returns : an instance of Bio::SearchIO::psl |
145
|
|
|
|
|
|
|
Args : |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub _initialize { |
151
|
3
|
|
|
3
|
|
4
|
my ( $self, @args ) = @_; |
152
|
3
|
|
|
|
|
10
|
$self->SUPER::_initialize(@args); |
153
|
3
|
|
|
|
|
9
|
my ($pname) = $self->_rearrange( [qw(PROGRAM_NAME)], @args ); |
154
|
3
|
|
33
|
|
|
14
|
$self->program_name( $pname || $DefaultProgramName ); |
155
|
3
|
|
|
|
|
9
|
$self->_eventHandler->register_factory( |
156
|
|
|
|
|
|
|
'result', |
157
|
|
|
|
|
|
|
Bio::Search::Result::ResultFactory->new( |
158
|
|
|
|
|
|
|
-type => 'Bio::Search::Result::GenericResult' |
159
|
|
|
|
|
|
|
) |
160
|
|
|
|
|
|
|
); |
161
|
|
|
|
|
|
|
|
162
|
3
|
|
|
|
|
6
|
$self->_eventHandler->register_factory( |
163
|
|
|
|
|
|
|
'hit', |
164
|
|
|
|
|
|
|
Bio::Search::Hit::HitFactory->new( |
165
|
|
|
|
|
|
|
-type => 'Bio::Search::Hit::GenericHit' |
166
|
|
|
|
|
|
|
) |
167
|
|
|
|
|
|
|
); |
168
|
3
|
|
|
|
|
5
|
$self->_eventHandler->register_factory( |
169
|
|
|
|
|
|
|
'hsp', |
170
|
|
|
|
|
|
|
Bio::Search::HSP::HSPFactory->new( |
171
|
|
|
|
|
|
|
-type => 'Bio::Search::HSP::PSLHSP' |
172
|
|
|
|
|
|
|
) |
173
|
|
|
|
|
|
|
); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 next_result |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Title : next_result |
179
|
|
|
|
|
|
|
Usage : my $result = $parser->next_result |
180
|
|
|
|
|
|
|
Function: Parse the next result from the data stream |
181
|
|
|
|
|
|
|
Returns : L or undef if no more results |
182
|
|
|
|
|
|
|
Args : none |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub next_result { |
187
|
4
|
|
|
4
|
1
|
45
|
my ($self) = @_; |
188
|
4
|
|
|
|
|
5
|
my ( $lastquery, $lasthit ); |
189
|
4
|
|
|
|
|
12
|
local $/ = "\n"; |
190
|
4
|
|
|
|
|
4
|
local $_; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
# skip over any header lines |
193
|
4
|
|
100
|
|
|
30
|
while( defined($_ = $self->_readline) and ! /^\d+\s+\d+\s+/ ) {} |
194
|
4
|
|
|
|
|
13
|
$self->_pushback($_); |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
# now start the main parsing loop |
197
|
4
|
|
|
|
|
7
|
while ( defined( $_ = $self->_readline ) ) { |
198
|
|
|
|
|
|
|
my ( |
199
|
6
|
|
|
|
|
36
|
$matches, $mismatches, $rep_matches, $n_count, |
200
|
|
|
|
|
|
|
$q_num_insert, $q_base_insert, $t_num_insert, $t_base_insert, |
201
|
|
|
|
|
|
|
$strand, $q_name, $q_length, $q_start, |
202
|
|
|
|
|
|
|
$q_end, $t_name, $t_length, $t_start, |
203
|
|
|
|
|
|
|
$t_end, $block_count, $block_sizes, $q_starts, |
204
|
|
|
|
|
|
|
$t_starts |
205
|
|
|
|
|
|
|
) = split; |
206
|
|
|
|
|
|
|
|
207
|
6
|
50
|
|
|
|
17
|
$q_length > 0 or $self->throw("parse error, invalid query length '$q_length'"); |
208
|
6
|
|
|
|
|
62
|
my $score = sprintf( "%.2f", 100 * ( $matches + $mismatches + $rep_matches ) / $q_length ); |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
# this is overall percent identity... |
211
|
6
|
|
|
|
|
7
|
my $match_total = $matches + $mismatches + $rep_matches; |
212
|
6
|
50
|
|
|
|
10
|
$match_total > 0 |
213
|
|
|
|
|
|
|
or $self->throw("parse error, matches + mismatches + rep_matches must be > 0!"); |
214
|
6
|
|
|
|
|
21
|
my $percent_id = sprintf("%.2f", 100 * ( $matches + $rep_matches ) / $match_total ); |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
# Remember Jim's code is 0 based |
217
|
6
|
100
|
100
|
|
|
29
|
if ( defined $lastquery |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
218
|
|
|
|
|
|
|
&& $lastquery ne $q_name ) |
219
|
|
|
|
|
|
|
{ |
220
|
1
|
|
|
|
|
4
|
$self->end_element( { 'Name' => 'Hit' } ); |
221
|
1
|
|
|
|
|
4
|
$self->end_element( { 'Name' => 'PSLOutput' } ); |
222
|
1
|
|
|
|
|
4
|
$self->_pushback($_); |
223
|
1
|
|
|
|
|
3
|
return $self->end_document; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
elsif ( !defined $lastquery ) { |
226
|
2
|
|
|
|
|
4
|
$self->{'_result_count'}++; |
227
|
2
|
|
|
|
|
9
|
$self->start_element( { 'Name' => 'PSLOutput' } ); |
228
|
2
|
|
|
|
|
7
|
$self->element( |
229
|
|
|
|
|
|
|
{ |
230
|
|
|
|
|
|
|
'Name' => 'PSLOutput_program', |
231
|
|
|
|
|
|
|
'Data' => $self->program_name |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
); |
234
|
2
|
|
|
|
|
9
|
$self->element( |
235
|
|
|
|
|
|
|
{ |
236
|
|
|
|
|
|
|
'Name' => 'PSLOutput_query-def', |
237
|
|
|
|
|
|
|
'Data' => $q_name |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
); |
240
|
2
|
|
|
|
|
11
|
$self->element( |
241
|
|
|
|
|
|
|
{ |
242
|
|
|
|
|
|
|
'Name' => 'PSLOutput_query-len', |
243
|
|
|
|
|
|
|
'Data' => $q_length |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
); |
246
|
2
|
|
|
|
|
5
|
$self->start_element( { 'Name' => 'Hit' } ); |
247
|
2
|
|
|
|
|
5
|
$self->element( |
248
|
|
|
|
|
|
|
{ |
249
|
|
|
|
|
|
|
'Name' => 'Hit_id', |
250
|
|
|
|
|
|
|
'Data' => $t_name |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
); |
253
|
2
|
|
|
|
|
7
|
$self->element( |
254
|
|
|
|
|
|
|
{ |
255
|
|
|
|
|
|
|
'Name' => 'Hit_len', |
256
|
|
|
|
|
|
|
'Data' => $t_length |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
); |
259
|
2
|
|
|
|
|
6
|
$self->element( |
260
|
|
|
|
|
|
|
{ |
261
|
|
|
|
|
|
|
'Name' => 'Hit_score', |
262
|
|
|
|
|
|
|
'Data' => $score |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
); |
265
|
|
|
|
|
|
|
} |
266
|
|
|
|
|
|
|
elsif ( $lasthit ne $t_name ) { |
267
|
0
|
|
|
|
|
0
|
$self->end_element( { 'Name' => 'Hit' } ); |
268
|
0
|
|
|
|
|
0
|
$self->start_element( { 'Name' => 'Hit' } ); |
269
|
0
|
|
|
|
|
0
|
$self->element( |
270
|
|
|
|
|
|
|
{ |
271
|
|
|
|
|
|
|
'Name' => 'Hit_id', |
272
|
|
|
|
|
|
|
'Data' => $t_name |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
); |
275
|
0
|
|
|
|
|
0
|
$self->element( |
276
|
|
|
|
|
|
|
{ |
277
|
|
|
|
|
|
|
'Name' => 'Hit_len', |
278
|
|
|
|
|
|
|
'Data' => $t_length |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
); |
281
|
0
|
|
|
|
|
0
|
$self->element( |
282
|
|
|
|
|
|
|
{ |
283
|
|
|
|
|
|
|
'Name' => 'Hit_score', |
284
|
|
|
|
|
|
|
'Data' => $score |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
); |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
|
289
|
5
|
|
|
|
|
6
|
my $identical = $matches + $rep_matches; |
290
|
5
|
|
|
|
|
13
|
$self->start_element( { 'Name' => 'Hsp' } ); |
291
|
5
|
|
|
|
|
15
|
$self->element( |
292
|
|
|
|
|
|
|
{ |
293
|
|
|
|
|
|
|
'Name' => 'Hsp_score', |
294
|
|
|
|
|
|
|
'Data' => $score |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
); |
297
|
5
|
|
|
|
|
11
|
$self->element( |
298
|
|
|
|
|
|
|
{ |
299
|
|
|
|
|
|
|
'Name' => 'Hsp_identity', |
300
|
|
|
|
|
|
|
'Data' => $identical |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
); |
303
|
5
|
|
|
|
|
11
|
$self->element( |
304
|
|
|
|
|
|
|
{ |
305
|
|
|
|
|
|
|
'Name' => 'Hsp_positive', |
306
|
|
|
|
|
|
|
'Data' => $identical |
307
|
|
|
|
|
|
|
} |
308
|
|
|
|
|
|
|
); |
309
|
5
|
|
|
|
|
14
|
$self->element( |
310
|
|
|
|
|
|
|
{ |
311
|
|
|
|
|
|
|
'Name' => 'Hsp_mismatches', |
312
|
|
|
|
|
|
|
'Data' => $mismatches |
313
|
|
|
|
|
|
|
} |
314
|
|
|
|
|
|
|
); |
315
|
5
|
|
|
|
|
19
|
$self->element( |
316
|
|
|
|
|
|
|
{ |
317
|
|
|
|
|
|
|
'Name' => 'Hsp_gaps', |
318
|
|
|
|
|
|
|
'Data' => $q_base_insert + $t_base_insert |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
); |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
# query gaps are the number of target inserts and vice-versa |
323
|
5
|
|
|
|
|
15
|
$self->element( |
324
|
|
|
|
|
|
|
{ |
325
|
|
|
|
|
|
|
'Name' => 'Hsp_querygaps', |
326
|
|
|
|
|
|
|
'Data' => $t_base_insert |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
); |
329
|
5
|
|
|
|
|
12
|
$self->element( |
330
|
|
|
|
|
|
|
{ |
331
|
|
|
|
|
|
|
'Name' => 'Hsp_hitgaps', |
332
|
|
|
|
|
|
|
'Data' => $q_base_insert |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
); |
335
|
5
|
100
|
|
|
|
11
|
if ( $strand eq '+' ) { |
336
|
3
|
|
|
|
|
9
|
$self->element( |
337
|
|
|
|
|
|
|
{ |
338
|
|
|
|
|
|
|
'Name' => 'Hsp_query-from', |
339
|
|
|
|
|
|
|
'Data' => $q_start + 1 |
340
|
|
|
|
|
|
|
} |
341
|
|
|
|
|
|
|
); |
342
|
3
|
|
|
|
|
9
|
$self->element( |
343
|
|
|
|
|
|
|
{ |
344
|
|
|
|
|
|
|
'Name' => 'Hsp_query-to', |
345
|
|
|
|
|
|
|
'Data' => $q_end |
346
|
|
|
|
|
|
|
} |
347
|
|
|
|
|
|
|
); |
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
else { |
350
|
2
|
|
|
|
|
7
|
$self->element( |
351
|
|
|
|
|
|
|
{ |
352
|
|
|
|
|
|
|
'Name' => 'Hsp_query-to', |
353
|
|
|
|
|
|
|
'Data' => $q_start + 1 |
354
|
|
|
|
|
|
|
} |
355
|
|
|
|
|
|
|
); |
356
|
2
|
|
|
|
|
6
|
$self->element( |
357
|
|
|
|
|
|
|
{ |
358
|
|
|
|
|
|
|
'Name' => 'Hsp_query-from', |
359
|
|
|
|
|
|
|
'Data' => $q_end |
360
|
|
|
|
|
|
|
} |
361
|
|
|
|
|
|
|
); |
362
|
|
|
|
|
|
|
} |
363
|
|
|
|
|
|
|
|
364
|
5
|
|
|
|
|
16
|
my $hsplen = |
365
|
|
|
|
|
|
|
($q_base_insert + |
366
|
|
|
|
|
|
|
$t_base_insert + |
367
|
|
|
|
|
|
|
abs( $t_end - $t_start ) + |
368
|
|
|
|
|
|
|
abs( $q_end - $q_start ))/2; |
369
|
|
|
|
|
|
|
|
370
|
5
|
|
|
|
|
16
|
$self->element( |
371
|
|
|
|
|
|
|
{ |
372
|
|
|
|
|
|
|
'Name' => 'Hsp_hit-from', |
373
|
|
|
|
|
|
|
'Data' => $t_start + 1 |
374
|
|
|
|
|
|
|
} |
375
|
|
|
|
|
|
|
); |
376
|
5
|
|
|
|
|
14
|
$self->element( |
377
|
|
|
|
|
|
|
{ |
378
|
|
|
|
|
|
|
'Name' => 'Hsp_hit-to', |
379
|
|
|
|
|
|
|
'Data' => $t_end |
380
|
|
|
|
|
|
|
} |
381
|
|
|
|
|
|
|
); |
382
|
5
|
|
|
|
|
12
|
$self->element( |
383
|
|
|
|
|
|
|
{ |
384
|
|
|
|
|
|
|
'Name' => 'Hsp_align-len', |
385
|
|
|
|
|
|
|
'Data' => $hsplen |
386
|
|
|
|
|
|
|
} |
387
|
|
|
|
|
|
|
); |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
# cleanup trailing commas in some output |
390
|
5
|
|
|
|
|
16
|
$block_sizes =~ s/\,$//; |
391
|
5
|
|
|
|
|
12
|
$q_starts =~ s/\,$//; |
392
|
5
|
|
|
|
|
8
|
$t_starts =~ s/\,$//; |
393
|
5
|
|
|
|
|
17
|
my @blocksizes = split( /,/, $block_sizes ); # block sizes |
394
|
5
|
|
|
|
|
15
|
my @qstarts = split( /,/, $q_starts ); # starting position of each block |
395
|
|
|
|
|
|
|
# in query |
396
|
5
|
|
|
|
|
12
|
my @tstarts = split( /,/, $t_starts ); # starting position of each block |
397
|
|
|
|
|
|
|
# in target |
398
|
5
|
|
|
|
|
4
|
my ( @qgapblocks, @hgapblocks ); |
399
|
|
|
|
|
|
|
|
400
|
5
|
|
|
|
|
14
|
for ( my $i = 0 ; $i < $block_count ; $i++ ) { |
401
|
38
|
100
|
|
|
|
35
|
if ( $strand eq '+' ) { |
402
|
30
|
|
|
|
|
53
|
push @qgapblocks, [ $qstarts[$i] + 1, $blocksizes[$i] ]; |
403
|
|
|
|
|
|
|
} |
404
|
|
|
|
|
|
|
else { |
405
|
8
|
|
|
|
|
16
|
push @qgapblocks, [ $q_length - $qstarts[$i], $blocksizes[$i] ]; |
406
|
|
|
|
|
|
|
} |
407
|
38
|
|
|
|
|
77
|
push @hgapblocks, [ $tstarts[$i] + 1, $blocksizes[$i] ]; |
408
|
|
|
|
|
|
|
} |
409
|
5
|
|
|
|
|
13
|
$self->element( |
410
|
|
|
|
|
|
|
{ |
411
|
|
|
|
|
|
|
'Name' => 'Hsp_qgapblocks', |
412
|
|
|
|
|
|
|
'Data' => \@qgapblocks |
413
|
|
|
|
|
|
|
} |
414
|
|
|
|
|
|
|
); |
415
|
5
|
|
|
|
|
16
|
$self->element( |
416
|
|
|
|
|
|
|
{ |
417
|
|
|
|
|
|
|
'Name' => 'Hsp_hgapblocks', |
418
|
|
|
|
|
|
|
'Data' => \@hgapblocks |
419
|
|
|
|
|
|
|
} |
420
|
|
|
|
|
|
|
); |
421
|
5
|
|
|
|
|
11
|
$self->end_element( { 'Name' => 'Hsp' } ); |
422
|
5
|
|
|
|
|
6
|
$lastquery = $q_name; |
423
|
5
|
|
|
|
|
22
|
$lasthit = $t_name; |
424
|
|
|
|
|
|
|
} |
425
|
3
|
100
|
66
|
|
|
20
|
if ( defined $lasthit || defined $lastquery ) { |
426
|
1
|
|
|
|
|
3
|
$self->end_element( { 'Name' => 'Hit' } ); |
427
|
1
|
|
|
|
|
3
|
$self->end_element( { 'Name' => 'Result' } ); |
428
|
1
|
|
|
|
|
4
|
return $self->end_document; |
429
|
|
|
|
|
|
|
} |
430
|
|
|
|
|
|
|
} |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
=head2 start_element |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
Title : start_element |
435
|
|
|
|
|
|
|
Usage : $eventgenerator->start_element |
436
|
|
|
|
|
|
|
Function: Handles a start element event |
437
|
|
|
|
|
|
|
Returns : none |
438
|
|
|
|
|
|
|
Args : hashref with at least 2 keys 'Data' and 'Name' |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
=cut |
442
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
sub start_element { |
444
|
91
|
|
|
91
|
1
|
59
|
my ( $self, $data ) = @_; |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
# we currently don't care about attributes |
447
|
91
|
|
|
|
|
60
|
my $nm = $data->{'Name'}; |
448
|
91
|
100
|
|
|
|
133
|
if ( my $type = $MODEMAP{$nm} ) { |
449
|
9
|
|
|
|
|
14
|
$self->_mode($type); |
450
|
9
|
50
|
|
|
|
18
|
if ( $self->_eventHandler->will_handle($type) ) { |
451
|
9
|
|
|
|
|
12
|
my $func = 'start_'.lc $type; |
452
|
9
|
|
|
|
|
15
|
$self->_eventHandler->$func( $data->{'Attributes'} ); |
453
|
|
|
|
|
|
|
} |
454
|
9
|
|
|
|
|
12
|
unshift @{ $self->{'_elements'} }, $type; |
|
9
|
|
|
|
|
16
|
|
455
|
|
|
|
|
|
|
} |
456
|
91
|
100
|
|
|
|
120
|
if ( $nm eq 'PSLOutput' ) { |
457
|
2
|
|
|
|
|
4
|
$self->{'_values'} = {}; |
458
|
2
|
|
|
|
|
2
|
$self->{'_result'} = undef; |
459
|
2
|
|
|
|
|
4
|
$self->{'_mode'} = ''; |
460
|
|
|
|
|
|
|
} |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
} |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
=head2 end_element |
465
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
Title : end_element |
467
|
|
|
|
|
|
|
Usage : $eventgenerator->end_element |
468
|
|
|
|
|
|
|
Function: Handles an end element event |
469
|
|
|
|
|
|
|
Returns : return value from the associated end_$type event handler |
470
|
|
|
|
|
|
|
Args : hashref with at least 2 keys 'Data' and 'Name' |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
=cut |
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
sub end_element { |
476
|
91
|
|
|
91
|
1
|
65
|
my ( $self, $data ) = @_; |
477
|
91
|
|
|
|
|
71
|
my $nm = $data->{'Name'}; |
478
|
91
|
|
|
|
|
52
|
my $rc; |
479
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
# Hsp are sort of weird, in that they end when another |
481
|
|
|
|
|
|
|
# object begins so have to detect this in end_element for now |
482
|
|
|
|
|
|
|
|
483
|
91
|
100
|
|
|
|
159
|
if ( my $type = $MODEMAP{$nm} ) { |
|
|
50
|
|
|
|
|
|
484
|
9
|
50
|
|
|
|
15
|
if ( $self->_eventHandler->will_handle($type) ) { |
485
|
9
|
|
|
|
|
16
|
my $func = 'end_'.lc $type; |
486
|
|
|
|
|
|
|
$rc = $self->_eventHandler->$func( $self->{'_reporttype'}, |
487
|
9
|
|
|
|
|
12
|
$self->{'_values'} ); |
488
|
|
|
|
|
|
|
} |
489
|
9
|
|
|
|
|
12
|
shift @{ $self->{'_elements'} }; |
|
9
|
|
|
|
|
9
|
|
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
} |
492
|
|
|
|
|
|
|
elsif ( $MAPPING{$nm} ) { |
493
|
82
|
50
|
|
|
|
87
|
if ( ref( $MAPPING{$nm} ) =~ /hash/i ) { |
494
|
0
|
|
|
|
|
0
|
my $key = ( keys %{ $MAPPING{$nm} } )[0]; |
|
0
|
|
|
|
|
0
|
|
495
|
|
|
|
|
|
|
$self->{'_values'}->{$key}->{ $MAPPING{$nm}->{$key} } = |
496
|
0
|
|
|
|
|
0
|
$self->{'_last_data'}; |
497
|
|
|
|
|
|
|
} |
498
|
|
|
|
|
|
|
else { |
499
|
82
|
|
|
|
|
129
|
$self->{'_values'}->{ $MAPPING{$nm} } = $self->{'_last_data'}; |
500
|
|
|
|
|
|
|
} |
501
|
|
|
|
|
|
|
} |
502
|
|
|
|
|
|
|
else { |
503
|
0
|
|
|
|
|
0
|
$self->warn( |
504
|
|
|
|
|
|
|
__PACKAGE__ . "::end_element: unknown nm '$nm', ignoring\n" ); |
505
|
|
|
|
|
|
|
} |
506
|
91
|
|
|
|
|
71
|
$self->{'_last_data'} = ''; # remove read data if we are at |
507
|
|
|
|
|
|
|
# end of an element |
508
|
|
|
|
|
|
|
$self->{'_result'} = $rc |
509
|
|
|
|
|
|
|
if ( defined $nm |
510
|
|
|
|
|
|
|
&& defined $MODEMAP{$nm} |
511
|
91
|
100
|
66
|
|
|
278
|
&& $MODEMAP{$nm} eq 'result' ); |
|
|
|
100
|
|
|
|
|
512
|
91
|
|
|
|
|
103
|
return $rc; |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
} |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
=head2 element |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
Title : element |
519
|
|
|
|
|
|
|
Usage : $eventhandler->element({'Name' => $name, 'Data' => $str}); |
520
|
|
|
|
|
|
|
Function: Convience method that calls start_element, characters, end_element |
521
|
|
|
|
|
|
|
Returns : none |
522
|
|
|
|
|
|
|
Args : Hash ref with the keys 'Name' and 'Data' |
523
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
=cut |
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
sub element { |
528
|
82
|
|
|
82
|
1
|
55
|
my ( $self, $data ) = @_; |
529
|
82
|
|
|
|
|
79
|
$self->start_element($data); |
530
|
82
|
|
|
|
|
74
|
$self->characters($data); |
531
|
82
|
|
|
|
|
83
|
$self->end_element($data); |
532
|
|
|
|
|
|
|
} |
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
=head2 characters |
535
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
Title : characters |
537
|
|
|
|
|
|
|
Usage : $eventgenerator->characters($str) |
538
|
|
|
|
|
|
|
Function: Send a character events |
539
|
|
|
|
|
|
|
Returns : none |
540
|
|
|
|
|
|
|
Args : string |
541
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
=cut |
544
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
sub characters { |
546
|
82
|
|
|
82
|
1
|
53
|
my ( $self, $data ) = @_; |
547
|
|
|
|
|
|
|
|
548
|
82
|
50
|
|
|
|
100
|
return unless ( defined $data->{'Data'} ); |
549
|
82
|
50
|
|
|
|
167
|
if ( $data->{'Data'} =~ /^\s+$/ ) { |
550
|
0
|
0
|
|
|
|
0
|
return unless $data->{'Name'} =~ /Hsp\_(midline|qseq|hseq)/; |
551
|
|
|
|
|
|
|
} |
552
|
|
|
|
|
|
|
|
553
|
82
|
50
|
66
|
|
|
85
|
if ( $self->in_element('hsp') |
554
|
|
|
|
|
|
|
&& $data->{'Name'} =~ /Hsp\_(qseq|hseq|midline)/ ) |
555
|
|
|
|
|
|
|
{ |
556
|
|
|
|
|
|
|
|
557
|
0
|
|
|
|
|
0
|
$self->{'_last_hspdata'}->{ $data->{'Name'} } .= $data->{'Data'}; |
558
|
|
|
|
|
|
|
} |
559
|
|
|
|
|
|
|
|
560
|
82
|
|
|
|
|
93
|
$self->{'_last_data'} = $data->{'Data'}; |
561
|
|
|
|
|
|
|
} |
562
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
=head2 _mode |
564
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
Title : _mode |
566
|
|
|
|
|
|
|
Usage : $obj->_mode($newval) |
567
|
|
|
|
|
|
|
Function: |
568
|
|
|
|
|
|
|
Example : |
569
|
|
|
|
|
|
|
Returns : value of _mode |
570
|
|
|
|
|
|
|
Args : newvalue (optional) |
571
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
|
573
|
|
|
|
|
|
|
=cut |
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
sub _mode { |
576
|
9
|
|
|
9
|
|
7
|
my ( $self, $value ) = @_; |
577
|
9
|
50
|
|
|
|
14
|
if ( defined $value ) { |
578
|
9
|
|
|
|
|
8
|
$self->{'_mode'} = $value; |
579
|
|
|
|
|
|
|
} |
580
|
9
|
|
|
|
|
9
|
return $self->{'_mode'}; |
581
|
|
|
|
|
|
|
} |
582
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
=head2 within_element |
584
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
Title : within_element |
586
|
|
|
|
|
|
|
Usage : if( $eventgenerator->within_element($element) ) {} |
587
|
|
|
|
|
|
|
Function: Test if we are within a particular element |
588
|
|
|
|
|
|
|
This is different than 'in' because within can be tested |
589
|
|
|
|
|
|
|
for a whole block. |
590
|
|
|
|
|
|
|
Returns : boolean |
591
|
|
|
|
|
|
|
Args : string element name |
592
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
=cut |
595
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
sub within_element { |
597
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $name ) = @_; |
598
|
|
|
|
|
|
|
return 0 |
599
|
|
|
|
|
|
|
if (!defined $name && !defined $self->{'_elements'} |
600
|
0
|
0
|
0
|
|
|
0
|
|| scalar @{ $self->{'_elements'} } == 0 ); |
|
0
|
|
0
|
|
|
0
|
|
601
|
0
|
|
|
|
|
0
|
foreach ( @{ $self->{'_elements'} } ) { |
|
0
|
|
|
|
|
0
|
|
602
|
0
|
0
|
|
|
|
0
|
if ( $_ eq $name ) { |
603
|
0
|
|
|
|
|
0
|
return 1; |
604
|
|
|
|
|
|
|
} |
605
|
|
|
|
|
|
|
} |
606
|
0
|
|
|
|
|
0
|
return 0; |
607
|
|
|
|
|
|
|
} |
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
=head2 in_element |
610
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
Title : in_element |
612
|
|
|
|
|
|
|
Usage : if( $eventgenerator->in_element($element) ) {} |
613
|
|
|
|
|
|
|
Function: Test if we are in a particular element |
614
|
|
|
|
|
|
|
This is different than 'in' because within can be tested |
615
|
|
|
|
|
|
|
for a whole block. |
616
|
|
|
|
|
|
|
Returns : boolean |
617
|
|
|
|
|
|
|
Args : string element name |
618
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
=cut |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
sub in_element { |
623
|
82
|
|
|
82
|
1
|
79
|
my ( $self, $name ) = @_; |
624
|
82
|
50
|
|
|
|
101
|
return 0 if !defined $self->{'_elements'}->[0]; |
625
|
82
|
|
|
|
|
286
|
return ( $self->{'_elements'}->[0] eq $name ); |
626
|
|
|
|
|
|
|
} |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
=head2 start_document |
629
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
Title : start_document |
631
|
|
|
|
|
|
|
Usage : $eventgenerator->start_document |
632
|
|
|
|
|
|
|
Function: Handles a start document event |
633
|
|
|
|
|
|
|
Returns : none |
634
|
|
|
|
|
|
|
Args : none |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
=cut |
638
|
|
|
|
|
|
|
|
639
|
|
|
|
|
|
|
sub start_document { |
640
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
641
|
0
|
|
|
|
|
0
|
$self->{'_lasttype'} = ''; |
642
|
0
|
|
|
|
|
0
|
$self->{'_values'} = {}; |
643
|
0
|
|
|
|
|
0
|
$self->{'_result'} = undef; |
644
|
0
|
|
|
|
|
0
|
$self->{'_mode'} = ''; |
645
|
0
|
|
|
|
|
0
|
$self->{'_elements'} = []; |
646
|
|
|
|
|
|
|
} |
647
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
=head2 end_document |
649
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
Title : end_document |
651
|
|
|
|
|
|
|
Usage : $eventgenerator->end_document |
652
|
|
|
|
|
|
|
Function: Handles an end document event |
653
|
|
|
|
|
|
|
Returns : Bio::Search::Result::ResultI object |
654
|
|
|
|
|
|
|
Args : none |
655
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
=cut |
658
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
sub end_document { |
660
|
2
|
|
|
2
|
1
|
4
|
my ( $self, @args ) = @_; |
661
|
2
|
|
|
|
|
9
|
return $self->{'_result'}; |
662
|
|
|
|
|
|
|
} |
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
=head2 result_count |
665
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
Title : result_count |
667
|
|
|
|
|
|
|
Usage : my $count = $searchio->result_count |
668
|
|
|
|
|
|
|
Function: Returns the number of results we have processed |
669
|
|
|
|
|
|
|
Returns : integer |
670
|
|
|
|
|
|
|
Args : none |
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
=cut |
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
sub result_count { |
676
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
677
|
0
|
|
|
|
|
0
|
return $self->{'_result_count'}; |
678
|
|
|
|
|
|
|
} |
679
|
|
|
|
|
|
|
|
680
|
0
|
|
|
0
|
0
|
0
|
sub report_count { shift->result_count } |
681
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
=head2 program_name |
683
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
Title : program_name |
685
|
|
|
|
|
|
|
Usage : $obj->program_name($newval) |
686
|
|
|
|
|
|
|
Function: Get/Set the program name |
687
|
|
|
|
|
|
|
Returns : value of program_name (a scalar) |
688
|
|
|
|
|
|
|
Args : on set, new value (a scalar or undef, optional) |
689
|
|
|
|
|
|
|
|
690
|
|
|
|
|
|
|
|
691
|
|
|
|
|
|
|
=cut |
692
|
|
|
|
|
|
|
|
693
|
|
|
|
|
|
|
sub program_name { |
694
|
5
|
|
|
5
|
1
|
6
|
my $self = shift; |
695
|
|
|
|
|
|
|
|
696
|
5
|
100
|
|
|
|
12
|
$self->{'program_name'} = shift if @_; |
697
|
5
|
|
50
|
|
|
17
|
return $self->{'program_name'} || $DefaultProgramName; |
698
|
|
|
|
|
|
|
} |
699
|
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
1; |