3 # BioPerl module for Bio::ParameterBaseI
5 # Cared for by Chris Fields <cjfields at uiuc dot edu>
7 # Copyright Chris Fields
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
15 Bio::ParameterBaseI - Simple interface class for any parameter-related data such
16 as IDs, database name, program arguments, and other odds and ends.
20 # Bio::DB::MyParams implements Bio::ParameterBaseI
22 @params = (-db => 'protein',
26 $pobj->Bio::DB::MyDBParams->new();
28 # sets only parameters passed; results in a state change if any parameter
29 # passed is new or differs from previously set value
31 $pobj->set_params(@params);
33 # reset all parameters (sets to undef); results in a state change
35 $pobj->reset_params();
37 # resets parameters to those in %param (sets all others to undef); resets the
38 # object state to indicate change.
40 $pobj->reset_params(@params);
42 # direct get/set; results in a state change if any parameter passed is new or
43 # differs from previously set value
45 $pobj->db('nucleotide');
48 # retrieve list containing set defined parameters
50 %myparams = $pobj->get_parameters();
52 # checks whether the state of the object has changed (i.e. parameter has
55 if ($pobj->parameters_changed) {
58 # return cached search
61 # available parameters
63 @params = $pobj->available_parameters();
65 # retrieve string (URI, query, etc); calling to* methods changes object state
66 # to indicate data hasn't changed (so future calls to parameters_changed()
69 $query = $pobj->to_string(); # returns raw string
70 $uri = $pobj->to_uri(); # returns URI-based object
71 $uri = $pobj->to_my_data_struct(); # returns implemenation-specific data structure
76 This is a class interface which focuses on common parameter-related tasks such
77 as building simple database queries, URI-related requests, program arguments,
80 Implementing classes use the following ways to set parameters:
82 1) Create a new instance of a ParameterBaseI-implementing object.
84 $pobj->Bio::DB::MyParamClass->new(-db => 'local', -id => \@ids);
86 2) Pass the parameters as a hash or array to set_parameters(), which sets the
87 parameters listed in the hash but leaves all others as is.
89 $pobj->set_parameters(-retmax => 100, -retstart => 20);
91 3) Pass the parameters as a hash or array to reset_parameters(), which sets the
92 parameters listed in the hash and resets everything else.
94 $pobj->reset_parameters(-term => 'pyrimidine'); # sets db and id to undef
96 4) Pass values using specific getter/setters.
98 $pobj->id(\@ids); # sets IDs
100 There is no restriction on what one uses to set up individual parameter
101 getter/setters, though there are some other options implemented in BioPerl (for
102 instance, Bio::Root::RootI::_set_from_args()).
104 A key requirement is there be a way to detect changes in the state of the
105 ParameterBaseI object so that any object with a Bio::ParameterBaseI can decide
106 whether to submit a new request or return cached data. State changes are
107 revealed by the returned values of the parameters_changed() method, which is a
108 simple boolean set to TRUE when the object is first instantiated or parameters
111 When retrieving anything using the implementation-specific to_* methods (such as
112 to_query, to_string, to_uri, to_request, etc), the ParameterBaseI object state
113 is set to FALSE to indicate the data has been accessed and indicate reaccessing
114 will retrieve the same value. The observing object can then independently decide
115 whether to rerun the cached query or return a previously cached result.
117 One can also use indiviual getter/setters to retrieve single parameter values as
118 well as use parameter_hash() to retrieve all of the parameters in one go as a
119 hash. To check which parameters are available use available_parameters(). Args
126 User feedback is an integral part of the
127 evolution of this and other Bioperl modules. Send
128 your comments and suggestions preferably to one
129 of the Bioperl mailing lists. Your participation
132 bioperl-l@lists.open-bio.org - General discussion
133 http://www.bioperl.org/wiki/Mailing_lists - About the mailing lists
135 =head2 Reporting Bugs
137 Report bugs to the Bioperl bug tracking system to
138 help us keep track the bugs and their resolution.
139 Bug reports can be submitted via the web.
141 http://bugzilla.open-bio.org/
145 Email cjfields at uiuc dot edu
149 The rest of the documentation details each of the
150 object methods. Internal methods are usually
155 # Let the code begin...
157 package Bio
::ParameterBaseI
;
161 use base
qw(Bio::Root::RootI);
163 =head2 set_parameters
165 Title : set_parameters
166 Usage : $pobj->set_parameters(%params);
167 Function: sets the parameters listed in the hash or array
169 Args : [optional] hash or array of parameter/values.
174 shift->throw_not_implemented;
177 =head2 reset_parameters
179 Title : reset_parameters
180 Usage : resets values
181 Function: resets parameters to either undef or value in passed hash
183 Args : [optional] hash of parameter-value pairs
187 sub reset_parameters
{
188 shift->throw_not_implemented;
191 =head2 parameters_changed
193 Title : parameters_changed
194 Usage : if ($pobj->parameters_changed) {...}
195 Function: Returns boolean true (1) if parameters have changed
196 Returns : Boolean (0 or 1)
197 Args : [optional] Boolean
201 sub parameters_changed
{
202 shift->throw_not_implemented;
205 =head2 available_parameters
207 Title : available_parameters
208 Usage : @params = $pobj->available_parameters()
209 Function: Returns a list of the available parameters
210 Returns : Array of parameters
211 Args : [optional, implementation-dependent] string for returning subset of
216 sub available_parameters
{
217 shift->throw_not_implemented;
220 =head2 get_parameters
222 Title : get_parameters
223 Usage : %params = $pobj->get_parameters;
224 Function: Returns list of key-value pairs of parameter => value
225 Returns : List of key-value pairs
226 Args : [optional] A string is allowed if subsets are wanted or (if a
227 parameter subset is default) 'all' to return all parameters
232 shift->throw_not_implemented;
237 All to_* methods are implementation-specific