Bio::Tools::EUtilities::Summary Item
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvs
Summary
Bio::Tools::EUtilities::Summary::Item - simple layered object for DocSum item data
Package variables
No package variables defined.
Inherit
Bio::Root::Root Bio::Tools::EUtilities::EUtilDataI
Synopsis
  # Items can be nested up to three levels at this time. These levels can be
# accessed via Item, ListItem, or StructureItem methods:
while (my $item = $docsum->next_Item) { print "Name: ",$item->get_name,"\n"; print "Data: ",$item->get_content,"\n"; print "Type: ",$item->get_type,"\n"; while (my $ls = $item->next_ListItem) { # do same here while (my $struct = $ls->next_StructureItem) { # do more stuff here } } }
Description
DocSum data, as returned from esummary, normally is a simple list of
item-content-content_type groups. However, items can also contain nested data to
represent more complex data (such as structural data). Up to three nested layers
may appear in any document summary.
This class contains methods to access data that can appear in a docsum for any
individual item as well as describes methods to traverse the hierarchy of items
present in a document summary.
The unique name for items are accessed via get_name(), the content by
get_content() (if present), and the data type by get_type(). Items can have
ListItems (Item objects with a datatype() 'list'), which in turn can have
StructureItems (Item objects with a datatype of 'structure'). Items are
initially traversed via a DocSum object using next_Item() or obtained all at
once with get_Items(). Similarly, nested Items can be accessed by using
next_ListItem/get_ListItems and next_StructureItem/get_StructureItem. A
flattened list of items can be accessed with get_all_Items().
Methods
newDescriptionCode
get_idsDescriptionCode
get_idDescriptionCode
next_ListItemDescriptionCode
get_ListItemsDescriptionCode
next_StructureItemDescriptionCode
get_StructureItemsDescriptionCode
next_subItemDescriptionCode
get_subItemsDescriptionCode
get_nameDescriptionCode
get_typeDescriptionCode
get_contentDescriptionCode
rewindDescriptionCode
next_ItemDescriptionCode
get_ItemsDescriptionCode
get_all_ItemsDescriptionCode
get_all_namesDescriptionCode
get_Items_by_nameDescriptionCode
get_contents_by_nameDescriptionCode
get_type_by_nameDescriptionCode
_add_data
No description
Code
to_stringDescriptionCode
Methods description
newcode    nextTop
 Title    : new
Usage :
Function :
Returns :
Args :
get_idscodeprevnextTop
 Title    : get_ids
Usage : my ($id) = $item->get_ids;
Function : returns array or array ref with id
Returns : array or array ref
Args : none
Note : the behavior of this method is to remain consistent with other
implementations of get_ids(). To retrieve the single DocSum ID use
get_id()
get_idcodeprevnextTop
 Title    : get_id
Usage : my ($id) = $item->get_id;
Function : returns UID of record
Returns : integer
Args : none
next_ListItemcodeprevnextTop
 Title    : next_ListItem
Usage : while (my $ls = $item->next_ListItem) {...}
Function : iterates through ListItems (nested layer of Item)
Returns : single ListItem
Args : none
get_ListItemscodeprevnextTop
 Title    : get_ListItems
Usage : my @ls = $item->get_ListItems
Function : returns list of, well, List Items
Returns : array of List Items
Args : none
next_StructureItemcodeprevnextTop
 Title    : next_StructureItem
Usage : while (my $struc = $ls->next_StructureItem) {...}
Function : iterates through StructureItems (nested layer of ListItem)
Returns : single StructureItems
Args : none
get_StructureItemscodeprevnextTop
 Title    : get_StructureItems
Usage : my @structs = $ls->get_StructureItems
Function : returns list of Structure Items
Returns : array of StructureItems
Args : none
next_subItemcodeprevnextTop
 Title    : next_subItem
Usage : while (my $it = $ls->next_subItem) {...}
Function : iterates through the next layer of Items
Returns : single Item
Args : none
Notes : unlike next_ListItem and next_StructureItem, this generically
accesses any sub Items (useful for recursive calls, for example)
get_subItemscodeprevnextTop
 Title    : get_subItems
Usage : my @items = $ls->get_subItems
Function : returns list of sub Items
Returns : array of Items
Args : none
Notes : unlike get_ListItems and get_StructureItems, this generically
accesses any sub Items (useful for recursive calls, for example)
get_namecodeprevnextTop
 Title    : get_name
Usage : my $nm = $ls->get_name
Function : retrieves Item/ListItem/StructureItem name for this Item
Returns : string
Args : none
get_typecodeprevnextTop
 Title    : get_type
Usage : my $type = $ls->get_type
Function : retrieves Item/ListItem/StructureItem type
Returns : string
Args : none
Note : this is not the same as the datatype(), which describes the
group this Item object belongs to
get_contentcodeprevnextTop
 Title    : get_content
Usage : my $data = $ls->get_content
Function : retrieves Item/ListItem/StructureItem content (if any)
Returns : string
Args : none
rewindcodeprevnextTop
 Title    : rewind
Usage : $item->rewind()
Function : rewinds iterators
Returns : none
Args : [optional] No arg - only rewinds current layer
'all' - rewind all DocSum object layers
(Items, ListItems, StructureItems)
next_ItemcodeprevnextTop
 Title    : next_Item
Usage : while (my $item = $docsum->next_Item) {...}
Function : iterates through Items (nested layer of Item)
Returns : single Item
Args : [optional] single arg (string)
'flatten' - iterates through a flattened list ala
get_all_DocSum_Items()
get_ItemscodeprevnextTop
 Title    : get_Items
Usage : my @items = $docsum->get_Items
Function : returns list of, well, Items
Returns : array of Items
Args : none
get_all_ItemscodeprevnextTop
 Title    : get_all_Items
Usage : my @items = $docsum->get_all_Items
Function : returns flattened list of all Item objects (Items, ListItems,
StructureItems)
Returns : array of Items
Args : none
Note : items are added top-down (similar order to using nested calls)
in original list order.
1 2 7 8 Item - Item - Item - Item ... | | 3 6 ListItem - ListItem | | 4 5 Structure - Structure
get_all_namescodeprevnextTop
 Title    : get_all_names
Usage : my @names = get_all_names()
Function : Returns an array of names for all Item(s) in DocSum.
Returns : array of unique strings
Args : none
get_Items_by_namecodeprevnextTop
 Title    : get_Items_by_name
Usage : my @items = get_Items_by_name('CreateDate')
Function : Returns named Item(s) in DocSum (indicated by passed argument)
Returns : array of Item objects
Args : string (Item name)
get_contents_by_namecodeprevnextTop
 Title    : get_contents_by_name
Usage : my ($data) = get_contents_by_name('CreateDate')
Function : Returns content for named Item(s) in DocSum (indicated by
passed argument)
Returns : array of values (type varies per Item)
Args : string (Item name)
get_type_by_namecodeprevnextTop
 Title    : get_type_by_name
Usage : my $data = get_type_by_name('CreateDate')
Function : Returns data type for named Item in DocSum (indicated by
passed argument)
Returns : scalar value (string) if present
Args : string (Item name)
to_stringcodeprevnextTop
 Title    : to_string
Usage : $foo->to_string()
Function : converts current object to string
Returns : none
Args : (optional) simple data for text formatting. This implementation
passes an argument for layering Items/subItems
Note : Used generically for debugging and print_DocSums methods
Methods code
newdescriptionprevnextTop
sub new {
    my ($class, @args) = @_;
    my $self = $class->SUPER::new(@args);
    my ($type) = $self->_rearrange(['DATATYPE'],@args);
    $type ||= 'item';
    $self->datatype($type);
    $self->eutil('esummary');
    $self->rewind('recursive');
    return $self;
}
get_idsdescriptionprevnextTop
sub get_ids {
    my $self = shift;
    return ($self->{'_id'});
}
get_iddescriptionprevnextTop
sub get_id {
    my $self = shift;
    return $self->{'_id'};
}
next_ListItemdescriptionprevnextTop
sub next_ListItem {
    my $self = shift;
    unless ($self->{'_lists_it'}) {
        my @lists = $self->get_ListItems;
        # reset the structure iterator (required!)
delete $self->{'_structures_it'} if $self->{'_structures_it'}; $self->{'_lists_it'} = sub {return shift @lists} } return $self->{'_lists_it'}->();
}
get_ListItemsdescriptionprevnextTop
sub get_ListItems {
    my $self = shift;
    my @items = $self->get_type eq 'List' ? $self->get_subItems : ();
    return @items;
}
next_StructureItemdescriptionprevnextTop
sub next_StructureItem {
    my $self = shift;
    unless ($self->{'_structures_it'}) {
        my @structs = $self->get_StructureItems;
        $self->{'_structures_it'} = sub {return shift @structs}
    }
    return $self->{'_structures_it'}->();
}
get_StructureItemsdescriptionprevnextTop
sub get_StructureItems {
    my $self = shift;
    my @items = $self->get_type eq 'Structure' ? $self->get_subItems : ();
    return @items;
}
next_subItemdescriptionprevnextTop
sub next_subItem {
    my $self = shift;
    unless ($self->{'_subitem_it'}) {
        my @structs = $self->get_subItems;
        $self->{'_subitem_it'} = sub {return shift @structs}
    }
    return $self->{'_subitem_it'}->();
}
get_subItemsdescriptionprevnextTop
sub get_subItems {
    my $self = shift;
    ref $self->{'_items'}  ? return @{ $self->{'_items'} } : return ();
}
get_namedescriptionprevnextTop
sub get_name {
    my $self = shift;
    return $self->{'_itemname'};
}
get_typedescriptionprevnextTop
sub get_type {
    my $self = shift;
    return $self->{'_itemtype'};
}
get_contentdescriptionprevnextTop
sub get_content {
    my $self = shift;
    return $self->{'_itemcontent'};
}
rewinddescriptionprevnextTop
sub rewind {
    my ($self, $request) = @_;
    if ($request && $request eq 'all') {
        map {$_->rewind()} $self->get_ListItems;
    }
    delete $self->{"_lists_it"} if $self->{"_lists_it"};
    delete $self->{"_structures_it"} if $self->{"_structures_it"};
}
next_ItemdescriptionprevnextTop
sub next_Item {
    my ($self, $request) = @_;
    unless ($self->{"_items_it"}) {
        #my @items = $self->get_Items;
my @items = ($request && $request eq 'flatten') ? $self->get_all_Items : $self->get_Items ; $self->{"_items_it"} = sub {return shift @items} } $self->{'_items_it'}->();
}
get_ItemsdescriptionprevnextTop
sub get_Items {
    my $self = shift;
    return ref $self->{'_items'} ? @{ $self->{'_items'} } : return ();
}
get_all_ItemsdescriptionprevnextTop
sub get_all_Items {
    my $self = shift;
    unless ($self->{'_ordered_items'}) {
        for my $item ($self->get_Items) {
            push @{$self->{'_ordered_items'}}, $item;
            for my $ls ($item->get_ListItems) {
                push @{$self->{'_ordered_items'}}, $ls;
                for my $st ($ls->get_StructureItems) {
                    push @{$self->{'_ordered_items'}}, $st;                
                } 
            }
        }
    }
    return @{$self->{'_ordered_items'}};
}
get_all_namesdescriptionprevnextTop
sub get_all_names {
    my ($self) = @_;
    my %tmp;
    my @data = grep {!$tmp{$_}++}
        map {$_->get_name} $self->get_all_Items;
    return @data;
}
get_Items_by_namedescriptionprevnextTop
sub get_Items_by_name {
    my ($self, $key) = @_;
    return unless $key;
    my @data = grep {$_->get_name eq $key}
        $self->get_all_Items;
    return @data;
}
get_contents_by_namedescriptionprevnextTop
sub get_contents_by_name {
    my ($self, $key) = @_;
    return unless $key;
    my @data = map {$_->get_content} 
        grep {$_->get_name eq $key}
        $self->get_all_Items;
    return @data;
}
get_type_by_namedescriptionprevnextTop
sub get_type_by_name {
    my ($self, $key) = @_;
    return unless $key;
    my ($it) = grep {$_->get_name eq $key} $self->get_all_Items;
    return $it->get_type;
}

# private data method
}
_add_datadescriptionprevnextTop
sub _add_data {
    my ($self, $data) = @_;
    if ($data->{Item}) {
        my $objtype = lc $data->{Type}.'_item';
        $self->{'_id'} = $data->{Id} if exists $data->{Id};
        for my $sd (@{ $data->{Item} } ) {
            $sd->{Id} = $data->{Id} if exists $data->{Id};
            my $subdoc = Bio::Tools::EUtilities::Summary::Item->new(
                                -datatype => $objtype,
                                -verbose => $self->verbose);
            $subdoc->_add_data($sd);
            push @{ $self->{'_items'} }, $subdoc;
        }
    }
    for my $nm (qw(Type content Name)) {
        $self->{'_item'.lc $nm} = $data->{$nm} if defined $data->{$nm};
    }
    $self->{'_id'} = $data->{Id} if exists $data->{Id};
}
to_stringdescriptionprevnextTop
sub to_string {
    my $self = shift;
    my $level = shift || 0;
    # this is the field length for the initial data (spaces are padded in front)
my $pad = 20 - $level; my $content = $self->get_content || ''; my $string .= sprintf("%-*s%-*s%s\n", $level, '', $pad, $self->get_name(), $self->_text_wrap(':', ' ' x ($pad).':', $content)); for my $sub ($self->get_subItems) { $string .= $sub->to_string(4 + $level); } return $string; } 1;
}
General documentation
FEEDBACKTop
Mailing ListsTop
User feedback is an integral part of the
evolution of this and other Bioperl modules. Send
your comments and suggestions preferably to one
of the Bioperl mailing lists. Your participation
is much appreciated.
  bioperl-l@lists.open-bio.org               - General discussion
http://www.bioperl.org/wiki/Mailing_lists - About the mailing lists
Support Top
Please direct usage questions or support issues to the mailing list:
bioperl-l@bioperl.org
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.
Reporting BugsTop
Report bugs to the Bioperl bug tracking system to
help us keep track the bugs and their resolution.
Bug reports can be submitted via the web.
  https://redmine.open-bio.org/projects/bioperl/
AUTHOR Chris FieldsTop
Email cjfields at bioperl dot org
APPENDIXTop
The rest of the documentation details each of the
object methods. Internal methods are usually
preceded with a _
ItemContainerI methodsTop