Bio/SearchIO/Writer/TextResultWriter.pm

filter: Statementstmt 76.1% 166 / 218 Branchbran 48.4% 63 / 130 Conditioncond 30.8% 21 / 68 MC/DCmcdc 2.5% 1 / 40 Subroutinesub 86.3% 19 / 22 Podpod 86.6% 13 / 15 totaltotal 57.4% 283 / 493 CC 96 SCAR 52.8
CC
96
Cov
60%
to_string
320.9
algorithm_reference
56.0
new
9.1
CRAP 196.7
« Bio/Tree/DistanceFactory.pm ↑ Summary Bio/SeqIO/embl.pm »
1 #
2 # BioPerl module for Bio::SearchIO::Writer::TextResultWriter
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Jason Stajich <jason@bioperl.org>
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::Writer::TextResultWriter - Object to implement writing
17 a Bio::Search::ResultI in Text.
18  
19 =head1 SYNOPSIS
20  
21 use Bio::SearchIO;
22 use Bio::SearchIO::Writer::TextResultWriter;
23  
24 my $in = Bio::SearchIO->new(-format => 'blast',
25 -file => shift @ARGV);
26  
27 my $writer = Bio::SearchIO::Writer::TextResultWriter->new();
28 my $out = Bio::SearchIO->new(-writer => $writer);
29 $out->write_result($in->next_result);
30  
31 =head1 DESCRIPTION
32  
33 This object implements the SearchWriterI interface which will produce
34 a set of Text for a specific Bio::Search::Report::ReportI interface.
35  
36 You can also provide the argument -filters =E<gt> \%hash to filter the at
37 the hsp, hit, or result level. %hash is an associative array which
38 contains any or all of the keys (HSP, HIT, RESULT). The values
39 pointed to by these keys would be references to a subroutine which
40 expects to be passed an object - one of Bio::Search::HSP::HSPI,
41 Bio::Search::Hit::HitI, and Bio::Search::Result::ResultI respectively.
42 Each function needs to return a boolean value as to whether or not the
43 passed element should be included in the output report - true if it is
44 to be included, false if it to be omitted.
45  
46 For example to filter on sequences in the database which are too short
47 for your criteria you would do the following.
48  
49 Define a hit filter method
50  
51 sub hit_filter {
52 my $hit = shift;
53 return $hit->length E<gt> 100; # test if length of the hit sequence
54 # long enough
55 }
56 my $writer = Bio::SearchIO::Writer::TextResultWriter->new(
57 -filters => { 'HIT' =E<gt> \&hit_filter }
58 );
59  
60 Another example would be to filter HSPs on percent identity, let's
61 only include HSPs which are 75% identical or better.
62  
63 sub hsp_filter {
64 my $hsp = shift;
65 return $hsp->percent_identity E<gt> 75;
66 }
67 my $writer = Bio::SearchIO::Writer::TextResultWriter->new(
68 -filters => { 'HSP' =E<gt> \&hsp_filter }
69 );
70  
71 See L<Bio::SearchIO::SearchWriterI> for more info on the filter method.
72  
73  
74 This module will use the module Text::Wrap if it is installed to wrap
75 the Query description line. If you do not have Text::Wrap installed
76 this module will work fine but you won't have the Query line wrapped.
77 You will see a warning about this when you first instantiate a
78 TextResultWriter - to avoid these warnings from showing up, simply set
79 the verbosity upon initialization to -1 like this: my $writer = new
80 Bio::SearchIO::Writer::TextResultWriter(-verbose =E<gt> -1);
81  
82 =head1 FEEDBACK
83  
84 =head2 Mailing Lists
85  
86 User feedback is an integral part of the evolution of this and other
87 Bioperl modules. Send your comments and suggestions preferably to
88 the Bioperl mailing list. Your participation is much appreciated.
89  
90 bioperl-l@bioperl.org - General discussion
91 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
92  
93 =head2 Support
94  
95 Please direct usage questions or support issues to the mailing list:
96  
97 I<bioperl-l@bioperl.org>
98  
99 rather than to the module maintainer directly. Many experienced and
100 reponsive experts will be able look at the problem and quickly
101 address it. Please include a thorough description of the problem
102 with code and data examples if at all possible.
103  
104 =head2 Reporting Bugs
105  
106 Report bugs to the Bioperl bug tracking system to help us keep track
107 of the bugs and their resolution. Bug reports can be submitted via the
108 web:
109  
110 https://github.com/bioperl/bioperl-live/issues
111  
112 =head1 AUTHOR - Jason Stajich
113  
114 Email jason@bioperl.org
115  
116 =head1 APPENDIX
117  
118 The rest of the documentation details each of the object methods.
119 Internal methods are usually preceded with a _
120  
121 =cut
122  
123  
124 # Let the code begin...
125  
126  
127 package Bio::SearchIO::Writer::TextResultWriter;
128 2 $Bio::SearchIO::Writer::TextResultWriter::VERSION = '1.7.8';
129 2 ▶use vars qw($MaxNameLen $MaxDescLen $AlignmentLineWidth $DescLineLen $TextWrapLoaded);
Subroutine BEGIN: called CC=1 SCAR=0.0
130 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
131  
132 # Object preamble - inherits from Bio::Root::RootI
133  
134 2 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.1
135 2 $MaxDescLen = 65;
136 2 $AlignmentLineWidth = 60;
137 2 eval { require Text::Wrap; $TextWrapLoaded = 1;};
138 2 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
139 0 $TextWrapLoaded = 0;
140 }
141 }
142  
143 2 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
144  
145 2 ▶use base qw(Bio::Root::Root Bio::SearchIO::SearchWriterI);
Subroutine BEGIN: called CC=1 SCAR=0.0
146  
147 =head2 new
148  
149 Title : new
150 Usage : my $obj = Bio::SearchIO::Writer::TextResultWriter->new();
151 Function: Builds a new Bio::SearchIO::Writer::TextResultWriter object
152 Returns : Bio::SearchIO::Writer::TextResultWriter
153 Args : -filters => hashref with any or all of the keys (HSP HIT RESULT)
154 which have values pointing to a subroutine reference
155 which will expect to get a Hit,HSP, Result object respectively
156 -no_wublastlinks => boolean. Do not display WU-BLAST lines even if
157 they are parsed out
158 Links = (1)
159  
160 =cut
161  
162 1 ▶sub new {
Subroutine new: called CC=5 SCAR=22.0
Pod documented
163 1 my($class,@args) = @_;
164  
165 1 my $self = $class->SUPER::new(@args);
166 1 my ($filters,$nowublastlinks) = $self->_rearrange([qw(FILTERS
167 NO_WUBLASTLINKS)],
168 @args);
169 1 ▶ if( defined $filters ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $filters) 0 1 1
170 0 ▶ if( !ref($filters) =~ /HASH/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (!ref($filters) =~ /HASH/i) { } 0 0 0
171 0 $self->warn("Did not provide a hashref for the FILTERS option, ignoring.");
172 } else {
173 0 ▶ while( my ($type,$code) = each %{$filters} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$filters;}) 0 0 0
174 0 $self->filter($type,$code);
175 }
176 }
177 }
178 1 $self->no_wublastlinks(! $nowublastlinks);
179 1 ▶ unless( $TextWrapLoaded ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::SearchIO::Writer::TextResultWriter::TextWrapLoaded) { } 1 0 1
180 0 $self->warn("Could not load Text::Wrap - the Query Description will not be line wrapped\n");
181 } else {
182 1 $Text::Wrap::columns = $MaxDescLen;
183 }
184 1 return $self;
185 }
186  
187  
188 =head2 to_string
189  
190 Purpose : Produces data for each Search::Result::ResultI in a string.
191 : This is an abstract method. For some useful implementations,
192 : see ResultTableWriter.pm, HitTableWriter.pm,
193 : and HSPTableWriter.pm.
194 Usage : print $writer->to_string( $result_obj, @args );
195 Argument : $result_obj = A Bio::Search::Result::ResultI object
196 : @args = any additional arguments used by your implementation.
197 Returns : String containing data for each search Result or any of its
198 : sub-objects (Hits and HSPs).
199 Throws : n/a
200  
201 =cut
202  
203 1 ▶sub to_string {
Subroutine to_string: called CC=70 SCAR=57.7
Pod documented
204 1 my ($self,$result,$num) = @_;
205 1 ▶ $num ||= 0;
Condition50%1/2
$num ||= 0
l!l
10
MC/DC0%0/1
$num ||= 0
$num
Truth table50%1/2
A
A= $num
Aresult
11
00
206 1 ▶ return unless defined $result;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 0 1 1
207 1 my $links = $self->no_wublastlinks;
208 1 my ($resultfilter,$hitfilter, $hspfilter) = ( $self->filter('RESULT'),
209 $self->filter('HIT'),
210 $self->filter('HSP') );
211 0 ▶ return '' if( defined $resultfilter && ! &{$resultfilter}($result) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $resultfilter and not &{$resultfilter;}($result) 0 1 1
Condition33%1/3
defined $resultfilter and not &{$resultfilter;}($result)
!ll&&!rl&&r
100
MC/DC0%0/2
defined $resultfilter and not &{$resultfilter;}($result)
defined $resultfilter not &{$resultfilter;}($result)
Truth table33%1/3
A and not(B)
A= defined $resultfilterB= not &{$resultfilter;}($result)
ABresult
0X0
100
111
212
213 1 my ($qtype,$dbtype,$dbseqtype,$type);
214 1 my $alg = $result->algorithm;
215
216 1 ▶ my $wublast = ($result->algorithm_version =~ /WashU/) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$result->algorithm_version =~ /WashU/ ? : 0 1 1
217
218 # This is actually wrong for the FASTAs I think
219 1 ▶ if( $alg =~ /T(FAST|BLAST)([XY])/i ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($alg =~ /T(FAST|BLAST)([XY])/i) { } 1 0 1
elsif ($alg =~ /T(FAST|BLAST)N/i) { } 0 0 0
elsif ($alg =~ /(FAST|BLAST)N/i or $alg =~ /(WABA|EXONERATE)/i) { } 0 0 0
elsif ($alg =~ /(FAST|BLAST)P/ or $alg =~ /SSEARCH|(HMM|SEARCH|PFAM)/i) { } 0 0 0
elsif ($alg =~ /(FAST|BLAST)[XY]/i) { } 0 0 0
220 1 $qtype = $dbtype = 'translated';
221 1 $dbseqtype = $type = 'PROTEIN';
222 } elsif( $alg =~ /T(FAST|BLAST)N/i ) {
223 0 $qtype = '';
224 0 $dbtype = 'translated';
225 0 $type = 'PROTEIN';
226 0 $dbseqtype = 'NUCLEOTIDE';
227 ▶ } elsif( $alg =~ /(FAST|BLAST)N/i ||
Condition0%0/3
$alg =~ /(FAST|BLAST)N/i or $alg =~ /(WABA|EXONERATE)/i
l!l&&r!l&&!r
000
MC/DC0%0/2
$alg =~ /(FAST|BLAST)N/i or $alg =~ /(WABA|EXONERATE)/i
$alg =~ /(FAST|BLAST)N/i $alg =~ /(WABA|EXONERATE)/i
Truth table0%0/3
A or B
A= $alg =~ /(FAST|BLAST)N/iB= $alg =~ /(WABA|EXONERATE)/i
ABresult
1X1
011
000
228 $alg =~ /(WABA|EXONERATE)/i ) {
229 0 $qtype = $dbtype = '';
230 0 $type = $dbseqtype = 'NUCLEOTIDE';
231 ▶ } elsif( $alg =~ /(FAST|BLAST)P/ ||
Condition0%0/3
$alg =~ /(FAST|BLAST)P/ or $alg =~ /SSEARCH|(HMM|SEARCH|PFAM)/i
l!l&&r!l&&!r
000
MC/DC0%0/2
$alg =~ /(FAST|BLAST)P/ or $alg =~ /SSEARCH|(HMM|SEARCH|PFAM)/i
$alg =~ /(FAST|BLAST)P/ $alg =~ /SSEARCH|(HMM|SEARCH|PFAM)/i
Truth table0%0/3
A or B
A= $alg =~ /(FAST|BLAST)P/B= $alg =~ /SSEARCH|(HMM|SEARCH|PFAM)/i
ABresult
1X1
011
000
232 $alg =~ /SSEARCH|(HMM|SEARCH|PFAM)/i ) {
233 0 $qtype = $dbtype = '';
234 0 $type = $dbseqtype = 'PROTEIN';
235 } elsif( $alg =~ /(FAST|BLAST)[XY]/i ) {
236 0 $qtype = 'translated';
237 0 $dbtype = 'PROTEIN';
238 0 $dbseqtype = $type = 'PROTEIN';
239 } else {
240 0 print STDERR "algorithm was ", $result->algorithm, " couldn't match\n";
241 }
242
243
244 1 ▶ my %baselens = ( 'Sbjct:' => ( $dbtype eq 'translated' ) ? 3 : 1,
Branch: 2 branches
BranchTrueFalseTotal
$dbtype eq 'translated' ? : 1 0 1
$qtype eq 'translated' ? : 1 0 1
245 'Query:' => ( $qtype eq 'translated' ) ? 3 : 1);
246  
247 1 my $str;
248 1 ▶ if( ! defined $num || $num <= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $num or $num <= 1) 1 0 1
Condition33%1/3
not defined $num or $num <= 1
l!l&&r!l&&!r
010
MC/DC0%0/2
not defined $num or $num <= 1
not defined $num $num <= 1
Truth table33%1/3
not(A) or B
A= not defined $numB= $num <= 1
ABresult
1X1
011
000
249 1 $str = &{$self->start_report}($result);
250 }
251  
252 1 $str .= &{$self->title}($result);
253 1 $str .= $result->algorithm . " " . $result->algorithm_version . "\n\n\n";
254 1 ▶ $str .= $result->algorithm_reference || $self->algorithm_reference($result);
Condition33%1/3
$result->algorithm_reference || $self->algorithm_reference($result)
l!l&&r!l&&!r
100
MC/DC0%0/2
$result->algorithm_reference || $self->algorithm_reference($result)
$result->algorithm_reference $self->algorithm_reference($result)
Truth table33%1/3
A || B
A= $result->algorithm_referenceB= $self->algorithm_reference($result)
ABresult
1X1
011
000
255 1 $str .= &{$self->introduction}($result);
256  
257  
258 1 $str .= qq{
259 Score E
260 Sequences producing significant alignments: (bits) value
261 };
262 1 my $hspstr = '';
263 1 ▶ if( $result->can('rewind')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->can("rewind")) 1 0 1
264 1 $result->rewind(); # support stream based parsing routines
265 }
266 1 ▶ while( my $hit = $result->next_hit ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hit = $result->next_hit) 20 1 21
267 0 ▶ next if( defined $hitfilter && ! &{$hitfilter}($hit) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $hitfilter and not &{$hitfilter;}($hit) 0 20 20
Condition33%1/3
defined $hitfilter and not &{$hitfilter;}($hit)
!ll&&!rl&&r
2000
MC/DC0%0/2
defined $hitfilter and not &{$hitfilter;}($hit)
defined $hitfilter not &{$hitfilter;}($hit)
Truth table33%1/3
A and not(B)
A= defined $hitfilterB= not &{$hitfilter;}($hit)
ABresult
0X0
100
111
268 20 my $nm = $hit->name();
269 20 ▶ $self->debug( "no $nm for name (".$hit->description(). "\n")
Branch: 1 branch
BranchTrueFalseTotal
unless $nm 0 20 20
270 unless $nm;
271 20 my ($gi,$acc) = &{$self->id_parser}($nm);
272 20 my $p = "%-$MaxDescLen". "s";
273 20 my $descsub;
274 20 my $desc = sprintf("%s %s",$nm,$hit->description);
275 20 ▶ if( length($desc) - 3 > $MaxDescLen) {
Branch: 1 branch
BranchTrueFalseTotal
if (length($desc) - 3 > $Bio::SearchIO::Writer::TextResultWriter::MaxDescLen) { } 20 0 20
276 20 $descsub = sprintf($p,
277 substr($desc,0,$MaxDescLen-3) .
278 "...");
279 } else {
280 0 $descsub = sprintf($p,$desc);
281 }
282 20 ▶ $str .= $wublast ? sprintf("%s %-4s %s\n",
Branch: 5 branches
BranchTrueFalseTotal
$wublast ? : 0 20 20
defined $hit->raw_score ? : 0 0 0
defined $hit->significance ? : 0 0 0
defined $hit->bits ? : 20 0 20
defined $hit->significance ? : 20 0 20
283 $descsub,
284 defined $hit->raw_score ? $hit->raw_score : ' ',
285 defined $hit->significance ? $hit->significance : '?') :
286 sprintf("%s %-4s %s\n",
287 $descsub,
288 defined $hit->bits ? $hit->bits: ' ',
289 defined $hit->significance ? $hit->significance : '?');
290 20 my @hsps = $hit->hsps;
291 20 ▶ if( @hsps ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@hsps) 20 0 20
292 20 ▶ $hspstr .= sprintf(">%s %s\n%9sLength = %d\n\n",
Branch: 1 branch
BranchTrueFalseTotal
defined $hit->description ? : 20 0 20
293 $hit->name,
294 defined $hit->description ? $hit->description : '',
295 '', # empty is for the %9s in the str formatting
296 $hit->length);
297  
298 20 foreach my $hsp ( @hsps ) {
299 0 ▶ next if( defined $hspfilter && ! &{$hspfilter}($hsp) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $hspfilter and not &{$hspfilter;}($hsp) 0 21 21
Condition33%1/3
defined $hspfilter and not &{$hspfilter;}($hsp)
!ll&&!rl&&r
2100
MC/DC0%0/2
defined $hspfilter and not &{$hspfilter;}($hsp)
defined $hspfilter not &{$hspfilter;}($hsp)
Truth table33%1/3
A and not(B)
A= defined $hspfilterB= not &{$hspfilter;}($hsp)
ABresult
0X0
100
111
300 21 $hspstr .= sprintf(" Score = %4s bits (%s), Expect = %s",
301 $hsp->bits, $hsp->score, $hsp->evalue);
302 21 ▶ if( $hsp->pvalue ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hsp->pvalue) 0 21 21
303 0 $hspstr .= ", P = ".$hsp->pvalue;
304 }
305 21 $hspstr .= "\n";
306 21 $hspstr .= sprintf(" Identities = %d/%d (%d%%)",
307 ( $hsp->frac_identical('total') *
308 $hsp->length('total')),
309 $hsp->length('total'),
310 POSIX::floor($hsp->frac_identical('total')
311 * 100));
312
313 21 ▶ if( $type eq 'PROTEIN' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "PROTEIN") 21 0 21
314 21 $hspstr .= sprintf(", Positives = %d/%d (%d%%)",
315 ( $hsp->frac_conserved('total') *
316 $hsp->length('total')),
317 $hsp->length('total'),
318 POSIX::floor($hsp->frac_conserved('total') * 100));
319  
320 }
321 21 ▶ if( $hsp->gaps ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hsp->gaps) 0 21 21
322 0 $hspstr .= sprintf(", Gaps = %d/%d (%d%%)",
323 $hsp->gaps('total'),
324 $hsp->length('total'),
325 POSIX::floor(100 * $hsp->gaps('total') /
326 $hsp->length('total')));
327 }
328 21 $hspstr .= "\n";
329 21 my ($hframe,$qframe) = ( $hsp->hit->frame,
330 $hsp->query->frame);
331 21 my ($hstrand,$qstrand) = ($hsp->hit->strand,$hsp->query->strand);
332 # so TBLASTX will have Query/Hit frames
333 # BLASTX will have Query frame
334 # TBLASTN will have Hit frame
335 21 ▶ if( $hstrand || $qstrand ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hstrand or $qstrand) 21 0 21
Condition33%1/3
$hstrand or $qstrand
l!l&&r!l&&!r
2100
MC/DC0%0/2
$hstrand or $qstrand
$hstrand $qstrand
Truth table33%1/3
A or B
A= $hstrandB= $qstrand
ABresult
1X1
011
000
336 21 $hspstr .= " Frame = ";
337 21 my ($signq, $signh);
338 21 ▶ unless( $hstrand ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hstrand) { } 21 0 21
339 0 $hframe = undef;
340 # if strand is null or 0 then it is protein
341 # and this no frame
342 } else {
343 21 ▶ $signh = $hstrand < 0 ? '-' : '+';
Branch: 1 branch
BranchTrueFalseTotal
$hstrand < 0 ? : 5 16 21
344 }
345 21 ▶ unless( $qstrand ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qstrand) { } 21 0 21
346 0 $qframe = undef;
347 # if strand is null or 0 then it is protein
348 } else {
349 21 ▶ $signq =$qstrand < 0 ? '-' : '+';
Branch: 1 branch
BranchTrueFalseTotal
$qstrand < 0 ? : 7 14 21
350 }
351 # remember bioperl stores frames as 0,1,2 (GFF way)
352 # BLAST reports reports as 1,2,3 so
353 # we have to add 1 to the frame values
354 21 ▶ if( defined $hframe && ! defined $qframe) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $hframe and not defined $qframe) { } 0 21 21
elsif (defined $qframe and not defined $hframe) { } 0 21 21
Condition33%1/3
defined $hframe and not defined $qframe
!ll&&!rl&&r
0210
MC/DC0%0/2
defined $hframe and not defined $qframe
defined $hframe not defined $qframe
Truth table33%1/3
A and not(B)
A= defined $hframeB= not defined $qframe
ABresult
0X0
100
111
355 0 $hspstr .= "$signh".($hframe+1);
356 ▶ } elsif( defined $qframe && ! defined $hframe) {
Condition33%1/3
defined $qframe and not defined $hframe
!ll&&!rl&&r
0210
MC/DC0%0/2
defined $qframe and not defined $hframe
defined $qframe not defined $hframe
Truth table33%1/3
A and not(B)
A= defined $qframeB= not defined $hframe
ABresult
0X0
100
111
357 0 $hspstr .= "$signq".($qframe+1);
358 } else {
359 21 $hspstr .= sprintf(" %s%d / %s%d",
360 $signq,$qframe+1,
361 $signh, $hframe+1);
362 }
363 }
364
365 21 ▶ if( $links &&
Branch: 1 branch
BranchTrueFalseTotal
if ($links and $hsp->can("links") and defined(my $lnks = $hsp->links)) 0 21 21
Condition33%2/6
$links and $hsp->can("links") and defined(my $lnks = $hsp->links)
!ll&&!rl&&r
0210
$links and $hsp->can("links")
!ll&&!rl&&r
0021
MC/DC0%0/3
$links and $hsp->can("links") and defined(my $lnks = $hsp->links)
$links $hsp->can("links") defined(my $lnks = $hsp->links)
Truth table25%1/4
A and B and C
A= $linksB= $hsp->can("links")C= defined(my $lnks = $hsp->links)
ABCresult
0XX0
10X0
1100
1111
366 $hsp->can('links') && defined(my $lnks = $hsp->links) ) {
367 0 $hspstr .= sprintf(" Links = %s\n",$lnks);
368 }
369 21 $hspstr .= "\n\n";
370  
371 21 ▶ my @hspvals = ( {'name' => 'Query:',
Branch: 4 branches
BranchTrueFalseTotal
$qstrand >= 0 ? : 14 7 21
$qstrand >= 0 ? : 14 7 21
$hstrand >= 0 ? : 16 5 21
$hstrand >= 0 ? : 16 5 21
Condition50%2/4
$qstrand || 1
l!l
210
$hstrand || 1
l!l
210
MC/DC0%0/1
$qstrand || 1
$qstrand
MC/DC0%0/1
$hstrand || 1
$hstrand
Truth table50%1/2
A
A= $qstrand
Aresult
11
00
Truth table50%1/2
A
A= $hstrand
Aresult
11
00
372 'seq' => $hsp->query_string,
373 'start' => ( $qstrand >= 0 ?
374 $hsp->query->start :
375 $hsp->query->end),
376 'end' => ($qstrand >= 0 ?
377 $hsp->query->end :
378 $hsp->query->start),
379 'index' => 0,
380 'direction' => $qstrand || 1
381 },
382 { 'name' => ' 'x6, # this might need to adjust for long coordinates??
383 'seq' => $hsp->homology_string,
384 'start' => undef,
385 'end' => undef,
386 'index' => 0,
387 'direction' => 1
388 },
389 { 'name' => 'Sbjct:',
390 'seq' => $hsp->hit_string,
391 'start' => ($hstrand >= 0 ?
392 $hsp->hit->start : $hsp->hit->end),
393 'end' => ($hstrand >= 0 ?
394 $hsp->hit->end : $hsp->hit->start),
395 'index' => 0,
396 'direction' => $hstrand || 1
397 }
398 );
399  
400  
401 # let's set the expected length (in chars) of the starting number
402 # in an alignment block so we can have things line up
403 # Just going to try and set to the largest
404  
405 85 my ($numwidth) = sort { $b <=> $a }(length($hspvals[0]->{'start'}),
406 length($hspvals[0]->{'end'}),
407 length($hspvals[2]->{'start'}),
408 21 length($hspvals[2]->{'end'}));
409 21 my $count = 0;
410 21 ▶ while ( $count <= $hsp->length('total') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count <= $hsp->length("total")) 21 21 42
411 21 foreach my $v ( @hspvals ) {
412 63 my $piece = substr($v->{'seq'}, $v->{'index'} +$count,
413 $AlignmentLineWidth);
414 63 my $cp = $piece;
415 63 my $plen = scalar ( $cp =~ tr/\-//);
416 63 my ($start,$end) = ('','');
417 63 ▶ if( defined $v->{'start'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v->{"start"}) 42 21 63
418 42 $start = $v->{'start'};
419 # since strand can be + or - use the direction
420 # to signify which whether to add or subtract from end
421 my $d = $v->{'direction'} * ( $AlignmentLineWidth - $plen )*
422 42 $baselens{$v->{'name'}};
423 42 ▶ if( length($piece) < $AlignmentLineWidth ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $piece < $Bio::SearchIO::Writer::TextResultWriter::AlignmentLineWidth) 42 0 42
424 $d = (length($piece) - $plen) * $v->{'direction'} *
425 42 $baselens{$v->{'name'}};
426 }
427 42 $end = $v->{'start'} + $d - $v->{'direction'};
428 42 $v->{'start'} += $d;
429 }
430 $hspstr .= sprintf("%s %-".$numwidth."s %s %s\n",
431 63 $v->{'name'},
432 $start,
433 $piece,
434 $end
435 );
436 }
437 21 $count += $AlignmentLineWidth;
438 21 $hspstr .= "\n";
439 }
440 }
441 20 $hspstr .= "\n";
442 }
443 }
444 1 $str .= "\n\n".$hspstr;
445
446 1 ▶ $str .= sprintf(qq{ Database: %s
Condition40%2/5
$result->get_statistic('posted_date') || POSIX::strftime('%b %d, %Y %I:%M %p', localtime)
l!l&&r!l&&!r
100
$result->get_parameter('matrix') || ''
l!l
10
MC/DC0%0/2
$result->get_statistic('posted_date') || POSIX::strftime('%b %d, %Y %I:%M %p', localtime)
$result->get_statistic('posted_date') POSIX::strftime('%b %d, %Y %I:%M %p', localtime)
MC/DC0%0/1
$result->get_parameter('matrix') || ''
$result->get_parameter('matrix')
Truth table33%1/3
A || B
A= $result->get_statistic('posted_date')B= POSIX::strftime('%b %d, %Y %I:%M %p', localtime)
ABresult
1X1
011
000
Truth table50%1/2
A
A= $result->get_parameter('matrix')
Aresult
11
00
447 Posted date: %s
448 Number of letters in database: %s
449 Number of sequences in database: %s
450  
451 Matrix: %s
452 },
453 $result->database_name(),
454 $result->get_statistic('posted_date') ||
455 POSIX::strftime("%b %d, %Y %I:%M %p",localtime),
456 &_numwithcommas($result->database_letters()),
457 &_numwithcommas($result->database_entries()),
458 $result->get_parameter('matrix') || '');
459  
460 1 ▶ if( defined (my $open = $result->get_parameter('gapopen')) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $open = $result->get_parameter("gapopen"))) 0 1 1
461 0 ▶ $str .= sprintf("Gap Penalties Existence: %d, Extension: %d\n",
Condition0%0/4
$open || 0
l!l
00
$result->get_parameter('gapext') || 0
l!l
00
MC/DC0%0/1
$open || 0
$open
MC/DC0%0/1
$result->get_parameter('gapext') || 0
$result->get_parameter('gapext')
Truth table0%0/2
A
A= $open
Aresult
11
00
Truth table0%0/2
A
A= $result->get_parameter('gapext')
Aresult
11
00
462 $open || 0, $result->get_parameter('gapext') || 0);
463 }
464  
465 # skip those params we've already output
466 1 foreach my $param ( grep { ! /matrix|gapopen|gapext/i }
467 $result->available_parameters ) {
468 2 $str .= "$param: ". $result->get_parameter($param) ."\n";
469
470 }
471 1 $str .= "Search Statistics\n";
472 # skip posted date, we already output it
473 1 foreach my $stat ( sort grep { ! /posted_date/ }
474 $result->available_statistics ) {
475 26 my $expect = $result->get_parameter('expect');
476 26 my $v = $result->get_statistic($stat);
477 26 ▶ if( $v =~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /^\d+$/) 18 8 26
478 18 $v = &_numwithcommas($v);
479 }
480 26 ▶ if( defined $expect &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $expect and $stat eq 'seqs_better_than_cutoff') { } 1 25 26
Condition66%2/3
defined $expect and $stat eq "seqs_better_than_cutoff"
!ll&&!rl&&r
0251
MC/DC50%1/2
defined $expect and $stat eq "seqs_better_than_cutoff"
defined $expect $stat eq "seqs_better_than_cutoff"
Truth table66%2/3
A and B
A= defined $expectB= $stat eq "seqs_better_than_cutoff"
ABresult
0X0
100
111
481 $stat eq 'seqs_better_than_cutoff' ) {
482 1 $str .= "seqs_better_than_$expect: $v\n";
483 } else {
484 25 my $v =
485 $str .= "$stat: $v\n";
486 }
487 }
488 1 $str .= "\n\n";
489 1 return $str;
490 }
491  
492  
493 =head2 start_report
494  
495 Title : start_report
496 Usage : $index->start_report( CODE )
497 Function: Stores or returns the code to
498 write the start of the <HTML> block, the <TITLE> block
499 and the start of the <BODY> block of HTML. Useful
500 for (for instance) specifying alternative
501 HTML if you are embedding the output in
502 an HTML page which you have already started.
503 (For example a routine returning a null string).
504 Returns \&default_start_report (see below) if not
505 set.
506 Example : $index->start_report( \&my_start_report )
507 Returns : ref to CODE if called without arguments
508 Args : CODE
509  
510 =cut
511  
512 1 ▶sub start_report {
Subroutine start_report: called CC=3 SCAR=12.5
Pod documented
513 1 my( $self, $code ) = @_;
514 1 ▶ if ($code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code) 0 1 1
515 0 $self->{'_start_report'} = $code;
516 }
517 1 ▶ return $self->{'_start_report'} || \&default_start_report;
Condition50%1/2
$self->{'_start_report'} || \&Bio::SearchIO::Writer::TextResultWriter::default_start_report
l!l
01
MC/DC0%0/1
$self->{'_start_report'} || \&Bio::SearchIO::Writer::TextResultWriter::default_start_report
$self->{'_start_report'}
Truth table50%1/2
A
A= $self->{'_start_report'}
Aresult
11
00
518 }
519  
520 =head2 default_start_report
521  
522 Title : default_start_report
523 Usage : $self->default_start_report($result)
524 Function: The default method to call when starting a report.
525 Returns : sting
526 Args : First argument is a Bio::Search::Result::ResultI
527  
528 =cut
529  
530 1 ▶sub default_start_report {
Subroutine default_start_report: called CC=1 SCAR=0.0
Pod documented
531 1 my ($result) = @_;
532 1 return "";
533 }
534  
535 =head2 title
536  
537 Title : title
538 Usage : $self->title($CODE)
539  
540 Function: Stores or returns the code to provide HTML for the given
541 BLAST report that will appear at the top of the BLAST report
542 HTML output. Useful for (for instance) specifying
543 alternative routines to write your own titles.
544 Returns \&default_title (see below) if not
545 set.
546 Example : $index->title( \&my_title )
547 Returns : ref to CODE if called without arguments
548 Args : CODE
549  
550 =cut
551  
552 1 ▶sub title {
Subroutine title: called CC=3 SCAR=12.5
Pod documented
553 1 my( $self, $code ) = @_;
554 1 ▶ if ($code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code) 0 1 1
555 0 $self->{'_title'} = $code;
556 }
557 1 ▶ return $self->{'_title'} || \&default_title;
Condition50%1/2
$self->{'_title'} || \&Bio::SearchIO::Writer::TextResultWriter::default_title
l!l
01
MC/DC0%0/1
$self->{'_title'} || \&Bio::SearchIO::Writer::TextResultWriter::default_title
$self->{'_title'}
Truth table50%1/2
A
A= $self->{'_title'}
Aresult
11
00
558 }
559  
560 =head2 default_title
561  
562 Title : default_title
563 Usage : $self->default_title($result)
564 Function: Provides HTML for the given BLAST report that will appear
565 at the top of the BLAST report output.
566 Returns : empty for text implementation
567 Args : First argument is a Bio::Search::Result::ResultI
568  
569 =cut
570  
571 1 ▶sub default_title {
Subroutine default_title: called CC=1 SCAR=0.0
Pod documented
572 1 my ($result) = @_;
573 1 return "";
574 # The HTML implementation
575 # return sprintf(
576 # qq{<CENTER><H1><a href="http://bioperl.org">Bioperl</a> Reformatted HTML of %s Search Report<br> for %s</H1></CENTER>},
577 # $result->algorithm,
578 # $result->query_name());
579 }
580  
581  
582 =head2 introduction
583  
584 Title : introduction
585 Usage : $self->introduction($CODE)
586  
587 Function: Stores or returns the code to provide HTML for the given
588 BLAST report detailing the query and the
589 database information.
590 Useful for (for instance) specifying
591 routines returning alternative introductions.
592 Returns \&default_introduction (see below) if not
593 set.
594 Example : $index->introduction( \&my_introduction )
595 Returns : ref to CODE if called without arguments
596 Args : CODE
597  
598 =cut
599  
600 1 ▶sub introduction {
Subroutine introduction: called CC=3 SCAR=12.5
Pod documented
601 1 my( $self, $code ) = @_;
602 1 ▶ if ($code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code) 0 1 1
603 0 $self->{'_introduction'} = $code;
604 }
605 1 ▶ return $self->{'_introduction'} || \&default_introduction;
Condition50%1/2
$self->{'_introduction'} || \&Bio::SearchIO::Writer::TextResultWriter::default_introduction
l!l
01
MC/DC0%0/1
$self->{'_introduction'} || \&Bio::SearchIO::Writer::TextResultWriter::default_introduction
$self->{'_introduction'}
Truth table50%1/2
A
A= $self->{'_introduction'}
Aresult
11
00
606 }
607  
608 =head2 default_introduction
609  
610 Title : default_introduction
611 Usage : $self->default_introduction($result)
612 Function: Outputs HTML to provide the query
613 and the database information
614 Returns : string containing HTML
615 Args : First argument is a Bio::Search::Result::ResultI
616 Second argument is string holding literature citation
617  
618 =cut
619  
620 1 ▶sub default_introduction {
Subroutine default_introduction: called CC=1 SCAR=0.0
Pod documented
621 1 my ($result) = @_;
622  
623 1 return sprintf(
624 qq{
625 Query= %s
626 (%s letters)
627  
628 Database: %s
629 %s sequences; %s total letters
630 },
631 &_linewrap($result->query_name . " " .
632 $result->query_description),
633 &_numwithcommas($result->query_length),
634 $result->database_name(),
635 &_numwithcommas($result->database_entries()),
636 &_numwithcommas($result->database_letters()),
637 );
638 }
639  
640 =head2 end_report
641  
642 Title : end_report
643 Usage : $self->end_report()
644 Function: The method to call when ending a report, this is
645 mostly for cleanup for formats which require you to
646 have something at the end of the document (</BODY></HTML>)
647 for HTML
648 Returns : string
649 Args : none
650  
651 =cut
652  
653 1 ▶sub end_report {
Subroutine end_report: called CC=1 SCAR=0.0
Pod documented
654 1 return "";
655 }
656  
657  
658 # copied from Bio::Index::Fasta
659 # useful here as well
660  
661 =head2 id_parser
662  
663 Title : id_parser
664 Usage : $index->id_parser( CODE )
665 Function: Stores or returns the code used by record_id to
666 parse the ID for record from a string. Useful
667 for (for instance) specifying a different
668 parser for different flavours of FASTA file.
669 Returns \&default_id_parser (see below) if not
670 set. If you supply your own id_parser
671 subroutine, then it should expect a fasta
672 description line. An entry will be added to
673 the index for each string in the list returned.
674 Example : $index->id_parser( \&my_id_parser )
675 Returns : ref to CODE if called without arguments
676 Args : CODE
677  
678 =cut
679  
680 20 ▶sub id_parser {
Subroutine id_parser: called CC=3 SCAR=12.5
Pod documented
681 20 my( $self, $code ) = @_;
682
683 20 ▶ if ($code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code) 0 20 20
684 0 $self->{'_id_parser'} = $code;
685 }
686 20 ▶ return $self->{'_id_parser'} || \&default_id_parser;
Condition50%1/2
$self->{'_id_parser'} || \&Bio::SearchIO::Writer::TextResultWriter::default_id_parser
l!l
020
MC/DC0%0/1
$self->{'_id_parser'} || \&Bio::SearchIO::Writer::TextResultWriter::default_id_parser
$self->{'_id_parser'}
Truth table50%1/2
A
A= $self->{'_id_parser'}
Aresult
11
00
687 }
688  
689  
690  
691 =head2 default_id_parser
692  
693 Title : default_id_parser
694 Usage : $id = default_id_parser( $header )
695 Function: The default Fasta ID parser for Fasta.pm
696 Returns $1 from applying the regexp /^>\s*(\S+)/
697 to $header.
698 Returns : ID string
699 Args : a fasta header line string
700  
701 =cut
702  
703 20 ▶sub default_id_parser {
Subroutine default_id_parser: called CC=4 SCAR=17.3
Pod documented
704 20 my ($string) = @_;
705 20 my ($gi,$acc);
706 20 ▶ if( $string =~ s/gi\|(\d+)\|?// )
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ s/gi\|(\d+)\|?//) 0 20 20
707 0 { $gi = $1; $acc = $1;}
708
709 20 ▶ if( $string =~ /(\w+)\|([A-Z\d\.\_]+)(\|[A-Z\d\_]+)?/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /(\w+)\|([A-Z\d\.\_]+)(\|[A-Z\d\_]+)?/) { } 20 0 20
710 20 ▶ $acc = defined $2 ? $2 : $1;
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 20 0 20
711 } else {
712 0 $acc = $string;
713 0 $acc =~ s/^\s+(\S+)/$1/;
714 0 $acc =~ s/(\S+)\s+$/$1/;
715 }
716 20 return ($gi,$acc);
717 }
718
719 0 ▶sub MIN { $a <=> $b ? $a : $b; }
Subroutine MIN: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$a <=> $b ? : 0 0 0
720 0 ▶sub MAX { $a <=> $b ? $b : $a; }
Subroutine MAX: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$a <=> $b ? : 0 0 0
721  
722  
723 =head2 algorithm_reference
724  
725 Title : algorithm_reference
726 Usage : my $reference = $writer->algorithm_reference($result);
727 Function: Returns the appropriate Bibliographic reference for the
728 algorithm format being produced
729 Returns : String
730 Args : L<Bio::Search::Result::ResultI> to reference
731  
732  
733 =cut
734  
735 0 ▶sub algorithm_reference{
Subroutine algorithm_reference: not called CC=7 SCAR=40.3
Pod documented
736 0 my ($self,$result) = @_;
737 0 ▶ return '' if( ! defined $result || !ref($result) ||
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result and ref $result and $result->isa("Bio::Search::Result::ResultI") 0 0 0
Condition0%0/6
defined $result and ref $result and $result->isa("Bio::Search::Result::ResultI")
!ll&&!rl&&r
000
defined $result and ref $result
!ll&&!rl&&r
000
MC/DC0%0/3
defined $result and ref $result and $result->isa("Bio::Search::Result::ResultI")
defined $result ref $result $result->isa("Bio::Search::Result::ResultI")
Truth table0%0/4
A and B and C
A= defined $resultB= ref $resultC= $result->isa("Bio::Search::Result::ResultI")
ABCresult
0XX0
10X0
1100
1111
738 ! $result->isa('Bio::Search::Result::ResultI')) ;
739 0 ▶ if( $result->algorithm =~ /BLAST/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($result->algorithm =~ /BLAST/i) { } 0 0 0
elsif ($result->algorithm =~ /FAST/i) { } 0 0 0
740 0 my $res = $result->algorithm . ' '. $result->algorithm_version. "\n";
741 0 ▶ if( $result->algorithm_version =~ /WashU/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->algorithm_version =~ /WashU/i) { } 0 0 0
742 0 return $res .qq{
743 Copyright (C) 1996-2000 Washington University, Saint Louis, Missouri USA.
744 All Rights Reserved.
745
746 Reference: Gish, W. (1996-2000) http://blast.wustl.edu
747 };
748 } else {
749 0 return $res . qq{
750 Reference: Altschul, Stephen F., Thomas L. Madden, Alejandro A. Schaffer,
751 Jinghui Zhang, Zheng Zhang, Webb Miller, and David J. Lipman (1997),
752 "Gapped BLAST and PSI-BLAST: a new generation of protein database search
753 programs", Nucleic Acids Res. 25:3389-3402.
754 };
755 }
756 } elsif( $result->algorithm =~ /FAST/i ) {
757 0 return $result->algorithm. " ". $result->algorithm_version . "\n".
758 "\nReference: Pearson et al, Genomics (1997) 46:24-36\n";
759 } else {
760 0 return '';
761 }
762 }
763  
764 # from Perl Cookbook 2.17
765 23 ▶sub _numwithcommas {
Subroutine _numwithcommas: called CC=1 SCAR=0.0
766 23 my $num = reverse( $_[0] );
767 23 $num =~ s/(\d{3})(?=\d)(?!\d*\.)/$1,/g;
768 23 return scalar reverse $num;
769 }
770  
771 1 ▶sub _linewrap {
Subroutine _linewrap: called CC=2 SCAR=7.6
772 1 my ($str) = @_;
773 1 ▶ if($TextWrapLoaded) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::SearchIO::Writer::TextResultWriter::TextWrapLoaded) { } 1 0 1
774 1 return Text::Wrap::wrap("","",$str); # use Text::Wrap
775 0 } else { return $str; } # cannot wrap
776 }
777 =head2 Methods Bio::SearchIO::SearchWriterI
778  
779 L<Bio::SearchIO::SearchWriterI> inherited methods.
780  
781 =head2 filter
782  
783 Title : filter
784 Usage : $writer->filter('hsp', \&hsp_filter);
785 Function: Filter out either at HSP,Hit,or Result level
786 Returns : none
787 Args : string => data type,
788 CODE reference
789  
790  
791 =cut
792  
793 =head2 no_wublastlinks
794  
795 Title : no_wublastlinks
796 Usage : $obj->no_wublastlinks($newval)
797 Function: Get/Set boolean value regarding whether or not to display
798 Link = (1)
799 type output in the report output (WU-BLAST only)
800 Returns : boolean
801 Args : on set, new boolean value (a scalar or undef, optional)
802  
803  
804 =cut
805  
806 2 ▶sub no_wublastlinks{
Subroutine no_wublastlinks: called CC=2 SCAR=6.9
Pod documented
807 2 my $self = shift;
808  
809 2 ▶ return $self->{'no_wublastlinks'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 1 2
810 1 return $self->{'no_wublastlinks'};
811 }
812  
813  
814 2 1;
« Bio/Tree/DistanceFactory.pm ↑ Summary Bio/SeqIO/embl.pm »