3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
6 Licensed under the Apache License, Version 2.0 (the
"License");
7 you may not use
this file except in compliance with the License.
8 You may obtain a copy of the License at
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an
"AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License
for the specific language governing permissions and
16 limitations under the License.
23 Please email comments or questions to the
public Ensembl
24 developers list at <http:
26 Questions may also be sent to the Ensembl help desk at
31 Juguang Xiao <juguang@tll.org.sg>
43 my $db = get_ens_db_from_argv; #
this method is exported.
48 &GetOptions(
'others=s' => \$others );
52 This is a lazy but easy way to get the db-related arguments. All you
53 need to
do is to invoke get_ens_db_from_argv before
using standard
54 Getopt. The below options will be absorbed and removed from @ARGV.
56 db_file, host, db_host, dbhost, user, db_user, dbuser, pass, db_pass,
57 dbpass, dbname, db_name.
59 Now you can take advantage of Perl
's do method to execute a file as perl
60 script and get returned the last line of it. For your most accessed db
61 setting, you can have a file named, say, ensdb_homo_core_18.perlobj,
64 use strict; # The ceiling line
66 use Bio::EnsEMBL::DBSQL::DBAdaptor;
68 my $db = Bio::EnsEMBL::DBSQL::DBAdaptor->new(
69 -host => 'ensembldb.ensembl.org
',
71 -dbname => 'homo_sapiens_core_18_34
'
76 In the your command line, you just need to write like
78 perl my_script.pl -db_file ensdb_homo_core_18.perlobj
80 rather than the verbose
82 -host ensembldb.ensembl.org -user anonymous \
83 -dbname homo_sapiens_core_18_34
89 package Bio::EnsEMBL::Utils::EasyArgv;
94 our @ISA= qw(Exporter);
95 our @EXPORT = qw(get_ens_db_from_argv
97 use Bio::Root::Root; # For _load_module
102 sub get_ens_db_from_argv {
103 my ($db_file, $host, $user, $pass, $dbname, $driver, $db_module);
106 $db_module = 'Bio::EnsEMBL::SQL::DBAdaptor
';
107 Getopt::Long::config('pass_through
');
109 'db_file=s
' => \$db_file,
110 'driver|dbdriver|db_driver=s
' => \$driver,
111 'host|dbhost|db_host=s
' => \$host,
112 'user|dbuser|db_user=s
' => \$user,
113 'pass|dbpass|db_pass=s
' => \$pass,
114 'dbname|db_name=s
' => \$dbname,
115 'db_module=s
' => \$db_module
119 if(defined $db_file){
120 -e $db_file or die "'$db_file
' is defined but does not exist\n";
121 eval { $db = do($db_file) };
122 $@ and die "'$db_file
' is not a perlobj file\n";
124 or die "'$db_file
' is not EnsEMBL DBAdaptor\n";
125 _debug_print "I get a db from file\n";
127 }elsif(defined $host and defined $user and defined $dbname){
128 Bio::Root::Root::_load_module($db_module);
129 $db = $db_module->new(
137 die "Cannot get the db, due to the insufficient information\n";
143 print STDERR @_ if $debug;