Clarify warnings when defaulting the value of end()
[bioperl-live.git] / Bio / SearchDist.pm
blob0906af7507416a55ef7fd371e13ee687b3d5ea49
1 # $Id$
4 # BioPerl module for Bio::SearchDist
6 # Please direct questions and support issues to <bioperl-l@bioperl.org>
8 # Cared for by Ewan Birney <birney@ebi.ac.uk>
10 # Copyright Ewan Birney
12 # You may distribute this module under the same terms as perl itself
14 # POD documentation - main docs before the code
16 =head1 NAME
18 Bio::SearchDist - A perl wrapper around Sean Eddy's histogram object
20 =head1 SYNOPSIS
22 $dis = Bio::SearchDist->new();
23 foreach $score ( @scores ) {
24 $dis->add_score($score);
27 if( $dis->fit_evd() ) {
28 foreach $score ( @scores ) {
29 $evalue = $dis->evalue($score);
30 print "Score $score had an evalue of $evalue\n";
32 } else {
33 warn("Could not fit histogram to an EVD!");
36 =head1 DESCRIPTION
38 The Bio::SearchDist object is a wrapper around Sean Eddy's excellent
39 histogram object. The histogram object can bascially take in a number
40 of scores which are sensibly distributed somewhere around 0 that come
41 from a supposed Extreme Value Distribution. Having add all the scores
42 from a database search via the add_score method you can then fit a
43 extreme value distribution using fit_evd(). Once fitted you can then
44 get out the evalue for each score (or a new score) using
45 evalue($score).
47 The fitting procedure is better described in Sean Eddy's own code
48 (available from http://hmmer.janelia.org/, or in the histogram.h header
49 file in Compile/SW). Bascially it fits a EVD via a maximum likelhood
50 method with pruning of the top end of the distribution so that real
51 positives are discarded in the fitting procedure. This comes from
52 an orginally idea of Richard Mott's and the likelhood fitting
53 is from a book by Lawless [should ref here].
56 The object relies on the fact that the scores are sensibly distributed
57 around about 0 and that integer bins are sensible for the
58 histogram. Scores based on bits are often ideal for this (bits based
59 scoring mechanisms is what this histogram object was originally
60 designed for).
63 =head1 CONTACT
65 The original code this was based on comes from the histogram module as
66 part of the HMMer2 package. Look at http://hmmer.janelia.org/
68 Its use in Bioperl is via the Compiled XS extension which is cared for
69 by Ewan Birney (birney@ebi.ac.uk). Please contact Ewan first about
70 the use of this module
72 =head1 FEEDBACK
74 =head2 Mailing Lists
76 User feedback is an integral part of the evolution of this and other
77 Bioperl modules. Send your comments and suggestions preferably to one
78 of the Bioperl mailing lists. Your participation is much appreciated.
80 bioperl-l@bioperl.org - General discussion
81 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
83 =head2 Support
85 Please direct usage questions or support issues to the mailing list:
87 I<bioperl-l@bioperl.org>
89 rather than to the module maintainer directly. Many experienced and
90 reponsive experts will be able look at the problem and quickly
91 address it. Please include a thorough description of the problem
92 with code and data examples if at all possible.
94 =head2 Reporting Bugs
96 Report bugs to the Bioperl bug tracking system to help us keep track
97 the bugs and their resolution. Bug reports can be submitted via the
98 web:
100 http://bugzilla.open-bio.org/
102 =head1 APPENDIX
104 The rest of the documentation details each of the object
105 methods. Internal methods are usually preceded with a _
107 =cut
110 # Let the code begin...
113 package Bio::SearchDist;
114 use strict;
117 BEGIN {
118 eval {
119 require Bio::Ext::Align;
121 if ( $@ ) {
122 print $@;
123 print STDERR ("\nThe C-compiled engine for histogram object (Bio::Ext::Align) has not been installed.\n Please install the bioperl-ext package\n\n");
124 exit(1);
129 use base qw(Bio::Root::Root);
131 sub new {
132 my($class,@args) = @_;
133 my $self = $class->SUPER::new(@args);
134 my($min, $max, $lump) =
135 $self->_rearrange([qw(MIN MAX LUMP)], @args);
137 if( ! $min ) {
138 $min = -100;
141 if( ! $max ) {
142 $max = +100;
145 if( ! $lump ) {
146 $lump = 50;
149 $self->_engine(&Bio::Ext::Align::new_Histogram($min,$max,$lump));
151 return $self;
154 =head2 add_score
156 Title : add_score
157 Usage : $dis->add_score(300);
158 Function: Adds a single score to the distribution
159 Returns : nothing
160 Args :
163 =cut
165 sub add_score{
166 my ($self,$score) = @_;
167 my ($eng);
168 $eng = $self->_engine();
169 #$eng->AddToHistogram($score);
170 $eng->add($score);
173 =head2 fit_evd
175 Title : fit_evd
176 Usage : $dis->fit_evd();
177 Function: fits an evd to the current distribution
178 Returns : 1 if it fits successfully, 0 if not
179 Args :
182 =cut
184 sub fit_evd{
185 my ($self,@args) = @_;
187 return $self->_engine()->fit_EVD(10000,1);
190 =head2 fit_Gaussian
192 Title : fit_Gaussian
193 Usage :
194 Function:
195 Example :
196 Returns :
197 Args :
200 =cut
202 sub fit_Gaussian{
203 my ($self,$high) = @_;
205 if( ! defined $high ) {
206 $high = 10000;
209 return $self->_engine()->fit_Gaussian($high);
213 =head2 evalue
215 Title : evalue
216 Usage : $eval = $dis->evalue($score)
217 Function: Returns the evalue of this score
218 Returns : float
219 Args :
222 =cut
224 sub evalue{
225 my ($self,$score) = @_;
227 return $self->_engine()->evalue($score);
233 =head2 _engine
235 Title : _engine
236 Usage : $obj->_engine($newval)
237 Function: underlyine bp_sw:: histogram engine
238 Returns : value of _engine
239 Args : newvalue (optional)
242 =cut
244 sub _engine{
245 my ($self,$value) = @_;
246 if( defined $value) {
247 $self->{'_engine'} = $value;
249 return $self->{'_engine'};
253 ## End of Package
256 __END__