fixed index bugs, and fixed makefile
[bioperl-live.git] / Bio / SearchDist.pm
blob2b834b76d9f8b6c549292ccaf70d38522686b667
4 # BioPerl module for Bio::SearchDist
6 # Cared for by Ewan Birney <birney@sanger.ac.uk>
8 # Copyright Ewan Birney
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
14 =head1 NAME
16 Bio::SearchDist - A perl wrapper around Sean Eddy's histogram object
18 =head1 SYNOPSIS
20 $dis = Bio::SearchDist->new();
21 foreach $score ( @scores ) {
22 $dis->add_score($score);
25 if( $dis->fit_evd() ) {
26 foreach $score ( @scores ) {
27 $evalue = $dis->evalue($score);
28 print "Score $score had an evalue of $evalue\n";
30 } else {
31 warn("Could not fit histogram to an EVD!");
35 =head1 DESCRIPTION
37 The Bio::SearchDist object is a wrapper around Sean Eddy's excellent
38 histogram object. The histogram object can bascially take in a number
39 of scores which are sensibly distributed somewhere around 0 that come
40 from a supposed Extreme Value Distribution. Having add all the scores
41 from a database search via the add_score method you can then fit a
42 extreme value distribution using ->fit_evd(). Once fitted you can then
43 get out the evalue for each score (or a new score) using
44 ->evalue($score).
46 The fitting procedure is better described in Sean Eddy's own code
47 (available from http://hmmer.wustl.edu, or in the histogram.h header
48 file in Compile/SW). Bascially it fits a EVD via a maximum likelhood
49 method with pruning of the top end of the distribution so that real
50 positives are discarded in the fitting procedure. This comes from
51 an orginally idea of Richard Mott's and the likelhood fitting
52 is from a book by Lawless [should ref here].
55 The object relies on the fact that the scores are sensibly distributed
56 around about 0 and that integer bins are sensible for the
57 histogram. Scores based on bits are often ideal for this (bits based
58 scoring mechanisms is what this histogram object was originally
59 designed for).
62 =head1 CONTACT
64 The original code this was based on comes from the histogram module as
65 part of the HMMer2 package. Look at http://hmmer.wustl.edu/
67 Its use in Bioperl is via the Compiled XS extension which is cared for
68 by Ewan Birney (birney@sanger.ac.uk). Please contact Ewan first about
69 the use of this module
72 =head2 Reporting Bugs
74 Report bugs to the Bioperl bug tracking system to help us keep track
75 the bugs and their resolution. Bug reports can be submitted via email
76 or the web:
78 bioperl-bugs@bio.perl.org
79 http://bio.perl.org/bioperl-bugs/
82 =head1 APPENDIX
84 The rest of the documentation details each of the object
85 methods. Internal methods are usually preceded with a _
87 =cut
90 # Let the code begin...
93 package Bio::SearchDist;
94 use vars qw($AUTOLOAD @ISA);
95 use strict;
97 # Object preamble - inheriets from Bio::Root::Object
99 use Bio::Root::Object;
101 BEGIN {
102 eval {
103 require bp_sw;
105 if ( $@ ) {
106 print STDERR ("\nThe C-compiled engine for histogram object (bp_sw) has not been installed.\n Please read the installation instructions for bioperl for using the compiled extensions\n\n");
107 exit(1);
112 @ISA = qw(Bio::Root::Object Exporter);
113 @EXPORT_OK = qw();
114 # new() is inherited from Bio::Root::Object
116 # _initialize is where the heavy stuff will happen when new is called
118 sub _initialize {
119 my($self,%args) = @_;
120 my($min, $max, $lump) =
121 $self->_rearrange([qw(MIN MAX LUMP)], %args);
123 my $make = $self->SUPER::_initialize(%args);
125 if( ! $min ) {
126 $min = -100;
129 if( ! $max ) {
130 $max = +100;
133 if( ! $lump ) {
134 $lump = 50;
137 $self->_engine(&Wise2::new_Histogram($min,$max,$lump));
139 return $make; # success - we hope!
142 =head2 add_score
144 Title : add_score
145 Usage : $dis->add_score(300);
146 Function: Adds a single score to the distribution
147 Returns : nothing
148 Args :
151 =cut
153 sub add_score{
154 my ($self,$score) = @_;
155 my ($eng);
156 $eng = $self->_engine();
157 $eng->AddToHistogram($score);
161 =head2 fit_evd
163 Title : fit_evd
164 Usage : $dis->fit_evd();
165 Function: fits an evd to the current distribution
166 Returns : 1 if it fits successfully, 0 if not
167 Args :
170 =cut
172 sub fit_evd{
173 my ($self,@args) = @_;
175 return $self->_engine()->ExtremeValueFitHistogram(10000);
179 =head2 evalue
181 Title : evalue
182 Usage : $eval = $dis->evalue($score)
183 Function: Returns the evalue of this score
184 Returns : float
185 Args :
188 =cut
190 sub evalue{
191 my ($self,$score) = @_;
193 return $self->_engine()->evalue($score);
199 =head2 _engine
201 Title : _engine
202 Usage : $obj->_engine($newval)
203 Function: underlyine bp_sw:: histogram engine
204 Returns : value of _engine
205 Args : newvalue (optional)
208 =cut
210 sub _engine{
211 my ($self,$value) = @_;
212 if( defined $value) {
213 $obj->{'_engine'} = $value;
215 return $obj->{'_engine'};
220 ## End of Package
223 __END__