[BioSQL-l] script arguments revolution

Juguang Xiao juguang at tll.org.sg
Fri Nov 28 02:41:24 EST 2003


Hello both users and authors of ensembl scripts, bioperl-db also.

Have you even gotten bored to type '-host localhost -user root -dbname 
homo_sapiens_core_18_34' behind your own or others' ensembl script 
name, repetitively, 27 times a day? Is the below what you have to write 
for each scripts of your own, even the rest of the lines is much 
shorter than these?

use Getopt::Long;
my ($host, $user, $pass, $dbname, $others);
&GetOptions(
	'host|dbhost=s' => \$host,
	'user|dbuser=s' => \$user,
	'pass|dbpass=s' => \$pass,
	'dbname=s' => \$dbname,
	'others=s' => \$others
);
use Bio::EnsEMBL::DBSQL::DBAdaptor;
$db  = Bio::EnsEMBL::DBSQL::DBAdaptor->new(
	-host => $host,
	-user => $host,
	-pass => $pass
	-dbname => $dbname
);

Now, forget these wrist-painful past, and a new method is ready.

-------------
For script users, or command-line typewriters whatever you called 
yourself, also for script authors, you can generate a so-called perl 
object file to store your most accessed db setting. Give the file a 
name, ensdb_homo_core_18.perlobj, with the content like this

use strict;  # The ceiling line
use Bio:: EnsEMBL::DBSQL::DBAdaptor;
my $db = Bio:: EnsEMBL::DBSQL::DBAdaptor->new(
	-host => 'ensembldb.ensembl.org',
	-user => 'anonymous',
	-dbname => 'homo_sapiens_core_18_34'
);
$db;  # The floor line

Then, you can use Perl's do method, another mighty one, to execute the 
specified file and return the last line.

$db = do('ensdb_homo_core_18.perlobj'); # Now you have a ensembl db, in 
one line!!

I suggest the ensembl scripts accept --db_file option to get the 
perlobj file, to release users' figure ache.

----------------
For script authors, you are the supporters of this idea, I prepare a 
utility to facilitate you. 
Bio::EnsEMBL::Utils::EasyArgv::get_ens_db_from_argv is one-line 
solution for you to get db related arguments from @ARGV. Don't you 
think your script head will look nicer if like this?

use Bio::EnsEMBL::Utils::EasyArgv;
my $db = get_ens_db_from_argv; # this method is exported.
use Getopt::Long;
my ($others);
&GetOptions(
	'others=s' => \$others
);

get_ens_db_from_argv will process the usual options, like db_file, 
host, dbhost, user, dbuser, pass, dbpass, dbname, etc, and removed them 
from @ARGV. If db_file is provided, the db is fetched from the perlobj 
file directly, otherwise, it will be generated in air based other other 
arguments. It also can lead to die unless the users feed the script 
sufficient information.

Comments are welcome!

Juguang



More information about the BioSQL-l mailing list