0
|
1 =head1 LICENSE
|
|
2
|
|
3 Copyright (c) 1999-2012 The European Bioinformatics Institute and
|
|
4 Genome Research Limited. All rights reserved.
|
|
5
|
|
6 This software is distributed under a modified Apache license.
|
|
7 For license details, please see
|
|
8
|
|
9 http://www.ensembl.org/info/about/code_licence.html
|
|
10
|
|
11 =head1 CONTACT
|
|
12
|
|
13 Please email comments or questions to the public Ensembl
|
|
14 developers list at <dev@ensembl.org>.
|
|
15
|
|
16 Questions may also be sent to the Ensembl help desk at
|
|
17 <helpdesk@ensembl.org>.
|
|
18
|
|
19 =cut
|
|
20
|
|
21 =head1 NAME
|
|
22
|
|
23 Bio::EnsEMBL::DBLoader - Run time database loader
|
|
24
|
|
25 =head1 SYNOPSIS
|
|
26
|
|
27 $db =
|
|
28 Bio::EnsEMBL::DBLoader->new( "Bio::EnsEMBL::DBSQL::DBAdaptor/"
|
|
29 . "host=localhost;"
|
|
30 . "dbname=homo_sapiens_core_19_34a;"
|
|
31 . "user=ensro;" );
|
|
32
|
|
33 # $db is a database object
|
|
34 $db = Bio::EnsEMBL::DBLoader->standard();
|
|
35
|
|
36 # equivalent to
|
|
37 # Bio::EnsEMBL::DBLoader->new( $ENV{'ENSEMBL_DATABASE'} );
|
|
38
|
|
39 =head1 DESCRIPTION
|
|
40
|
|
41 This system provides a run-time loading of the database for ensembl,
|
|
42 allowing two things
|
|
43
|
|
44 a) Only "using" the database module which is required for a
|
|
45 particular implementation
|
|
46
|
|
47 b) Providing a simple string method to indicate where the database
|
|
48 is, allowing per sites defaults and other things as such
|
|
49
|
|
50
|
|
51 The string is parsed as follows:
|
|
52
|
|
53 Before the / is the Perl database object to load, after are the
|
|
54 parameters to pass to that database. The parameters are series of
|
|
55 key=values separated by semi-colons. These are passed as a hash to the
|
|
56 new method of the database object
|
|
57
|
|
58 =head1 METHODS
|
|
59
|
|
60 =cut
|
|
61
|
|
62 package Bio::EnsEMBL::DBLoader;
|
|
63
|
|
64 use strict;
|
|
65
|
|
66
|
|
67 =head2 new
|
|
68
|
|
69 Arg [1] : string $string
|
|
70 An Ensembl database locator string.
|
|
71 Example : Bio::EnsEMBL::DBSQL::DBLoader->new("Bio::EnsEMBL::DBSQL::DBAdaptor/host=localhost;dbname=homo_sapiens_core_19_34a;user=ensro;"
|
|
72 Description: Connects to an Ensembl database using the module specified in
|
|
73 the locator string.
|
|
74 Returntype : The module specified in the load string is returned.
|
|
75 Exceptions : thrown if the specified module cannot be instantiated or the
|
|
76 locator string cannot be parsed
|
|
77 Caller : ?
|
|
78 Status : Stable
|
|
79
|
|
80 =cut
|
|
81
|
|
82 sub new{
|
|
83 my ($class,$string) = @_;
|
|
84 my ($module,%hash);
|
|
85
|
|
86 $string =~ /(\S+?)\/([\S+\s*]+)/ || die "Could not parse [$string] as a ensembl database locator. Needs database_module/params";
|
|
87 $module = $1;
|
|
88 my $param = $2;
|
|
89
|
|
90 &_load_module($module);
|
|
91 my @param = split(/;/,$param);
|
|
92 foreach my $keyvalue ( @param ) {
|
|
93 $keyvalue =~ /(\S+?)=([\S*\s*]*)/ || do { warn("In loading $keyvalue, could not split into keyvalue for loading $module. Ignoring"); next; };
|
|
94
|
|
95 my $key = $1;
|
|
96 my $value = $2;
|
|
97
|
|
98 $hash{"-$key"} = $value;
|
|
99 }
|
|
100
|
|
101 my @kv = %hash;
|
|
102
|
|
103 return "$module"->new(%hash);
|
|
104 }
|
|
105
|
|
106
|
|
107 sub _load_module{
|
|
108 my ($modulein) = @_;
|
|
109 my ($module,$load,$m);
|
|
110
|
|
111 $module = "_<$modulein.pm";
|
|
112 $load = "$modulein.pm";
|
|
113 $load =~ s/::/\//g;
|
|
114
|
|
115 return 1 if $main::{$module};
|
|
116 eval {
|
|
117 require $load;
|
|
118 };
|
|
119 if( $@ ) {
|
|
120 print STDERR <<END;
|
|
121 $load: cannot be found
|
|
122 Exception $@
|
|
123
|
|
124 END
|
|
125 ;
|
|
126 return;
|
|
127 }
|
|
128 return 1;
|
|
129 }
|
|
130
|
|
131 1;
|