~ubuntu-branches/ubuntu/trusty/bioperl/trusty

« back to all changes in this revision

Viewing changes to Bio/Tools/EUtilities/EUtilDataI.pm

  • Committer: Package Import Robot
  • Author(s): Charles Plessy
  • Date: 2013-09-22 13:39:48 UTC
  • mfrom: (3.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20130922133948-c6z62zegjyp7ztou
Tags: 1.6.922-1
* New upstream release.
* Replaces and Breaks grinder (<< 0.5.3-3~) because of overlaping contents.
  Closes: #722910
* Stop Replacing and Breaking bioperl ( << 1.6.9 ): not needed anymore. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# BioPerl module for Bio::Tools::EUtilities::EUtilDataI
3
 
#
4
 
# Please direct questions and support issues to <bioperl-l@bioperl.org> 
5
 
#
6
 
# Cared for by Chris Fields <cjfields at bioperl dot org>
7
 
#
8
 
# Copyright Chris Fields
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::Tools::EUtilities::EUtilDataI - eutil data object interface
17
 
 
18
 
=head1 SYNOPSIS
19
 
 
20
 
  # say you had some data in a hash ref ($data) and wanted to create hierarchies
21
 
  # of object using the same interface, starting with the topmost...
22
 
 
23
 
  # $object is a Bio::Tools::EUtilities::EUtilDataI instance
24
 
 
25
 
  $object->_add_data($data);
26
 
 
27
 
  # in _add_data()... sort through keys and create subobjects as needed
28
 
 
29
 
  if ($key eq 'foo') {
30
 
     my $sub = Bio::Tools::EUtilities::FooData->new(-eutil => 'efoo',
31
 
                                                    -type => 'foo');
32
 
     $sub->_add_data($subdata);
33
 
     # store into parent object as needed...
34
 
     ...
35
 
   }
36
 
 
37
 
   # access stored data
38
 
 
39
 
   while (my $sub = $parent->next_Foo) {...}
40
 
 
41
 
 
42
 
=head1 DESCRIPTION
43
 
 
44
 
This is a simple interface which allows creation of simple typed object
45
 
hierarchies. Single layers can be accessed via simple iterators (next_* methods)
46
 
or retrieved all at once (get_*) methods; nested data can be iterated through
47
 
nested iterators for each object, or retrieved using get_all_* methods.
48
 
 
49
 
This interface defines common methods required for all eutil data-holding
50
 
objects: _add_data(), eutil(), and type(). It also specifies inheriting
51
 
interface classes use at least one of three methods: get_ids(), get_term(), or
52
 
get_database(), which are the three types of data that eutils mainly centers on.
53
 
 
54
 
Generally, eutil() is the Bio::Tools::EUtilities parser used to set the data.
55
 
Similarly, datatype() is the specific data type for the class.
56
 
 
57
 
Implementations which rely on subclasses to store data and have iterators should
58
 
also define a generalized rewind() method that (by default) rewinds all
59
 
iterators to the start. Args passed can specify exactly which iterator to rewind
60
 
and (if possible) recursively rewind nested object iterators.
61
 
 
62
 
As the method implies, _add_data() is a private method that adds data chunks to
63
 
the object and sets internal parameters for the various data objects. Methods
64
 
corresponding to the data type simply return the set data or iterate through the
65
 
data sets if the values are more complex. Data can alternatively be passed
66
 
through the object constructor.
67
 
 
68
 
=head2 Support 
69
 
 
70
 
Please direct usage questions or support issues to the mailing list:
71
 
 
72
 
I<bioperl-l@bioperl.org>
73
 
 
74
 
rather than to the module maintainer directly. Many experienced and 
75
 
reponsive experts will be able look at the problem and quickly 
76
 
address it. Please include a thorough description of the problem 
77
 
with code and data examples if at all possible.
78
 
 
79
 
=head2 Reporting Bugs
80
 
 
81
 
Report bugs to the Bioperl bug tracking system to
82
 
help us keep track the bugs and their resolution.
83
 
Bug reports can be submitted via the web.
84
 
 
85
 
  https://redmine.open-bio.org/projects/bioperl/
86
 
 
87
 
=head1 AUTHOR 
88
 
 
89
 
Email cjfields at bioperl dot org
90
 
 
91
 
=head1 APPENDIX
92
 
 
93
 
The rest of the documentation details each of the
94
 
object methods. Internal methods are usually
95
 
preceded with a _
96
 
 
97
 
=cut
98
 
 
99
 
package Bio::Tools::EUtilities::EUtilDataI;
100
 
use strict;
101
 
use warnings;
102
 
use Text::Wrap qw(wrap);
103
 
 
104
 
use base qw(Bio::Root::RootI);
105
 
 
106
 
=head2 eutil
107
 
 
108
 
 Title    : eutil
109
 
 Usage    : $eutil->$foo->eutil
110
 
 Function : Get/Set eutil
111
 
 Returns  : string
112
 
 Args     : string (eutil)
113
 
 Throws   : on invalid eutil
114
 
 
115
 
=cut
116
 
 
117
 
{
118
 
    my %VALID_EUTILS = map {$_ => 1} qw(esearch epost espell egquery elink einfo esummary);
119
 
 
120
 
sub eutil {
121
 
    my ($self, $eutil) = @_;
122
 
    if ($eutil) {
123
 
        $self->throw("$eutil not supported") if !exists $VALID_EUTILS{$eutil};
124
 
        return $self->{'_eutil'} = $eutil; 
125
 
    }
126
 
    return $self->{'_eutil'}; 
127
 
}
128
 
 
129
 
}
130
 
 
131
 
=head2 datatype
132
 
 
133
 
 Title   : type
134
 
 Usage   : $type = $qd->datatype;
135
 
 Function: retrieve simple data type object holds (linkset, docsum, item, etc)
136
 
 Returns : string (eutil name)
137
 
 Args    : none
138
 
 Note    : this is probably more useful for devs than for users as a way to keep
139
 
           track of the various types of modules used
140
 
 
141
 
=cut
142
 
 
143
 
sub datatype {
144
 
    my $self = shift;
145
 
    return $self->{'_type'} = shift if @_;
146
 
    return $self->{'_type'};
147
 
}
148
 
 
149
 
=head2 rewind
150
 
 
151
 
 Title    : rewind
152
 
 Usage    : $esum->rewind
153
 
 Function : rewinds the requested iterator
154
 
 Returns  : none
155
 
 Args     : [OPTIONAL] may include 'all', 'recursive', etc.
156
 
 
157
 
=cut
158
 
 
159
 
sub rewind {
160
 
    shift->warn("Object may not need an iterator.  Please check the documentation.");
161
 
}
162
 
 
163
 
=head2 _add_data
164
 
 
165
 
 Title    : _add_data
166
 
 Usage    : $foo->_add_data($data)
167
 
 Function : adds data to current object as a chunk
168
 
 Returns  : none
169
 
 Args     : hash ref containing relevant data
170
 
 
171
 
=cut
172
 
 
173
 
sub _add_data {
174
 
    shift->throw_not_implemented;
175
 
}
176
 
 
177
 
=head2 to_string
178
 
 
179
 
 Title    : to_string
180
 
 Usage    : $foo->to_string()
181
 
 Function : converts current object to string
182
 
 Returns  : none
183
 
 Args     : (optional) simple data for text formatting
184
 
 Note     : Used generally for debugging and for the print_* methods
185
 
 
186
 
=cut
187
 
 
188
 
sub to_string {
189
 
    shift->throw_not_implemented;
190
 
}
191
 
 
192
 
=head2 _text_wrap
193
 
 
194
 
 Title    : _text_wrap
195
 
 Usage    : $foo->_text_wrap($string)
196
 
 Function : private internal wrapper for Text::Wrap::wrap
197
 
 Returns  : string
198
 
 Args     : string
199
 
 Note     : Internal use only.  Simple wrapper method.
200
 
 
201
 
=cut
202
 
 
203
 
sub _text_wrap {
204
 
    shift;
205
 
    return wrap(@_);
206
 
}
207
 
 
208
 
1;