bug 2549; fixed small bug in Bio::Taxon which doesn't catch -common_name
[bioperl-live.git] / Bio / SearchIO / SearchWriterI.pm
blob6247528732599293c0d9bc430bdfe3d9fd54bc81
1 #-----------------------------------------------------------------
2 # $Id$
4 # BioPerl module Bio::SearchIO::SearchWriterI
6 # Cared for by Steve Chervitz <sac@bioperl.org>
8 # You may distribute this module under the same terms as perl itself
9 #-----------------------------------------------------------------
11 =head1 NAME
13 Bio::SearchIO::SearchWriterI - Interface for outputting parsed Search results
15 =head1 SYNOPSIS
17 Bio::SearchIO::SearchWriterI objects cannot be instantiated since this
18 module defines a pure interface.
20 Given an object that implements the Bio::SearchIO::SearchWriterI interface,
21 you can do the following things with it:
23 print $writer->to_string( $result_obj, @args );
25 =head1 DESCRIPTION
27 This module defines abstract methods that all subclasses must implement
28 to be used for outputting results from L<Bio::Search::Result::ResultI>
29 objects.
31 =head1 AUTHOR
33 Steve Chervitz E<lt>sac-at-bioperl.orgE<gt>
35 =head1 DISCLAIMER
37 This software is provided "as is" without warranty of any kind.
39 =head1 APPENDIX
41 The rest of the documentation details each of the object methods.
43 =cut
45 package Bio::SearchIO::SearchWriterI;
48 use base qw(Bio::Root::RootI);
50 =head2 to_string
52 Purpose : Produces data for each Search::Result::ResultI in a string.
53 : This is an abstract method. For some useful implementations,
54 : see ResultTableWriter.pm, HitTableWriter.pm,
55 : and HSPTableWriter.pm.
56 Usage : print $writer->to_string( $result_obj, @args );
57 Argument : $result_obj = A Bio::Search::Result::ResultI object
58 : @args = any additional arguments used by your implementation.
59 Returns : String containing data for each search Result or any of its
60 : sub-objects (Hits and HSPs).
61 Throws : n/a
63 =cut
65 sub to_string {
66 my ($self, $result, @args) = @_;
67 $self->throw_not_implemented;
70 =head2 start_report
72 Title : start_report
73 Usage : $self->start_report()
74 Function: The method to call when starting a report. You can override it
75 to make a custom header
76 Returns : string
77 Args : none
79 =cut
81 sub start_report { return '' }
83 =head2 end_report
85 Title : end_report
86 Usage : $self->end_report()
87 Function: The method to call when ending a report, this is
88 mostly for cleanup for formats which require you to
89 have something at the end of the document (</BODY></HTML>)
90 for HTML
91 Returns : string
92 Args : none
95 =cut
97 sub end_report { return '' }
99 =head2 filter
101 Title : filter
102 Usage : $writer->filter('hsp', \&hsp_filter);
103 Function: Filter out either at HSP,Hit,or Result level
104 Returns : none
105 Args : string => data type,
106 CODE reference
109 =cut
111 # yes this is an implementation in the interface,
112 # yes it assumes that the underlying class is hash-based
113 # yes that might not be a good idea, but until people
114 # start extending the SearchWriterI interface I think
115 # this is an okay way to go
117 sub filter {
118 my ($self,$method,$code) = @_;
119 return unless $method;
120 $method = uc($method);
121 if( $method ne 'HSP' &&
122 $method ne 'HIT' &&
123 $method ne 'RESULT' ) {
124 $self->warn("Unknown method $method");
125 return;
127 if( $code ) {
128 $self->throw("Must provide a valid code reference") unless ref($code) =~ /CODE/;
129 $self->{$method} = $code;
131 return $self->{$method};