| 1 | package Bio::Phylo::Unparsers::Taxlist; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use base 'Bio::Phylo::Unparsers::Abstract'; | ||
| 5 | use Bio::Phylo::Util::CONSTANT qw'/looks_like/ :objecttypes'; | ||
| 6 | use Bio::Phylo::Util::Exceptions 'throw'; | ||
| 7 | use Bio::Phylo::Util::Dependency qw'Template'; | ||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | Bio::Phylo::Unparsers::Taxlist - Serializer used by Bio::Phylo::IO, no serviceable | ||
| 12 | parts inside | ||
| 13 | |||
| 14 | =head1 DESCRIPTION | ||
| 15 | |||
| 16 | This module creates a taxon list/table | ||
| 17 | |||
| 18 | =begin comment | ||
| 19 | |||
| 20 | Type : Wrapper | ||
| 21 | Title : _to_string | ||
| 22 | Usage : my $json_string = $obj->_to_string; | ||
| 23 | Function: Stringifies a Bio::Phylo object into an HTML string | ||
| 24 | Alias : | ||
| 25 | Returns : SCALAR | ||
| 26 | Args : Bio::Phylo::* object | ||
| 27 | |||
| 28 | =end comment | ||
| 29 | |||
| 30 | =cut | ||
| 31 | |||
| 32 | sub _to_string { | ||
| 33 | my $self = shift; | ||
| 34 | my $obj = $self->{'PHYLO'}; | ||
| 35 | my $taxa; | ||
| 36 | if ( $obj->_type == _PROJECT_ ) { | ||
| 37 | $taxa = $obj->get_items(_TAXON_); | ||
| 38 | } | ||
| 39 | elsif ( $obj->_type == _TAXA_ ) { | ||
| 40 | $taxa = $obj->get_entities; | ||
| 41 | } | ||
| 42 | else { | ||
| 43 | throw 'ObjectMismatch' => "Can't make taxon list string out of $obj"; | ||
| 44 | } | ||
| 45 | my %predicates; | ||
| 46 | for my $taxon ( @{ $taxa } ) { | ||
| 47 | for my $meta ( @{ $taxon->get_meta } ) { | ||
| 48 | $predicates{$meta->get_predicate} = 1; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | my @predicates = keys %predicates; | ||
| 52 | my $result = ''; | ||
| 53 | if ( @predicates ) { | ||
| 54 | $result .= "name\t" . join("\t",@predicates) . "\n"; | ||
| 55 | } | ||
| 56 | for my $taxon ( @{ $taxa } ) { | ||
| 57 | $result .= $taxon->get_name; | ||
| 58 | if ( @predicates ) { | ||
| 59 | my @values; | ||
| 60 | for my $predicate ( @predicates ) { | ||
| 61 | push @values, $taxon->get_meta_object($predicate); | ||
| 62 | } | ||
| 63 | $result .= "\t" . join("\t",@values); | ||
| 64 | } | ||
| 65 | $result .= "\n"; | ||
| 66 | } | ||
| 67 | return $result; | ||
| 68 | |||
| 69 | } | ||
| 70 | |||
| 71 | # podinherit_insert_token | ||
| 72 | |||
| 73 | =head1 SEE ALSO | ||
| 74 | |||
| 75 | There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo> | ||
| 76 | for any user or developer questions and discussions. | ||
| 77 | |||
| 78 | =over | ||
| 79 | |||
| 80 | =item L<Bio::Phylo::IO> | ||
| 81 | |||
| 82 | The taxlist unparser is called by the L<Bio::Phylo::IO> object. | ||
| 83 | Look there to learn how to unparse objects. | ||
| 84 | |||
| 85 | =item L<Bio::Phylo::Manual> | ||
| 86 | |||
| 87 | Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>. | ||
| 88 | |||
| 89 | =back | ||
| 90 | |||
| 91 | =head1 CITATION | ||
| 92 | |||
| 93 | If you use Bio::Phylo in published research, please cite it: | ||
| 94 | |||
| 95 | B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen> | ||
| 96 | and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl. | ||
| 97 | I<BMC Bioinformatics> B<12>:63. | ||
| 98 | L<http://dx.doi.org/10.1186/1471-2105-12-63> | ||
| 99 | |||
| 100 | =cut | ||
| 101 | |||
| 102 | 1; |