FAST/Bio/SearchIO/cross_match.pm untested

filter: Statementstmt 0.0% 0 / 95 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 181 CC 25 SCAR 44.9
CC
25
Cov
0%
next_result
156.0
_alignment
90.0
_parse
42.0
CRAP 89.3
1 #
2 # BioPerl module for FAST::Bio::SearchIO::cross_match
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Shin Leong <sleong@watson.wustl.edu>
7 #
8 # Copyright Shin Leong
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 FAST::Bio::SearchIO::cross_match - CrossMatch-specific subclass of FAST::Bio::SearchIO
17  
18 =head1 SYNOPSIS
19  
20 # Working with iterations (CrossMatch results)
21 my $searchIO = FAST::Bio::SearchIO->new( -format => 'cross_match',
22 -file => "$file.screen.out" )
23 while(my $r = $searchIO->next_result) {
24 while(my $hit = $r->next_hit) {
25 while(my $hsp = $hit->next_hsp) {
26 #Do the processing here.
27 }
28 }
29 }
30 # See FAST::Bio::SearchIO for information about working with Results.
31  
32 # See L<FAST::Bio::SearchIO>
33 # for details about working with FAST::Bio::SearchIO.
34  
35  
36 =head1 DESCRIPTION
37  
38 This object is a subclass of FAST::Bio::SearchIO
39 and provides some operations that facilitate working with CrossMatch
40 and CrossMatch results.
41  
42 For general information about working with Results, see
43 L<FAST::Bio::Search::Result::GenericResult>.
44  
45 =head1 FEEDBACK
46  
47 =head2 Mailing Lists
48  
49 User feedback is an integral part of the evolution of this and other
50 Bioperl modules. Send your comments and suggestions preferably to
51 the Bioperl mailing list. Your participation is much appreciated.
52  
53 bioperl-l@bioperl.org - General discussion
54 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
55  
56 =head2 Support
57  
58 Please direct usage questions or support issues to the mailing list:
59  
60 I<bioperl-l@bioperl.org>
61  
62 rather than to the module maintainer directly. Many experienced and
63 reponsive experts will be able look at the problem and quickly
64 address it. Please include a thorough description of the problem
65 with code and data examples if at all possible.
66  
67 =head2 Reporting Bugs
68  
69 Report bugs to the Bioperl bug tracking system to help us keep track
70 of the bugs and their resolution. Bug reports can be submitted via the
71 web:
72  
73 https://redmine.open-bio.org/projects/bioperl/
74  
75 =head1 AUTHOR - Shin Leong
76  
77 Email sleong@watson.wustl.edu
78  
79 =head1 CONTRIBUTORS
80  
81 Additional contributors names and emails here
82  
83 =head1 APPENDIX
84  
85 The rest of the documentation details each of the object methods.
86 Internal methods are usually preceded with a _
87  
88 =cut
89  
90  
91 # Let the code begin...
92  
93 package FAST::Bio::SearchIO::cross_match;
94 use FAST::Bio::Search::Result::CrossMatchResult;
95 use FAST::Bio::SearchIO;
96 use FAST::Bio::Search::Hit::GenericHit;
97 use FAST::Bio::Search::HSP::GenericHSP;
98 use base qw(FAST::Bio::SearchIO);
99  
100 =head2 next_result
101  
102 Title : next_result
103 Usage : $result = stream->next_result
104 Function: Reads the next ResultI object from the stream and returns it.
105  
106 Certain driver modules may encounter entries in the stream that
107 are either misformatted or that use syntax not yet understood
108 by the driver. If such an incident is recoverable, e.g., by
109 dismissing a feature of a feature table or some other non-mandatory
110 part of an entry, the driver will issue a warning. In the case
111 of a non-recoverable situation an exception will be thrown.
112 Do not assume that you can resume parsing the same stream after
113 catching the exception. Note that you can always turn recoverable
114 errors into exceptions by calling $stream->verbose(2) (see
115 FAST::Bio::Root::RootI POD page).
116 Returns : A FAST::Bio::Search::Result::ResultI object
117 Args : n/a
118  
119 See L<FAST::Bio::Root::RootI>
120  
121 =cut
122  
123 sub next_result {
124 my ($self) = @_;
125 my $start = 0;
126 while( defined ($_ = $self->_readline )) {
127 return if($self->{'_end_document'});
128 if(/^cross_match version\s+(.*?)$/) {
129 $self->{_algorithm_version} = $1;
130 } elsif(/^Maximal single base matches/) {
131 $start = 1;
132 } elsif(/^(\d+) matching entries/) {
133 $self->{'_end_document'} = 1;
134 return;
135 } elsif(($start || $self->{'_result_count'}) && /^\s+(\d+)/xms) {
136 $self->{'_result_count'}++;
137 return $self->_parse($_);
138 } elsif(! $self->{_parameters}) {
139 if(/.*?\s+(\-.*?)$/) {
140 my $p = $1;
141 my @pp = split /\s+/, $p;
142 for(my $i = 0; $i < @pp; $i ++) {
143 if($pp[$i] =~ /^\-/) {
144 if($pp[$i + 1] && $pp[$i + 1] !~ /^\-/) {
145 $self->{_parameters}->{$pp[$i]} = $pp[$i + 1];
146 $i ++;
147 } else {
148 $self->{_parameters}->{$pp[$i]} = "";
149 }
150 }
151 }
152 }
153 } elsif(/^Query file(s):\s+(.*?)$/) {
154 $self->{_query_name} = $1;
155 } elsif(/^Subject file(s):\s+(.*?)$/) {
156 $self->{_subject_name} = $2;
157 }
158 }
159 }
160  
161 =head2 _alignment
162  
163 Title : _alignment
164 Usage : private
165  
166 =cut
167  
168 sub _alignment {
169 my $self = shift;
170
171 # C H_EO-aaa01PCR02 243 CCTCTGAATGGCTGAAGACCCCTCTGCCGAGGGAGGTTGGGGATTGTGGG 194
172 #
173 # 0284119_008.c1- 1 CCTCTGAATGGCTGAAGACCCCTCTGCCGAGGGAGGTTGGGGATTGTGGG 50
174 #
175 # C H_EO-aaa01PCR02 193 ACAAGGTCCCTTGGTGCTGATGGCCTGAAGGGGCCTGAGCTGTGGGCAGA 144
176 #
177 # 0284119_008.c1- 51 ACAAGGTCCCTTGGTGCTGATGGCCTGAAGGGGCCTGAGCTGTGGGCAGA 100
178 #
179 # C H_EO-aaa01PCR02 143 TGCAGTTTTCTGTGGGCTTGGGGAACCTCTCACGTTGCTGTGTCCTGGTG 94
180 #
181 # 0284119_008.c1- 101 TGCAGTTTTCTGTGGGCTTGGGGAACCTCTCACGTTGCTGTGTCCTGGTG 150
182 #
183 # C H_EO-aaa01PCR02 93 AGCAGCCCGACCAATAAACCTGCTTTTCTAAAAGGATCTGTGTTTGATTG 44
184 #
185 # 0284119_008.c1- 151 AGCAGCCCGACCAATAAACCTGCTTTTCTAAAAGGATCTGTGTTTGATTG 200
186 #
187 # C H_EO-aaa01PCR02 43 TATTCTCTGAAGGCAGTTACATAGGGTTACAGAGG 9
188 #
189 # 0284119_008.c1- 201 TATTCTCTGAAGGCAGTTACATAGGGTTACAGAGG 235
190
191  
192  
193 #LSF: Should be the blank line. Otherwise error.
194 my $blank = $self->_readline;
195 unless($blank =~ /^\s*$/) {
196 return;
197 }
198 my @data;
199 my @pad;
200 $count = 0;
201 while( defined ($_ = $self->_readline )) {
202 $count = 0 if($count >= 3);
203 next if(/^$/);
204 if(/^(C \S+.*?\d+ )(\S+) \d+$|^( \S+.*?\d+ )(\S+) \d+$$|^\s+$/) {
205 $count ++;
206 if($1 || $3) {
207 $pad[$count] = $1 ? $1 : $3;
208 push @{$data[$count]}, ($2 ? $2 : $4);
209 } else {
210 if(/\s{$pad[0],$pad[0]}(.*?)$/) {
211 push @{$data[$count]}, $1;
212 } else {
213 $self->throw("Format error for the homology line [$_].");
214 }
215 }
216 } else {
217 last;
218 }
219 }
220 return @data;
221 }
222  
223 =head2 _parse
224  
225 Title : _parse
226 Usage : private
227  
228 =cut
229  
230 sub _parse {
231 my $self = shift;
232 my $line = shift;
233 my $is_alignment = 0;
234 my($hit_seq, $homology_seq, $query_seq);
235 # 32 5.13 0.00 0.00 H_DO-0065PCR0005792_034a.b1-1 327 365 (165) C 1111547847_forward (0) 39 1
236 #OR
237 #ALIGNMENT 32 5.13 0.00 0.00 H_DO-0065PCR0005792_034a.b1-1 327 365 (165) C 1111547847_forward (0) 39 1
238 $line =~ s/^\s+|\s+$//g;
239 my @r = split /\s+/, $line;
240 if($r[0] eq "ALIGNMENT") {
241 $is_alignment = 1;
242 shift @r;
243 ($hit_seq, $homology_seq, $query_seq) = $self->_alignment();
244 }
245 my $subject_seq_id;
246 my $query_seq_id = $r[4];
247 my $query_start = $r[5];
248 my $query_end = $r[6];
249 my $is_complement = 0;
250 my $subject_start;
251 my $subject_end;
252 if($r[8] eq "C" && $r[9] !~ /^\(\d+\)$/) {
253 $subject_seq_id = $r[9];
254 $is_complement = 1;
255 $subject_start = $r[11];
256 $subject_end = $r[12];
257 } else {
258 $subject_seq_id = $r[8];
259 $subject_start = $r[9];
260 $subject_end = $r[10];
261 }
262 my $hit = FAST::Bio::Search::Hit::GenericHit->new(-name => $subject_seq_id,
263 -hsps => [FAST::Bio::Search::HSP::GenericHSP->new(-query_name => $query_seq_id,
264 -query_start => $query_start,
265 -query_end => $query_end,
266 -hit_name => $subject_seq_id,
267 -hit_start => $subject_start,
268 -hit_end => $subject_end,
269 -query_length => 0,
270 -hit_length => 0,
271 -identical => $r[0],
272 -conserved => $r[0],
273 -query_seq => $query_seq ? (join "", @$query_seq) : "", #query sequence portion of the HSP
274 -hit_seq => $hit_seq ? (join "", @$hit_seq) : "", #hit sequence portion of the HSP
275 -homology_seq=> $homology_seq ? (join "", @$homology_seq) : "", #homology sequence for the HSP
276 #LSF: Need the direction, just to fool the GenericHSP module.
277 -algorithm => 'SW',)],
278 );
279 my $result = FAST::Bio::Search::Result::CrossMatchResult->new( -query_name => $self->{_query_name},
280 -query_accession => '',
281 -query_description => '',
282 -query_length => 0,
283 -database_name => $self->{_subject_name},
284 -database_letters => 0,
285 -database_entries => 0,
286 -parameters => $self->{_parameters},
287 -statistics => { },
288 -algorithm => 'cross_match',
289 -algorithm_version => $self->{_algorithm_version},
290 );
291 $result->add_hit($hit);
292 return $result;
293 }
294  
295 =head2 result_count
296  
297 Title : result_count
298 Usage : $num = $stream->result_count;
299 Function: Gets the number of CrossMatch results that have been parsed.
300 Returns : integer
301 Args : none
302 Throws : none
303  
304 =cut
305  
306 sub result_count {
307 my $self = shift;
308 return $self->{'_result_count'};
309 }
310  
311 1;
312 #$Header$