| 1 | package Bio::Phylo::Unparsers::Nexus; | ||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 4 | 2 | ▶ | use base 'Bio::Phylo::Unparsers::Abstract'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Bio::Phylo::Util::CONSTANT ':objecttypes'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Bio::Phylo::Util::Exceptions 'throw'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||
| 10 | Bio::Phylo::Unparsers::Nexus - Serializer used by Bio::Phylo::IO, no serviceable parts inside | ||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||
| 14 | This module turns a L<Bio::Phylo::Matrices::Matrix> object into a nexus | ||||||||||||||||||||||||||
| 15 | formatted matrix. It is called by the L<Bio::Phylo::IO> facade, don't call it | ||||||||||||||||||||||||||
| 16 | directly. You can pass the following additional arguments to the unparse call: | ||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||
| 18 | # an array reference of matrix, forest and taxa objects: | ||||||||||||||||||||||||||
| 19 | -phylo => [ $block1, $block2 ] | ||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||
| 21 | # the arguments that can be passed for matrix objects, | ||||||||||||||||||||||||||
| 22 | # refer to Bio::Phylo::Matrices::Matrix::to_nexus: | ||||||||||||||||||||||||||
| 23 | -matrix_args => {} | ||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||
| 25 | # the arguments that can be passed for forest objects, | ||||||||||||||||||||||||||
| 26 | # refer to Bio::Phylo::Forest::to_nexus: | ||||||||||||||||||||||||||
| 27 | -forest_args => {} | ||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||
| 29 | # the arguments that can be passed for taxa objects, | ||||||||||||||||||||||||||
| 30 | # refer to Bio::Phylo::Taxa::to_nexus: | ||||||||||||||||||||||||||
| 31 | -taxa_args => {} | ||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||
| 33 | OR: | ||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||
| 35 | # for backward compatibility: | ||||||||||||||||||||||||||
| 36 | -phylo => $matrix | ||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||
| 38 | =begin comment | ||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||
| 40 | Type : Wrapper | ||||||||||||||||||||||||||
| 41 | Title : _to_string($matrix) | ||||||||||||||||||||||||||
| 42 | Usage : $nexus->_to_string($matrix); | ||||||||||||||||||||||||||
| 43 | Function: Stringifies a matrix object into | ||||||||||||||||||||||||||
| 44 | a nexus formatted table. | ||||||||||||||||||||||||||
| 45 | Alias : | ||||||||||||||||||||||||||
| 46 | Returns : SCALAR | ||||||||||||||||||||||||||
| 47 | Args : Bio::Phylo::Matrices::Matrix; | ||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||
| 49 | =end comment | ||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||
| 51 | =cut | ||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||
| 53 | 2 | ▶ | sub _to_string { | ||||||||||||||||||||||||
|
Subroutine
_to_string: called CC=24 SCAR=54.7
| |||||||||||||||||||||||||||
| 54 | 2 | my $self = shift; | |||||||||||||||||||||||||
| 55 | 2 | my $blocks = $self->{'PHYLO'}; | |||||||||||||||||||||||||
| 56 | 2 | my $nexus = "#NEXUS\n"; | |||||||||||||||||||||||||
| 57 | 2 | my $type; | |||||||||||||||||||||||||
| 58 | 2 | eval { $type = $blocks->_type }; | |||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||
| 60 | # array? | ||||||||||||||||||||||||||
| 61 | 2 | ▶ | if ($@) { | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 62 | 0 | for my $block (@$blocks) { | |||||||||||||||||||||||||
| 63 | 0 | eval { $type = $block->_type }; | |||||||||||||||||||||||||
| 64 | 0 | my %args; | |||||||||||||||||||||||||
| 65 | 0 | ▶ | if ( $type == _FOREST_ ) { | ||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ( exists $self->{'FOREST_ARGS'} ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 67 | 0 | %args = %{ $self->{'FOREST_ARGS'} }; | |||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||
| 70 | elsif ( $type == _TAXA_ ) { | ||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ( exists $self->{'TAXA_ARGS'} ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 72 | 0 | %args = %{ $self->{'TAXA_ARGS'} }; | |||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||
| 75 | elsif ( $type == _MATRIX_ ) { | ||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ( exists $self->{'MATRIX_ARGS'} ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 77 | 0 | %args = %{ $self->{'MATRIX_ARGS'} }; | |||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||
| 80 | elsif ($@) { | ||||||||||||||||||||||||||
| 81 | 0 | throw 'ObjectMismatch' => "Can't unparse this object: $blocks"; | |||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||
| 83 | 0 | $nexus .= $block->to_nexus(%args); | |||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||
| 87 | # taxa? | ||||||||||||||||||||||||||
| 88 | ▶ | elsif ( defined $type and $type == _TAXA_ ) { | |||||||||||||||||||||||||
|
Condition33%1/3
defined $type and $type == 6
MC/DC0%0/2
defined $type and $type == 6
defined $type
$type == 6
Truth table33%1/3
A and B
A= defined $typeB= $type == 6
| |||||||||||||||||||||||||||
| 89 | 0 | my %args; | |||||||||||||||||||||||||
| 90 | 0 | ▶ | if ( exists $self->{'TAXA_ARGS'} ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 91 | 0 | %args = %{ $self->{'TAXA_ARGS'} }; | |||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||
| 93 | 0 | $nexus .= $blocks->to_nexus(%args); | |||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||
| 96 | # matrix? | ||||||||||||||||||||||||||
| 97 | ▶ | elsif ( defined $type and $type == _MATRIX_ ) { | |||||||||||||||||||||||||
|
Condition33%1/3
defined $type and $type == 8
MC/DC0%0/2
defined $type and $type == 8
defined $type
$type == 8
Truth table33%1/3
A and B
A= defined $typeB= $type == 8
| |||||||||||||||||||||||||||
| 98 | 0 | my %args; | |||||||||||||||||||||||||
| 99 | 0 | ▶ | if ( exists $self->{'MATRIX_ARGS'} ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 100 | 0 | %args = %{ $self->{'MATRIX_ARGS'} }; | |||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||
| 102 | 0 | $nexus .= $blocks->to_nexus(%args); | |||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||
| 105 | # forest? | ||||||||||||||||||||||||||
| 106 | ▶ | elsif ( defined $type and $type == _FOREST_ ) { | |||||||||||||||||||||||||
|
Condition33%1/3
defined $type and $type == 4
MC/DC0%0/2
defined $type and $type == 4
defined $type
$type == 4
Truth table33%1/3
A and B
A= defined $typeB= $type == 4
| |||||||||||||||||||||||||||
| 107 | 0 | my %args; | |||||||||||||||||||||||||
| 108 | 0 | ▶ | if ( exists $self->{'FOREST_ARGS'} ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 109 | 0 | %args = %{ $self->{'FOREST_ARGS'} }; | |||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||
| 111 | 0 | $nexus .= $blocks->to_nexus(%args); | |||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||
| 114 | # project? | ||||||||||||||||||||||||||
| 115 | ▶ | elsif ( defined $type and $type == _PROJECT_ ) { | |||||||||||||||||||||||||
|
Condition33%1/3
defined $type and $type == 9
MC/DC0%0/2
defined $type and $type == 9
defined $type
$type == 9
Truth table33%1/3
A and B
A= defined $typeB= $type == 9
| |||||||||||||||||||||||||||
| 116 | 2 | my ( %farg, %marg, %targ ); | |||||||||||||||||||||||||
| 117 | 2 | ▶ | if ( exists $self->{'TAXA_ARGS'} ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 118 | 0 | %targ = %{ $self->{'TAXA_ARGS'} }; | |||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||
| 120 | 2 | ▶ | if ( exists $self->{'MATRIX_ARGS'} ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 121 | 0 | %marg = %{ $self->{'MATRIX_ARGS'} }; | |||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||
| 123 | 2 | ▶ | if ( exists $self->{'FOREST_ARGS'} ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 124 | 1 | %farg = %{ $self->{'FOREST_ARGS'} }; | |||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||
| 126 | 2 | $nexus = $blocks->to_nexus( %farg, %marg, %targ ); | |||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||
| 129 | # wrong! | ||||||||||||||||||||||||||
| 130 | else { | ||||||||||||||||||||||||||
| 131 | 0 | throw 'ObjectMismatch' => "Can't unparse this object: $blocks"; | |||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||
| 133 | 2 | return $nexus; | |||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||
| 136 | # podinherit_insert_token | ||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||
| 138 | =head1 SEE ALSO | ||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||
| 140 | There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo> | ||||||||||||||||||||||||||
| 141 | for any user or developer questions and discussions. | ||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||
| 143 | =over | ||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||
| 145 | =item L<Bio::Phylo::IO> | ||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||
| 147 | The nexus serializer is called by the L<Bio::Phylo::IO> object. | ||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||
| 149 | =item L<Bio::Phylo::Manual> | ||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||
| 151 | Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>. | ||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||
| 153 | =back | ||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||
| 155 | =head1 CITATION | ||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||
| 157 | If you use Bio::Phylo in published research, please cite it: | ||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||
| 159 | B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen> | ||||||||||||||||||||||||||
| 160 | and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl. | ||||||||||||||||||||||||||
| 161 | I<BMC Bioinformatics> B<12>:63. | ||||||||||||||||||||||||||
| 162 | L<http://dx.doi.org/10.1186/1471-2105-12-63> | ||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||
| 164 | =cut | ||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||
| 166 | 2 | 1; | |||||||||||||||||||||||||