XMLMetaDataDumper.pm
Go to the documentation of this file.
00001 =head1 LICENSE
00002 
00003 Copyright [2009-2016] EMBL-European Bioinformatics Institute
00004 
00005 Licensed under the Apache License, Version 2.0 (the "License");
00006 you may not use this file except in compliance with the License.
00007 You may obtain a copy of the License at
00008 
00009      http://www.apache.org/licenses/LICENSE-2.0
00010 
00011 Unless required by applicable law or agreed to in writing, software
00012 distributed under the License is distributed on an "AS IS" BASIS,
00013 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 See the License for the specific language governing permissions and
00015 limitations under the License.
00016 
00017 =head1 CONTACT
00018 
00019   Please email comments or questions to the public Ensembl
00020   developers list at <dev@ensembl.org>.
00021 
00022   Questions may also be sent to the Ensembl help desk at
00023   <helpdesk@ensembl.org>.
00024 
00025 =head1 NAME
00026 
00027 Bio::EnsEMBL::MetaData::MetaDataDumper::XMLMetaDataDumper
00028 
00029 =head1 SYNOPSIS
00030 
00031 =head1 DESCRIPTION
00032 
00033 Implementation to dump metadata details to an XML file.
00034 See Bio::EnsEMBL::MetaData::MetaDataDumper for method details.
00035 
00036 =head1 SEE ALSO
00037 Bio::EnsEMBL::MetaData::MetaDataDumper
00038 
00039 =head1 AUTHOR
00040 
00041 Dan Staines
00042 
00043 =cut
00044 
00045 package Bio::EnsEMBL::MetaData::MetaDataDumper::XMLMetaDataDumper;
00046 use base qw( Bio::EnsEMBL::MetaData::MetaDataDumper );
00047 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
00048 use Carp;
00049 use XML::Simple;
00050 use strict;
00051 use warnings;
00052 
00053 sub new {
00054   my ($proto, @args) = @_;
00055   my $self = $proto->SUPER::new(@args);
00056   $self->{file}     ||= "species_metadata.xml";
00057   $self->{division} ||= 1;
00058   return $self;
00059 }
00060 
00061 sub do_dump {
00062   my ($self, $metadata, $outfile) = @_;
00063   $self->logger()->info("Writing XML to " . $outfile);
00064   open(my $xml_file, '>', $outfile) ||
00065     croak "Could not write to " . $outfile;
00066   print $xml_file XML::Simple->new()
00067     ->XMLout($self->metadata_to_hash($metadata), RootName => 'genomes');
00068   close $xml_file;
00069   $self->logger()->info("Completed writing XML to " . $outfile);
00070   return;
00071 }
00072 
00073 sub start {
00074   my ($self, $divisions, $file, $dump_all) = @_;
00075   $self->SUPER::start($divisions, $file, $dump_all);
00076   for my $fh (values %{$self->{files}}) {
00077     print $fh "<genomes>";
00078   }
00079   return;
00080 }
00081 
00082 sub _write_metadata_to_file {
00083   my ($self, $md, $fh, $count) = @_;
00084   print $fh XML::Simple->new()
00085     ->XMLout($md->to_hash(1), RootName => 'genome')
00086     ;
00087   return;
00088 }
00089 
00090 sub end {
00091   my ($self) = @_;
00092   for my $fh (values %{$self->{files}}) {
00093     print $fh "</genomes>\n";
00094   }
00095   $self->SUPER::end();
00096   return;
00097 }
00098 
00099 1;