Bio-Phylo-Beagle

 view release on metacpan or  search on metacpan

lib/Bio/Phylo/Beagle.pm  view on Meta::CPAN

 Function: Gets instance index
 Returns : beagle instance index
 Args    : NONE

=cut

sub get_instance { $instance{ shift->get_id } }

=item get_tree()

Gets tree

 Type    : Accessor
 Title   : get_tree
 Usage   : my $tree = $beagle->get_tree;
 Function: Gets tree
 Returns : Bio::Phylo::Forest::Tree
 Args    : NONE

=cut

sub get_tree { $tree{ shift->get_id } }

=item get_model()

Gets model

 Type    : Accessor
 Title   : get_model
 Usage   : my $model = $beagle->get_model;
 Function: Gets model
 Returns : Bio::Phylo::Models::Substitution::Dna
 Args    : NONE

=cut

sub get_model { $model{ shift->get_id } }

=back

=head2 METHODS

=over

=item update_transition_matrices()

This function calculates a list of transition probabilities matrices and their
first and second derivatives (if requested).

 Type    : Mutator
 Title   : update_transition_matrices
 Usage   : $beagle->update_transition_matrices( %args )
 Function: Calculate a list of transition probability matrices
 Returns : error code
 Args    : -index  => Optional: Index of eigen-decomposition buffer
           -deriv1 => Optional: List of indices of first derivative matrices to update
           -deriv2 => Optional: List of indices of second derivative matrices to update

=cut

sub update_transition_matrices {
    $logger->info("@_");
    my $self = shift;
    my %args = looks_like_hash @_;
        
    # create node and edge arrays
    my $tree = $self->get_tree;        
    my ( @nodeIndices, @edgeLengths );
    my $nodeIndex = 0;
    $tree->visit_depth_first(
        '-post' => sub {
            my $node = shift;
            if ( not $node->is_root ) {
                push @nodeIndices, $nodeIndex;
                push @edgeLengths, $node->get_branch_length;
                $nodeIndex++;
            }
        }
    );
    my $nodeIndices = $create_intarray->(@nodeIndices);
    my $edgeLengths = $create_doublearray->(@edgeLengths);
    
    my $instance = $self->get_instance;
    my $index = $args{'-index'} || 0;
    my $firstderiv  = $args{'-deriv1'}; # XXX maybe do with $create_intarray
    my $secondderiv = $args{'-deriv2'};
    
    # /**
    #  * @brief Calculate a list of transition probability matrices
    #  *
    #  * This function calculates a list of transition probabilities matrices and their first and
    #  * second derivatives (if requested).
    #  *
    #  * @param instance                  Instance number (input)
    #  * @param eigenIndex                Index of eigen-decomposition buffer (input)
    #  * @param probabilityIndices        List of indices of transition probability matrices to update
    #  *                                   (input)
    #  * @param firstDerivativeIndices    List of indices of first derivative matrices to update
    #  *                                   (input, NULL implies no calculation)
    #  * @param secondDerivativeIndices    List of indices of second derivative matrices to update
    #  *                                   (input, NULL implies no calculation)
    #  * @param edgeLengths               List of edge lengths with which to perform calculations (input)
    #  * @param count                     Length of lists
    #  *
    #  * @return error code
    #  */        
    return beagle::beagleUpdateTransitionMatrices(
        $instance,    # instance
        0,            # eigenIndex
        $nodeIndices, # probabilityIndices
        $firstderiv,  # firstDerivativeIndices
        $secondderiv, # secondDerivativeIndices
        $edgeLengths, # edgeLengths
        scalar(@nodeIndices) # count
    );
}

=item update_partials()

This function either calculates or queues for calculation a list partials.
Implementations supporting ASYNCH may queue these calculations while other
implementations perform these operations immediately and in order.

 Type    : Mutator
 Title   : update_partials
 Usage   : $beagle->update_partials( %args )
 Function: Calculate or queue for calculation partials using a list of operations
 Returns : error code
 Args    : -operations => Bio::Phylo::BeagleOperations::Array
           -count      => Number of operations (input)
           -index      => Index number of scaleBuffer to store accumulated factors (input)

=cut

sub update_partials {
    $logger->info("@_");
    my $self = shift;
    if ( my %args = looks_like_hash @_ ) {
        
        my $operations = $args{'-operations'} || throw 'BadArgs' => 'Need -operations argument';
        my $count      = $args{'-count'}      || throw 'BadArgs' => 'Need -count argument';
        my $index      = $args{'-index'}      || throw 'BadArgs' => 'Need -index argument';
        
        # /**
        #  * @brief Calculate or queue for calculation partials using a list of operations
        #  *
        #  * This function either calculates or queues for calculation a list partials. Implementations
        #  * supporting ASYNCH may queue these calculations while other implementations perform these
        #  * operations immediately and in order.
        #  *
        #  * @param instance             Instance number (input)
        #  * @param operations           BeagleOperation list specifying operations (input)
        #  * @param operationCount       Number of operations (input)
        #  * @param cumulativeScaleIndex Index number of scaleBuffer to store accumulated factors (input)
        #  *
        #  * @return error code
        #  */
        return beagle::beagleUpdatePartials(
            $self->get_instance,
            $operations->get_array,
            $count,
            $index
        );
    }
}

=item calculate_root_log_likelihoods()

This function calculates a list of transition probabilities matrices and their
first and second derivatives (if requested).

 Type    : Mutator
 Title   : calculate_root_log_likelihoods
 Usage   : $beagle->calculate_root_log_likelihoods
 Function: Calculate site log likelihoods at a root node
 Returns : log likelihood
 Args    : -category_weights_indices =>  Optional: List of weights to apply to
                                         each partialsBuffer (input). There
                                         should be one categoryCount sized set
                                         for each of parentBufferIndices
           -state_frequencies_indices => Optional: List of state frequencies
                                         for each partialsBuffer (input). There
                                         should be one set for each of
                                         parentBufferIndices
           -count =>                     Optional: Number of partialsBuffer to
                                         integrate (input)
           -cumulative_scale_indices =>  Optional: List of scaleBuffers
                                         containing accumulated factors to apply
                                         to each partialsBuffer (input). There
                                         should be one index for each of
                                         parentBufferIndices

=cut

sub calculate_root_log_likelihoods {



( run in 2.001 seconds using v1.01-cache-2.11-cpan-9581c071862 )