NAME

Bio::Phylo::Listable - List of things, super class for many objects

SYNOPSIS

No direct usage, parent class. Methods documented here 
are available for all objects that inherit from it.

DESCRIPTION

A listable object is an object that contains multiple smaller objects of the same type. For example: a tree contains nodes, so it's a listable object.

This class contains methods that are useful for all listable objects: Matrices (i.e. sets of matrix objects), individual Matrix objects, Datum objects (i.e. character state sequences), Taxa, Forest, Tree and Node objects.

METHODS

CONSTRUCTOR

new()

Listable object constructor.

Type    : Constructor
Title   : new
Usage   : my $obj = Bio::Phylo::Listable->new;
Function: Instantiates a Bio::Phylo::Listable object
Returns : A Bio::Phylo::Listable object.
Args    : none

ARRAY METHODS

insert()

Pushes an object into its container.

Type    : Mutator
Title   : insert
Usage   : $obj->insert($other_obj);
Function: Pushes an object into its container.
Returns : A Bio::Phylo::Listable object.
Args    : A Bio::Phylo::* object.
insert_at_index()

Inserts argument object in container at argument index.

Type    : Mutator
Title   : insert_at_index
Usage   : $obj->insert_at_index($other_obj, $i);
Function: Inserts $other_obj at index $i in container $obj
Returns : A Bio::Phylo::Listable object.
Args    : A Bio::Phylo::* object.
delete()

Deletes argument from container.

Type    : Mutator
Title   : delete
Usage   : $obj->delete($other_obj);
Function: Deletes an object from its container.
Returns : A Bio::Phylo::Listable object.
Args    : A Bio::Phylo::* object.
Note    : Be careful with this method: deleting 
          a node from a tree like this will 
          result in undefined references in its 
          neighbouring nodes. Its children will 
          have their parent reference become 
          undef (instead of pointing to their 
          grandparent, as collapsing a node would 
          do). The same is true for taxon objects 
          that reference datum objects: if the 
          datum object is deleted from a matrix 
          (say), the taxon will now hold undefined 
          references.
clear()

Empties container object.

Type    : Mutator
Title   : clear
Usage   : $obj->clear();
Function: Clears the container.
Returns : A Bio::Phylo::Listable object.
Args    : Note.
Note    : 
prune_entities()

Prunes the container's contents specified by an array reference of indices.

Type    : Mutator
Title   : prune_entities
Usage   : $list->prune_entities([9,7,7,6]);
Function: Prunes a subset of contents
Returns : A Bio::Phylo::Listable object.
Args    : An array reference of indices
keep_entities()

Keeps the container's contents specified by an array reference of indices.

Type    : Mutator
Title   : keep_entities
Usage   : $list->keep_entities([9,7,7,6]);
Function: Keeps a subset of contents
Returns : A Bio::Phylo::Listable object.
Args    : An array reference of indices
get_entities()

Returns a reference to an array of objects contained by the listable object.

Type    : Accessor
Title   : get_entities
Usage   : my @entities = @{ $obj->get_entities };
Function: Retrieves all entities in the container.
Returns : A reference to a list of Bio::Phylo::* 
          objects.
Args    : none.
get_index_of()

Returns the index of the argument in the list, or undef if the list doesn't contain the argument

Type    : Accessor
Title   : get_index_of
Usage   : my $i = $listable->get_index_of($obj)
Function: Returns the index of the argument in the list,
          or undef if the list doesn't contain the argument
Returns : An index or undef
Args    : A contained object
get_by_index()

Gets element at index from container.

Type    : Accessor
Title   : get_by_index
Usage   : my $contained_obj = $obj->get_by_index($i);
Function: Retrieves the i'th entity 
          from a listable object.
Returns : An entity stored by a listable 
          object (or array ref for slices).
Args    : An index or range. This works 
          the way you dereference any perl
          array including through slices, 
          i.e. $obj->get_by_index(0 .. 10)>
          $obj->get_by_index(0, -1) 
          and so on.
Comments: Throws if out-of-bounds
get_by_regular_expression()

Gets elements that match regular expression from container.

Type    : Accessor
Title   : get_by_regular_expression
Usage   : my @objects = @{ 
              $obj->get_by_regular_expression(
                   -value => $method,
                   -match => $re
           ) };
Function: Retrieves the data in the 
          current Bio::Phylo::Listable 
          object whose $method output 
          matches $re
Returns : A list of Bio::Phylo::* objects.
Args    : -value => any of the string 
                    datum props (e.g. 'get_type')
          -match => a compiled regular 
                    expression (e.g. qr/^[D|R]NA$/)
get_by_value()

Gets elements that meet numerical rule from container.

Type    : Accessor
Title   : get_by_value
Usage   : my @objects = @{ $obj->get_by_value(
             -value => $method,
             -ge    => $number
          ) };
Function: Iterates through all objects 
          contained by $obj and returns 
          those for which the output of 
          $method (e.g. get_tree_length) 
          is less than (-lt), less than 
          or equal to (-le), equal to 
          (-eq), greater than or equal to 
          (-ge), or greater than (-gt) $number.
Returns : A reference to an array of objects
Args    : -value => any of the numerical 
                    obj data (e.g. tree length)
          -lt    => less than
          -le    => less than or equals
          -eq    => equals
          -ge    => greater than or equals
          -gt    => greater than
get_by_name()

Gets first element that has argument name

Type    : Accessor
Title   : get_by_name
Usage   : my $found = $obj->get_by_name('foo');
Function: Retrieves the first contained object
          in the current Bio::Phylo::Listable 
          object whose name is 'foo'
Returns : A Bio::Phylo::* object.
Args    : A name (string)

ITERATOR METHODS

first()

Jumps to the first element contained by the listable object.

Type    : Iterator
Title   : first
Usage   : my $first_obj = $obj->first;
Function: Retrieves the first 
          entity in the container.
Returns : A Bio::Phylo::* object
Args    : none.
last()

Jumps to the last element contained by the listable object.

Type    : Iterator
Title   : last
Usage   : my $last_obj = $obj->last;
Function: Retrieves the last 
          entity in the container.
Returns : A Bio::Phylo::* object
Args    : none.
current()

Returns the current focal element of the listable object.

Type    : Iterator
Title   : current
Usage   : my $current_obj = $obj->current;
Function: Retrieves the current focal 
          entity in the container.
Returns : A Bio::Phylo::* object
Args    : none.
next()

Returns the next focal element of the listable object.

Type    : Iterator
Title   : next
Usage   : my $next_obj = $obj->next;
Function: Retrieves the next focal 
          entity in the container.
Returns : A Bio::Phylo::* object
Args    : none.
previous()

Returns the previous element of the listable object.

Type    : Iterator
Title   : previous
Usage   : my $previous_obj = $obj->previous;
Function: Retrieves the previous 
          focal entity in the container.
Returns : A Bio::Phylo::* object
Args    : none.
current_index()

Returns the current internal index of the container.

Type    : Generic query
Title   : current_index
Usage   : my $last_index = $obj->current_index;
Function: Returns the current internal 
          index of the container.
Returns : An integer
Args    : none.
last_index()

Returns the highest valid index of the container.

Type    : Generic query
Title   : last_index
Usage   : my $last_index = $obj->last_index;
Function: Returns the highest valid 
          index of the container.
Returns : An integer
Args    : none.

VISITOR METHODS

visit()

Iterates over objects contained by container, executes argument code reference on each.

Type    : Visitor predicate
Title   : visit
Usage   : $obj->visit( 
              sub{ print $_[0]->get_name, "\n" } 
          );
Function: Implements visitor pattern 
          using code reference.
Returns : The container, possibly modified.
Args    : a CODE reference.

TESTS

contains()

Tests whether the container object contains the argument object.

Type    : Test
Title   : contains
Usage   : if ( $obj->contains( $other_obj ) ) {
              # do something
          }
Function: Tests whether the container object 
          contains the argument object
Returns : BOOLEAN
Args    : A Bio::Phylo::* object
can_contain()

Tests if argument can be inserted in container.

Type    : Test
Title   : can_contain
Usage   : &do_something if $listable->can_contain( $obj );
Function: Tests if $obj can be inserted in $listable
Returns : BOOL
Args    : An $obj to test

UTILITY METHODS

set_listener()

Attaches a listener (code ref) which is executed when contents change.

Type    : Utility method
Title   : set_listener
Usage   : $object->set_listener( sub { my $object = shift; } );
Function: Attaches a listener (code ref) which is executed when contents change.
Returns : Invocant.
Args    : A code reference.
Comments: When executed, the code reference will receive $object
          (the container) as its first argument.
notify_listeners()

Notifies listeners of changed contents.

Type    : Utility method
Title   : notify_listeners
Usage   : $object->notify_listeners;
Function: Notifies listeners of changed contents.
Returns : Invocant.
Args    : NONE.
Comments:
clone()

Clones container.

Type    : Utility method
Title   : clone
Usage   : my $clone = $object->clone;
Function: Creates a deep copy of the container.
Returns : A copy of the container.
Args    : NONE.
Comments: Cloning is currently experimental, use with caution.
cross_reference()

The cross_reference method links node and datum objects to the taxa they apply to. After crossreferencing a matrix with a taxa object, every datum object has a reference to a taxon object stored in its $datum->get_taxon field, and every taxon object has a list of references to datum objects stored in its $taxon->get_data field.

Type    : Generic method
Title   : cross_reference
Usage   : $obj->cross_reference($taxa);
Function: Crossreferences the entities 
          in the container with names 
          in $taxa
Returns : string
Args    : A Bio::Phylo::Taxa object
Comments:

SETS MANAGEMENT

Many Bio::Phylo objects are segmented, i.e. they contain one or more subparts of the same type. For example, a matrix contains multiple rows; each row contains multiple cells; a tree contains nodes, and so on. (Segmented objects all inherit from Bio::Phylo::Listable, i.e. the class whose documentation you're reading here.) In many cases it is useful to be able to define subsets of the contents of segmented objects, for example sets of taxon objects inside a taxa block. The Bio::Phylo::Listable object allows this through a number of methods (add_set, remove_set, add_to_set, remove_from_set etc.). Those methods delegate the actual management of the set contents to the Bio::Phylo::Set object. Consult the documentation for Bio::Phylo::Set for a code sample.

add_set()
Type    : Mutator
Title   : add_set
Usage   : $obj->add_set($set)
Function: Associates a Bio::Phylo::Set object with the container
Returns : Invocant
Args    : A Bio::Phylo::Set object
remove_set()
Type    : Mutator
Title   : remove_set
Usage   : $obj->remove_set($set)
Function: Removes association between a Bio::Phylo::Set object and the container
Returns : Invocant
Args    : A Bio::Phylo::Set object
get_sets()
Type    : Accessor
Title   : get_sets
Usage   : my @sets = @{ $obj->get_sets() };
Function: Retrieves all associated Bio::Phylo::Set objects
Returns : Invocant
Args    : None
is_in_set()
Type    : Test
Title   : is_in_set
Usage   : @do_something if $listable->is_in_set($obj,$set);
Function: Returns whether or not the first argument is listed in the second argument
Returns : Boolean
Args    : $obj - an object that may, or may not be in $set
          $set - the Bio::Phylo::Set object to query
Notes   : This method makes two assumptions:
          i) the $set object is associated with the container,
             i.e. add_set($set) has been called previously
          ii) the $obj object is part of the container
          If either assumption is violated a warning message
          is printed.
add_to_set()
Type    : Mutator
Title   : add_to_set
Usage   : $listable->add_to_set($obj,$set);
Function: Adds first argument to the second argument
Returns : Invocant
Args    : $obj - an object to add to $set
          $set - the Bio::Phylo::Set object to add to
Notes   : this method assumes that $obj is already 
          part of the container. If that assumption is
          violated a warning message is printed.
remove_from_set()
Type    : Mutator
Title   : remove_from_set
Usage   : $listable->remove_from_set($obj,$set);
Function: Removes first argument from the second argument
Returns : Invocant
Args    : $obj - an object to remove from $set
          $set - the Bio::Phylo::Set object to remove from
Notes   : this method assumes that $obj is already 
          part of the container. If that assumption is
          violated a warning message is printed.
sets_to_xml()

Returns string representation of sets

Type    : Accessor
Title   : sets_to_xml
Usage   : my $str = $obj->sets_to_xml;
Function: Gets xml string
Returns : Scalar
Args    : None

SEE ALSO

Also see the manual: Bio::Phylo::Manual and http://rutgervos.blogspot.com.

Objects inheriting from Bio::Phylo::Listable

Bio::Phylo::Forest

Iterate over a set of trees.

Bio::Phylo::Forest::Tree

Iterate over nodes in a tree.

Bio::Phylo::Forest::Node

Iterate of children of a node.

Bio::Phylo::Matrices

Iterate over a set of matrices.

Bio::Phylo::Matrices::Matrix

Iterate over the datum objects in a matrix.

Bio::Phylo::Matrices::Datum

Iterate over the characters in a datum.

Bio::Phylo::Taxa

Iterate over a set of taxa.

Superclasses

Bio::Phylo::NeXML::Writable

This object inherits from Bio::Phylo::NeXML::Writable, so methods defined there are also applicable here.

CITATION

If you use Bio::Phylo in published research, please cite it:

Rutger A Vos, Jason Caravas, Klaas Hartmann, Mark A Jensen and Chase Miller, 2011. Bio::Phylo - phyloinformatic analysis using Perl. BMC Bioinformatics 12:63. http://dx.doi.org/10.1186/1471-2105-12-63