line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bio::Phylo::Unparsers::Nexus; |
2
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
47
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
81
|
|
4
|
2
|
|
|
2
|
|
11
|
use base 'Bio::Phylo::Unparsers::Abstract'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
538
|
|
5
|
2
|
|
|
2
|
|
12
|
use Bio::Phylo::Util::CONSTANT ':objecttypes'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
394
|
|
6
|
2
|
|
|
2
|
|
11
|
use Bio::Phylo::Util::Exceptions 'throw'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
751
|
|
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
|
|
|
|
|
|
|
sub _to_string { |
54
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
55
|
2
|
|
|
|
|
8
|
my $blocks = $self->{'PHYLO'}; |
56
|
2
|
|
|
|
|
4
|
my $nexus = "#NEXUS\n"; |
57
|
2
|
|
|
|
|
2
|
my $type; |
58
|
2
|
|
|
|
|
4
|
eval { $type = $blocks->_type }; |
|
2
|
|
|
|
|
8
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# array? |
61
|
2
|
50
|
33
|
|
|
35
|
if ($@) { |
|
|
50
|
33
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
|
|
50
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
for my $block (@$blocks) { |
63
|
0
|
|
|
|
|
0
|
eval { $type = $block->_type }; |
|
0
|
|
|
|
|
0
|
|
64
|
0
|
|
|
|
|
0
|
my %args; |
65
|
0
|
0
|
|
|
|
0
|
if ( $type == _FOREST_ ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
0
|
if ( exists $self->{'FOREST_ARGS'} ) { |
67
|
0
|
|
|
|
|
0
|
%args = %{ $self->{'FOREST_ARGS'} }; |
|
0
|
|
|
|
|
0
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
elsif ( $type == _TAXA_ ) { |
71
|
0
|
0
|
|
|
|
0
|
if ( exists $self->{'TAXA_ARGS'} ) { |
72
|
0
|
|
|
|
|
0
|
%args = %{ $self->{'TAXA_ARGS'} }; |
|
0
|
|
|
|
|
0
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
elsif ( $type == _MATRIX_ ) { |
76
|
0
|
0
|
|
|
|
0
|
if ( exists $self->{'MATRIX_ARGS'} ) { |
77
|
0
|
|
|
|
|
0
|
%args = %{ $self->{'MATRIX_ARGS'} }; |
|
0
|
|
|
|
|
0
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
elsif ($@) { |
81
|
0
|
|
|
|
|
0
|
throw 'ObjectMismatch' => "Can't unparse this object: $blocks"; |
82
|
|
|
|
|
|
|
} |
83
|
0
|
|
|
|
|
0
|
$nexus .= $block->to_nexus(%args); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# taxa? |
88
|
|
|
|
|
|
|
elsif ( defined $type and $type == _TAXA_ ) { |
89
|
0
|
|
|
|
|
0
|
my %args; |
90
|
0
|
0
|
|
|
|
0
|
if ( exists $self->{'TAXA_ARGS'} ) { |
91
|
0
|
|
|
|
|
0
|
%args = %{ $self->{'TAXA_ARGS'} }; |
|
0
|
|
|
|
|
0
|
|
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
0
|
$nexus .= $blocks->to_nexus(%args); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# matrix? |
97
|
|
|
|
|
|
|
elsif ( defined $type and $type == _MATRIX_ ) { |
98
|
0
|
|
|
|
|
0
|
my %args; |
99
|
0
|
0
|
|
|
|
0
|
if ( exists $self->{'MATRIX_ARGS'} ) { |
100
|
0
|
|
|
|
|
0
|
%args = %{ $self->{'MATRIX_ARGS'} }; |
|
0
|
|
|
|
|
0
|
|
101
|
|
|
|
|
|
|
} |
102
|
0
|
|
|
|
|
0
|
$nexus .= $blocks->to_nexus(%args); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# forest? |
106
|
|
|
|
|
|
|
elsif ( defined $type and $type == _FOREST_ ) { |
107
|
0
|
|
|
|
|
0
|
my %args; |
108
|
0
|
0
|
|
|
|
0
|
if ( exists $self->{'FOREST_ARGS'} ) { |
109
|
0
|
|
|
|
|
0
|
%args = %{ $self->{'FOREST_ARGS'} }; |
|
0
|
|
|
|
|
0
|
|
110
|
|
|
|
|
|
|
} |
111
|
0
|
|
|
|
|
0
|
$nexus .= $blocks->to_nexus(%args); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# project? |
115
|
|
|
|
|
|
|
elsif ( defined $type and $type == _PROJECT_ ) { |
116
|
2
|
|
|
|
|
3
|
my ( %farg, %marg, %targ ); |
117
|
2
|
50
|
|
|
|
6
|
if ( exists $self->{'TAXA_ARGS'} ) { |
118
|
0
|
|
|
|
|
0
|
%targ = %{ $self->{'TAXA_ARGS'} }; |
|
0
|
|
|
|
|
0
|
|
119
|
|
|
|
|
|
|
} |
120
|
2
|
50
|
|
|
|
4
|
if ( exists $self->{'MATRIX_ARGS'} ) { |
121
|
0
|
|
|
|
|
0
|
%marg = %{ $self->{'MATRIX_ARGS'} }; |
|
0
|
|
|
|
|
0
|
|
122
|
|
|
|
|
|
|
} |
123
|
2
|
100
|
|
|
|
30
|
if ( exists $self->{'FOREST_ARGS'} ) { |
124
|
1
|
|
|
|
|
2
|
%farg = %{ $self->{'FOREST_ARGS'} }; |
|
1
|
|
|
|
|
4
|
|
125
|
|
|
|
|
|
|
} |
126
|
2
|
|
|
|
|
20
|
$nexus = $blocks->to_nexus( %farg, %marg, %targ ); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# wrong! |
130
|
|
|
|
|
|
|
else { |
131
|
0
|
|
|
|
|
0
|
throw 'ObjectMismatch' => "Can't unparse this object: $blocks"; |
132
|
|
|
|
|
|
|
} |
133
|
2
|
|
|
|
|
8
|
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
|
|
|
|
|
|
|
1; |