Bio-Palantir
view release on metacpan or search on metacpan
lib/Bio/Palantir/Parser.pm view on Meta::CPAN
package Bio::Palantir::Parser;
# ABSTRACT: front-end class for Bio::Palantir::Parser module, wich handles the parsing of biosynML.xml and regions.js antiSMASH reports
$Bio::Palantir::Parser::VERSION = '0.211420';
use Moose;
use namespace::autoclean;
use autodie;
use Carp;
use File::Basename 'fileparse';
use File::Temp;
use JSON::Parse 'json_file_to_perl';
use POSIX 'ceil';
use XML::Bare;
use XML::Hash::XS;
use aliased 'Bio::Palantir::Parser::Root';
extends 'Bio::FastParsers::Base';
# ATTRIBUTES
has 'root' => (
is => 'ro',
isa => 'Bio::Palantir::Parser::Root',
init_arg => undef,
lazy => 1,
builder => '_build_root',
);
has 'module_delineation' => (
is => 'ro',
isa => 'Str',
default => 'substrate-selection',
);
## no critic (ProhibitUnusedPrivateSubroutines)
sub _build_root {
my $self = shift;
my @exts = qw(.xml .js);
my ($name, $dir, $ext) = fileparse($self->file, @exts);
my $biosynml = File::Temp->new(suffix => '.xml');
if ($ext eq '.js') {
my $xmlstr = $self->_convert_js2biosynml;
open my $out, '>', $biosynml->filename;
say {$out} $xmlstr;
}
my $file = $ext eq '.xml' ? $self->file : $biosynml->filename;
my $xb = XML::Bare->new( file => $file )
or croak "Can't open '$file' for reading: $!";
my $root = $xb->parse->{'root'};
unless ($root) {
carp "Warning: '$file' unexpectedly empty; returning no root!";
return;
}
( run in 0.415 second using v1.01-cache-2.11-cpan-98e64b0badf )