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 =head1 AUTHOR
|
|
20
|
|
21 Juguang Xiao <juguang@tll.org.sg>
|
|
22
|
|
23 =cut
|
|
24
|
|
25 =head1 NAME
|
|
26
|
|
27 Bio::EnsEMBL::Utils::EasyArgv
|
|
28
|
|
29 =head1 SYNOPSIS
|
|
30
|
|
31 use Bio::EnsEMBL::Utils::EasyArgv;
|
|
32
|
|
33 my $db = get_ens_db_from_argv; # this method is exported.
|
|
34
|
|
35 use Getopt::Long;
|
|
36
|
|
37 my $others;
|
|
38 &GetOptions( 'others=s' => \$others );
|
|
39
|
|
40 =head1 DESCRIPTION
|
|
41
|
|
42 This is a lazy but easy way to get the db-related arguments. All you
|
|
43 need to do is to invoke get_ens_db_from_argv before using standard
|
|
44 Getopt. The below options will be absorbed and removed from @ARGV.
|
|
45
|
|
46 db_file, host, db_host, dbhost, user, db_user, dbuser, pass, db_pass,
|
|
47 dbpass, dbname, db_name.
|
|
48
|
|
49 Now you can take advantage of Perl's do method to execute a file as perl
|
|
50 script and get returned the last line of it. For your most accessed db
|
|
51 setting, you can have a file named, say, ensdb_homo_core_18.perlobj,
|
|
52 with the content like
|
|
53
|
|
54 use strict; # The ceiling line
|
|
55
|
|
56 use Bio::EnsEMBL::DBSQL::DBAdaptor;
|
|
57
|
|
58 my $db = Bio::EnsEMBL::DBSQL::DBAdaptor->new(
|
|
59 -host => 'ensembldb.ensembl.org',
|
|
60 -user => 'anonymous',
|
|
61 -dbname => 'homo_sapiens_core_18_34'
|
|
62 );
|
|
63
|
|
64 $db; # The floor line
|
|
65
|
|
66 In the your command line, you just need to write like
|
|
67
|
|
68 perl my_script.pl -db_file ensdb_homo_core_18.perlobj
|
|
69
|
|
70 rather than the verbose
|
|
71
|
|
72 -host ensembldb.ensembl.org -user anonymous \
|
|
73 -dbname homo_sapiens_core_18_34
|
|
74
|
|
75 =head1 METHODS
|
|
76
|
|
77 =cut
|
|
78
|
|
79 package Bio::EnsEMBL::Utils::EasyArgv;
|
|
80
|
|
81 use strict;
|
|
82 use vars qw($debug);
|
|
83 use Exporter ();
|
|
84 our @ISA= qw(Exporter);
|
|
85 our @EXPORT = qw(get_ens_db_from_argv
|
|
86 );
|
|
87 use Bio::Root::Root; # For _load_module
|
|
88 use Getopt::Long;
|
|
89
|
|
90 sub _debug_print;
|
|
91
|
|
92 sub get_ens_db_from_argv {
|
|
93 my ($db_file, $host, $user, $pass, $dbname, $driver, $db_module);
|
|
94 $host = 'localhost';
|
|
95 $driver ='mysql';
|
|
96 $db_module = 'Bio::EnsEMBL::SQL::DBAdaptor';
|
|
97 Getopt::Long::config('pass_through');
|
|
98 &GetOptions(
|
|
99 'db_file=s' => \$db_file,
|
|
100 'driver|dbdriver|db_driver=s' => \$driver,
|
|
101 'host|dbhost|db_host=s' => \$host,
|
|
102 'user|dbuser|db_user=s' => \$user,
|
|
103 'pass|dbpass|db_pass=s' => \$pass,
|
|
104 'dbname|db_name=s' => \$dbname,
|
|
105 'db_module=s' => \$db_module
|
|
106 );
|
|
107
|
|
108 my $db;
|
|
109 if(defined $db_file){
|
|
110 -e $db_file or die "'$db_file' is defined but does not exist\n";
|
|
111 eval { $db = do($db_file) };
|
|
112 $@ and die "'$db_file' is not a perlobj file\n";
|
|
113 $db->isa('Bio::EnsEMBL::DBSQL::DBAdaptor')
|
|
114 or die "'$db_file' is not EnsEMBL DBAdaptor\n";
|
|
115 _debug_print "I get a db from file\n";
|
|
116
|
|
117 }elsif(defined $host and defined $user and defined $dbname){
|
|
118 Bio::Root::Root::_load_module($db_module);
|
|
119 $db = $db_module->new(
|
|
120 -host => $host,
|
|
121 -user => $user,
|
|
122 -pass => $pass,
|
|
123 -dbname => $dbname,
|
|
124 -driver => $driver
|
|
125 );
|
|
126 }else{
|
|
127 die "Cannot get the db, due to the insufficient information\n";
|
|
128 }
|
|
129 return $db;
|
|
130 }
|
|
131
|
|
132 sub _debug_print {
|
|
133 print STDERR @_ if $debug;
|
|
134 }
|
|
135
|
|
136
|
|
137 1;
|