package Bio::Phylo::Unparsers::Json;
use strict;
use warnings;
use base 'Bio::Phylo::Unparsers::Abstract';
use Bio::Phylo::Util::CONSTANT qw'/looks_like/';
use Bio::Phylo::Util::Exceptions 'throw';
us
ML::XML2JSON';
=head1 NAME
Bio::Phylo::Unparsers::Json - Serializer used by Bio::Phylo::IO, no serviceable
parts inside
=head1 DESCRIPTION
This module turns the supplied object into a JSON string.
Type : Wrapper
Title : _to_string
Usage : my $json_string = $obj->_to_string;
Function: Stringifies a Bio::Phylo object into a JSON string
Alias :
Returns : SCALAR
Args : Bio::Phyl
ge Bio::Phylo::NeXML::XML2JSON;
use XML::XML2JSON;
use base 'XML::XML2JSON';
use strict;
use warnings;
=head1 NAME
Bio::Phylo::NeXML::XML2JSON - Helps convert NeXML to JSON, no serviceable parts ins
ide
=cut
# As of 2017, the most recent version of XML::XML2JSON seems to have been
# abandoned with a bug in it. It assumes that hash keys are ordered, whereas
# more recent Perl versions randomize
{ $Self->{attribute_prefix} . 'encoding' } || $Obj->{'encoding'} || 'UTF-8';
my $Dom = $XML::XML2JSON::XMLPARSER->createDocument( $Version, $Encoding );
my $GotRoot = 0;
# patch: first filter out
package Bio::Phylo::Parsers::Json;
use strict;
use warnings;
use base 'Bio::Phylo::Parsers::Abstract';
use Bio::Phylo::IO 'parse';
use Bio::Phylo::Util::Exceptions 'throw';
use Bio::Phylo::Util::Depen
2JSON';
=head1 NAME
Bio::Phylo::Parsers::Json - Parser used by Bio::Phylo::IO, no serviceable parts inside
=head1 DESCRIPTION
This module is used to import NeXML data that was re-formatted as JSON
, using
the mapping implemented by L<XML::XML2JSON>. This module is experimental in that
complex NeXML-to-JSON mapped strings may fail to yield valid NeXML (and,
consequently, valid Bio::Phylo objects
m can also be written to NeXML (L<http://www.nexml.org>) using
C<to_xml> and to a JSON mapping thereof using C<to_json>.
=back
=head2 Input and output
The L<Bio::Phylo::IO> module is the unified fr
t=UTF-8',
'phyloxml' => 'application/xml;charset=UTF-8',
'nexus' => 'text/plain',
'json' => 'text/javascript',
'newick' => 'text/plain',
'fasta' => 'text/plain',
);
{
to simple JSON. For a conversion to NeXML/JSON, use C<to_json>.
Type : Serializer
Title : to_js
Usage : my $json = $object->to_js;
Function: Serializes to JSON
Returns : A JSON string
A
rgs : None.
Comments:
=cut
sub to_js {JSON::to_json(shift->_json_data,{'pretty'=>1}) if looks_like_class 'JSON'}
sub _json_data {
my $self = shift;
my %data = %{ $self->
eates a taxon list/table
=begin comment
Type : Wrapper
Title : _to_string
Usage : my $json_string = $obj->_to_string;
Function: Stringifies a Bio::Phylo object into an HTML string
Alias
ethod
Title : _json_data
Usage : $node->_json_data;
Function: Populates a data structure to be serialized as JSON
Returns :
Args :
=end comment
=cut
sub _json_data {
my $s
elf = shift;
my %result = %{ $self->SUPER::_json_data };
$result{'length'} = $self->get_branch_length if defined $self->get_branch_length;
$result{'rank'} = $self->get_rank if $se
lf->get_rank;
$result{'children'} = [ map { $_->_json_data } @{ $self->get_children } ];
return \%result;
}
=begin comment
Type : Internal method
Title : _cleanup
Usage : $tr
phylo>
for any user or developer questions and discussions.
=over
=item L<Bio::Phylo::IO>
The json unparser is called by the L<Bio::Phylo::IO> object.
Look there to learn how to unparse objects.
tp://rutgervos.blogspot.com>.
=item L<http://www.json.org>
To learn more about the JavaScript Object Notation (JSON) format, visit
L<http://www.json.org>.
=back
=head1 CITATION
If you use Bio::Ph
rmats
Returns : [ qw(nexml nexus newick html json phyloxml rss1) ]
Args : NONE
=cut
sub get_supported_formats { [qw(nexml nexus newick html json phyloxml rss1)] }
=item get_authority()
Ge
cy 'JSON';
use Bio::Phylo::Util::Dependency 'URI';
=head1 NAME
Bio::Phylo::Parsers::Tnrs - Parser used by Bio::Phylo::IO, no serviceable parts inside
=head1 DESCRIPTION
This module parses JSON out
taxa = $fac->create_taxa( '-namespaces' => { 'tnrs' => _NS_TNRS_ } );
my $data_structure = JSON::decode_json( do { local $/; <$fh> } );
my %authority;
# iterate over all returned names
for my $n
of supported formats
Returns : [ qw(nexml nexus html json) ]
Args : NONE
=cut
sub get_supported_formats { [ 'nexml', 'html', 'json', 'nexus', 'rss1' ] }
=item get_redirect()
Gets a r
}
}
=item to_json()
Serializes object to JSON string
Type : Serializer
Title : to_json()
Usage : print $obj->to_json();
Function: Serializes object to JSON string
Returns : Str
Args : None
Comments:
=cut
sub to_json {
looks_like_class('Bio::Phylo::NeXML::XML2JSON')->new->convert( shift->to_xml );
}
sub _json_data {
my $self = shift;
my %meta =
ap { $_->get_predicate => $_->get_object } @{ $self->get_meta };
my %result = %{ $self->SUPER::_json_data };
$result{$_} = $meta{$_} for keys %meta;
$result{'name'} = $self->get_name if $self->g
of the provided project
=begin comment
Type : Wrapper
Title : _to_string
Usage : my $json_string = $obj->_to_string;
Function: Stringifies a Bio::Phylo object into an HTML string
Alias
ref of supported formats
Returns : [ 'nexml', 'json', 'nexus', 'rss1' ]
Args : NONE
=cut
sub get_supported_formats { [ 'nexml', 'json', 'nexus', 'rss1' ] }
=item get_authority()
G