3 # BioPerl module for Bio::DB::EUtilities::Summary::DocSum
5 # Cared for by Chris Fields
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
13 # Part of the EUtilities BioPerl package
17 Bio::DB::EUtilities::Summary::DocSum - data object for document summary data
28 User feedback is an integral part of the
29 evolution of this and other Bioperl modules. Send
30 your comments and suggestions preferably to one
31 of the Bioperl mailing lists. Your participation
34 bioperl-l@lists.open-bio.org - General discussion
35 http://www.bioperl.org/wiki/Mailing_lists - About the mailing lists
39 Report bugs to the Bioperl bug tracking system to
40 help us keep track the bugs and their resolution.
41 Bug reports can be submitted via the web.
43 http://bugzilla.open-bio.org/
45 =head1 AUTHOR Chris Fields
47 Email cjfields at uiuc dot edu
51 The rest of the documentation details each of the
52 object methods. Internal methods are usually
57 # Let the code begin...
59 package Bio
::Tools
::EUtilities
::Summary
::DocSum
;
63 use base
qw(Bio::Root::Root Bio::Tools::EUtilities::EUtilDataI);
65 use Bio
::Tools
::EUtilities
::Summary
::Item
;
78 my ($class, @args) = @_;
79 my $self = $class->SUPER::new
(@args);
80 my ($type) = $self->_rearrange(['DATATYPE'],@args);
82 $self->eutil('esummary');
83 $self->datatype($type);
90 Usage : my ($id) = $item->get_ids;
91 Function : returns array or array ref with id
92 Returns : array or array ref
94 Note : the behavior of this method remains consistent with other
95 implementations of get_ids(). To retrieve the single DocSum ID
102 return wantarray ?
$self->{'_id'} : [$self->{'_id'}];
108 Usage : my ($id) = $item->get_id;
109 Function : returns UID of record
117 return $self->{'_id'};
123 Usage : while (my $item = $docsum->next_Item) {...}
124 Function : iterates through Items (nested layer of Item)
125 Returns : single Item
126 Args : [optional] single arg (string)
127 'flatten' - iterates through a flattened list ala
128 get_all_DocSum_Items()
133 my ($self, $request) = @_;
134 unless ($self->{"_items_it"}) {
135 #my @items = $self->get_Items;
136 my @items = ($request && $request eq 'flatten') ?
137 $self->get_all_Items :
139 $self->{"_items_it"} = sub {return shift @items}
141 $self->{'_items_it'}->();
147 Usage : my @items = $docsum->get_Items
148 Function : returns list of, well, Items
149 Returns : array of Items
156 return ref $self->{'_items'} ? @
{ $self->{'_items'} } : return ();
161 Title : get_all_Items
162 Usage : my @items = $docsum->get_all_Items
163 Function : returns flattened list of all Item objects (Items, ListItems,
165 Returns : array of Items
167 Note : items are added top-down (similar order to using nested calls)
168 in original list order.
171 Item - Item - Item - Item ...
177 Structure - Structure
183 unless ($self->{'_ordered_items'}) {
184 for my $item ($self->get_Items) {
185 push @
{$self->{'_ordered_items'}}, $item;
186 for my $ls ($item->get_ListItems) {
187 push @
{$self->{'_ordered_items'}}, $ls;
188 for my $st ($ls->get_StructureItems) {
189 push @
{$self->{'_ordered_items'}}, $st;
194 return @
{$self->{'_ordered_items'}};
199 Title : get_all_names
200 Usage : my @names = get_all_names()
201 Function : Returns an array of names for all Item(s) in DocSum.
202 Returns : array of unique strings
210 my @data = grep {!$tmp{$_}++}
211 map {$_->get_name} $self->get_all_Items;
215 =head2 get_Items_by_name
217 Title : get_Items_by_name
218 Usage : my @items = get_Items_by_name('CreateDate')
219 Function : Returns named Item(s) in DocSum (indicated by passed argument)
220 Returns : array of Item objects
221 Args : string (Item name)
225 sub get_Items_by_name
{
226 my ($self, $key) = @_;
228 my @data = grep {$_->get_name eq $key}
229 $self->get_all_Items;
233 =head2 get_contents_by_name
235 Title : get_contents_by_name
236 Usage : my ($data) = get_contents_by_name('CreateDate')
237 Function : Returns content for named Item(s) in DocSum (indicated by
239 Returns : array of values (type varies per Item)
240 Args : string (Item name)
244 sub get_contents_by_name
{
245 my ($self, $key) = @_;
247 my @data = map {$_->get_content}
248 grep {$_->get_name eq $key}
249 $self->get_all_Items;
253 =head2 get_type_by_name
255 Title : get_type_by_name
256 Usage : my $data = get_type_by_name('CreateDate')
257 Function : Returns data type for named Item in DocSum (indicated by
259 Returns : scalar value (string) if present
260 Args : string (Item name)
264 sub get_type_by_name
{
265 my ($self, $key) = @_;
267 my ($it) = grep {$_->get_name eq $key} $self->get_all_Items;
268 return $it->get_type;
274 Usage : $docsum->rewind();
275 Function : rewinds DocSum iterator
278 'recursive' - rewind all DocSum object layers
279 (Items, ListItems, StructureItems)
284 my ($self, $request) = @_;
285 if ($request && $request eq 'all') {
286 map {$_->rewind('all') } $self->get_Items;
288 delete $self->{"_items_it"};
291 # private EUtilDataI method
294 my ($self, $data) = @_;
296 $self->{'_id'} = $data->{Id
} if exists $data->{Id
};
297 for my $sd (@
{ $data->{Item
} } ) {
298 $sd->{Id
} = $data->{Id
} if exists $data->{Id
};
300 Bio
::Tools
::EUtilities
::Summary
::Item
->new(-datatype
=> 'item',
301 -verbose
=> $self->verbose);
302 $subdoc->_add_data($sd);
303 push @
{ $self->{'_items'} }, $subdoc;
306 $self->{'_id'} = $data->{Id
} if exists $data->{Id
};
312 Usage : $foo->to_string()
313 Function : converts current object to string
315 Args : (optional) simple data for text formatting
316 Note : Used generally for debugging and for various print methods
322 my $string = sprintf("%-20s%s\n",'UID', ':'.$self->get_id);
323 while (my $item = $self->next_Item) {
324 $string .= $item->to_string;