File Coverage

lib/Bio/MLST/DatabaseSettings.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             package Bio::MLST::DatabaseSettings;
2             # ABSTRACT: Read in an XML file of settings and return a hash with the values.
3             $Bio::MLST::DatabaseSettings::VERSION = '2.1.1630910';
4              
5              
6              
7 5     5   447888 use Moose;
  5         1162207  
  5         48  
8 5     5   32903 use XML::LibXML;
  0            
  0            
9              
10             has 'filename' => ( is => 'ro', isa => 'Str', required => 1 );
11              
12             sub settings
13             {
14             my($self) = @_;
15             my %databases_attributes;
16            
17             my $dom = XML::LibXML->load_xml( location => $self->filename );
18            
19             for my $species ($dom->findnodes('/data/species'))
20             {
21             my $species_name = $self->_clean_string($species->firstChild()->data);
22              
23             $databases_attributes{$species_name}{profiles} = $self->_clean_string($species->findnodes('./mlst/database/profiles/url')->[0]->firstChild()->data);
24            
25             for my $allele ($species->findnodes('./mlst/database/loci/locus'))
26             {
27             if(! defined ($databases_attributes{$species_name}{alleles}) )
28             {
29             $databases_attributes{$species_name}{alleles} = [];
30             }
31             push(@{$databases_attributes{$species_name}{alleles}}, $self->_clean_string($allele->findnodes('./url')->[0]->firstChild()->data));
32             }
33             }
34             return \%databases_attributes;
35             }
36              
37              
38             sub _clean_string
39             {
40             my($self, $input_string) = @_;
41             chomp($input_string);
42             $input_string =~ s![\n\r\t]!!g;
43             return $input_string;
44             }
45              
46             no Moose;
47             __PACKAGE__->meta->make_immutable;
48             1;
49              
50             __END__
51              
52             =pod
53              
54             =encoding UTF-8
55              
56             =head1 NAME
57              
58             Bio::MLST::DatabaseSettings - Read in an XML file of settings and return a hash with the values.
59              
60             =head1 VERSION
61              
62             version 2.1.1630910
63              
64             =head1 SYNOPSIS
65              
66             Read in an XML file of settings and return a hash with the values.
67              
68             use Bio::MLST::DatabaseSettings;
69             my $database_settings = Bio::MLST::DatabaseSettings->new(
70             filename => 'filename'
71             );
72             $database_settings->settings;
73              
74             =head1 METHODS
75              
76             =head2 settings
77              
78             Returns a hash containing the settings for the database, separated by species name, and giving alleles and the profile location.
79              
80             =head1 AUTHOR
81              
82             Andrew J. Page <ap13@sanger.ac.uk>
83              
84             =head1 COPYRIGHT AND LICENSE
85              
86             This software is Copyright (c) 2012 by Wellcome Trust Sanger Institute.
87              
88             This is free software, licensed under:
89              
90             The GNU General Public License, Version 3, June 2007
91              
92             =cut