| 1 | package Bio::Phylo::Unparsers::Pagel; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use base 'Bio::Phylo::Unparsers::Abstract'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Bio::Phylo::Forest::Tree; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | =head1 NAME | ||||||||||
| 8 | |||||||||||
| 9 | Bio::Phylo::Unparsers::Pagel - Serializer used by Bio::Phylo::IO, no serviceable parts inside | ||||||||||
| 10 | |||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||
| 12 | |||||||||||
| 13 | This module unparses a Bio::Phylo data structure into an input file for | ||||||||||
| 14 | Discrete/Continuous/Multistate. The pagel file format (as it is interpreted | ||||||||||
| 15 | here) consists of: | ||||||||||
| 16 | |||||||||||
| 17 | =over | ||||||||||
| 18 | |||||||||||
| 19 | =item first line | ||||||||||
| 20 | |||||||||||
| 21 | the number of tips, the number of characters | ||||||||||
| 22 | |||||||||||
| 23 | =item subsequent lines | ||||||||||
| 24 | |||||||||||
| 25 | offspring name, parent name, branch length, character state(s). | ||||||||||
| 26 | |||||||||||
| 27 | =back | ||||||||||
| 28 | |||||||||||
| 29 | Here is an example of what the output might look like: | ||||||||||
| 30 | |||||||||||
| 31 | 4 2 | ||||||||||
| 32 | A,n1,0.000000,1,2 | ||||||||||
| 33 | B,n1,0.000000,1,2 | ||||||||||
| 34 | n1,n2,0.000000 | ||||||||||
| 35 | C,n2,0.000000,2,2 | ||||||||||
| 36 | n2,n3,0.000000 | ||||||||||
| 37 | D,n3,0.000000,2,1 | ||||||||||
| 38 | |||||||||||
| 39 | To the unparse() function pass a tree object as value of the '-phylo' | ||||||||||
| 40 | argument. The tips in this tree must be linked to taxon objects, and | ||||||||||
| 41 | the taxon objects must be linked to datum objects whose character | ||||||||||
| 42 | state sequences are to be serialized. | ||||||||||
| 43 | |||||||||||
| 44 | During unparsing, the tree is randomly resolved, and branch lengths are | ||||||||||
| 45 | formatted to %f floats (i.e. integers, decimal point, integers). | ||||||||||
| 46 | |||||||||||
| 47 | The pagel module is called by the L<Bio::Phylo::IO> object, so | ||||||||||
| 48 | look there to learn about parsing and serializing in general. | ||||||||||
| 49 | |||||||||||
| 50 | =begin comment | ||||||||||
| 51 | |||||||||||
| 52 | Type : Unparser | ||||||||||
| 53 | Title : to_string($tree) | ||||||||||
| 54 | Usage : $pagel->to_string($tree); | ||||||||||
| 55 | Function: Unparses a Bio::Phylo::Tree object into a pagel formatted string. | ||||||||||
| 56 | Returns : SCALAR | ||||||||||
| 57 | Args : Bio::Phylo::Tree | ||||||||||
| 58 | |||||||||||
| 59 | =end comment | ||||||||||
| 60 | |||||||||||
| 61 | =cut | ||||||||||
| 62 | |||||||||||
| 63 | 2 | ▶ | sub _to_string { | ||||||||
|
Subroutine
_to_string: called CC=6 SCAR=18.4
| |||||||||||
| 64 | 2 | my $self = shift; | |||||||||
| 65 | 2 | my $tree = $self->{'PHYLO'}; | |||||||||
| 66 | 2 | $tree->resolve; | |||||||||
| 67 | 2 | my ( $charcounter, $string ) = 0; | |||||||||
| 68 | 2 | foreach my $node ( @{ $tree->get_entities } ) { | |||||||||
| 69 | 34 | ▶ | if ( $node->get_parent ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 32 | $string .= $node->get_internal_name . ',' | |||||||||
| 71 | . $node->get_parent->get_internal_name . ','; | ||||||||||
| 72 | 32 | ▶ | if ( $node->get_branch_length ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 14 | $string .= sprintf( "%f", $node->get_branch_length ); | |||||||||
| 74 | } | ||||||||||
| 75 | else { | ||||||||||
| 76 | 18 | $string .= sprintf( "%f", 0 ); | |||||||||
| 77 | } | ||||||||||
| 78 | 32 | ▶ | if ( $node->get_taxon ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 0 | my $taxon = $node->get_taxon; | |||||||||
| 80 | 0 | foreach ( @{ $taxon->get_data } ) { | |||||||||
| 81 | 0 | $string .= ',' . $_->get_char; | |||||||||
| 82 | 0 | $charcounter++; | |||||||||
| 83 | } | ||||||||||
| 84 | } | ||||||||||
| 85 | 32 | $string .= "\n"; | |||||||||
| 86 | } | ||||||||||
| 87 | else { | ||||||||||
| 88 | 2 | next; | |||||||||
| 89 | } | ||||||||||
| 90 | } | ||||||||||
| 91 | 2 | my $header = $tree->calc_number_of_terminals . " "; | |||||||||
| 92 | 2 | $header .= $charcounter / $tree->calc_number_of_terminals; | |||||||||
| 93 | 2 | $string = $header . "\n" . $string; | |||||||||
| 94 | 2 | return $string; | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | # podinherit_insert_token | ||||||||||
| 98 | |||||||||||
| 99 | =head1 SEE ALSO | ||||||||||
| 100 | |||||||||||
| 101 | There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo> | ||||||||||
| 102 | for any user or developer questions and discussions. | ||||||||||
| 103 | |||||||||||
| 104 | =over | ||||||||||
| 105 | |||||||||||
| 106 | =item L<Bio::Phylo::IO> | ||||||||||
| 107 | |||||||||||
| 108 | The pagel unparser is called by the L<Bio::Phylo::IO> object. | ||||||||||
| 109 | Look there to learn how to create pagel formatted files. | ||||||||||
| 110 | |||||||||||
| 111 | =item L<Bio::Phylo::Manual> | ||||||||||
| 112 | |||||||||||
| 113 | Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>. | ||||||||||
| 114 | |||||||||||
| 115 | =back | ||||||||||
| 116 | |||||||||||
| 117 | =head1 CITATION | ||||||||||
| 118 | |||||||||||
| 119 | If you use Bio::Phylo in published research, please cite it: | ||||||||||
| 120 | |||||||||||
| 121 | B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen> | ||||||||||
| 122 | and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl. | ||||||||||
| 123 | I<BMC Bioinformatics> B<12>:63. | ||||||||||
| 124 | L<http://dx.doi.org/10.1186/1471-2105-12-63> | ||||||||||
| 125 | |||||||||||
| 126 | =cut | ||||||||||
| 127 | |||||||||||
| 128 | 1 | 1; | |||||||||