| 1 | package Bio::Phylo::Unparsers::Mrp; | ||
| 2 | use strict; | ||
| 3 | use base 'Bio::Phylo::Unparsers::Abstract'; | ||
| 4 | use Bio::Phylo::Util::CONSTANT qw'/looks_like/ :objecttypes'; | ||
| 5 | use Bio::Phylo::Util::Exceptions 'throw'; | ||
| 6 | use Bio::Phylo::Factory; | ||
| 7 | |||
| 8 | my $factory = Bio::Phylo::Factory->new; | ||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | Bio::Phylo::Unparsers::Mrp - Serializer used by Bio::Phylo::IO, no serviceable parts inside | ||
| 13 | |||
| 14 | =head1 DESCRIPTION | ||
| 15 | |||
| 16 | This module turns a L<Bio::Phylo::Forest> object into an MRP nexus | ||
| 17 | formatted matrix. It is called by the L<Bio::Phylo::IO> facade, don't call it | ||
| 18 | directly. | ||
| 19 | |||
| 20 | =begin comment | ||
| 21 | |||
| 22 | Type : Wrapper | ||
| 23 | Title : _to_string | ||
| 24 | Usage : my $mrp_string = $mrp->_to_string; | ||
| 25 | Function: Stringifies a matrix object into | ||
| 26 | an MRP nexus formatted table. | ||
| 27 | Alias : | ||
| 28 | Returns : SCALAR | ||
| 29 | Args : Bio::Phylo::Matrices::Matrix; | ||
| 30 | |||
| 31 | =end comment | ||
| 32 | |||
| 33 | =cut | ||
| 34 | |||
| 35 | sub _to_string { | ||
| 36 | my $self = shift; | ||
| 37 | my $forest = $self->{'PHYLO'}; | ||
| 38 | if ( looks_like_implementor $forest, 'get_forests' ) { | ||
| 39 | ($forest) = @{ $forest->get_forests }; | ||
| 40 | } | ||
| 41 | if ( looks_like_implementor $forest, 'make_matrix' ) { | ||
| 42 | my $proj = $factory->create_project; | ||
| 43 | my $matrix = $forest->make_matrix; | ||
| 44 | $proj->insert( $matrix->get_taxa, $matrix ); | ||
| 45 | return $proj->to_nexus( '-charstatelabels' => 1 ); | ||
| 46 | } | ||
| 47 | else { | ||
| 48 | throw 'ObjectMismatch' => "Can't make MRP matrix out of $forest"; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | # podinherit_insert_token | ||
| 53 | |||
| 54 | =head1 SEE ALSO | ||
| 55 | |||
| 56 | There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo> | ||
| 57 | for any user or developer questions and discussions. | ||
| 58 | |||
| 59 | =over | ||
| 60 | |||
| 61 | =item L<Bio::Phylo::IO> | ||
| 62 | |||
| 63 | The mrp unparser is called by the L<Bio::Phylo::IO> object. | ||
| 64 | Look there to learn how to create mrp matrices. | ||
| 65 | |||
| 66 | =item L<Bio::Phylo::Manual> | ||
| 67 | |||
| 68 | Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>. | ||
| 69 | |||
| 70 | =back | ||
| 71 | |||
| 72 | =head1 CITATION | ||
| 73 | |||
| 74 | If you use Bio::Phylo in published research, please cite it: | ||
| 75 | |||
| 76 | B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen> | ||
| 77 | and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl. | ||
| 78 | I<BMC Bioinformatics> B<12>:63. | ||
| 79 | L<http://dx.doi.org/10.1186/1471-2105-12-63> | ||
| 80 | |||
| 81 | =cut | ||
| 82 | |||
| 83 | 1; |