Bio/SearchIO/cross_match.pm

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