acedb home

Users

Admin/Curation

Developers

Documentation

Showcase

Newsletters

Software

Interfaces

Downloads

Feedback

Search

Introduction to AcePerl

AceDB logo

AcePerl is an excellent Perlmodule which provides access to ACeDB databases, and is written by Lincoln Stein, who also wrote CGI.pm.

AcePerl is an object-oriented Perl module, so you need to be happy with object-oriented Perl to use it. AcePerl can be used to access ACeDB databases either by contacting anaceserver directly, or by wrapping atace process opened on an ACeDB database directory. Access through the server is usually faster and more reliable.

There are two principal types of object in AcePerl, Database handle objects andData objects.

Database handle objects

These are connections to ACeDB databases. A conection is made with the connect()method. This example script opens a connection, and stores it in the variable$db:

    #!/usr/local/bin/perl -w

use strict;
use Ace; # Import the AcePerl library

my $host = 'humsrv1';
my $port = 310000;
my $db = Ace->connect( -host => $host, -port => $port )
or die "Can't connect to '$host' on port '$port' : ", Ace->error;

Data objects

Fetching objects from the database

Once you have a connection to the ACeDB database, objects can be retrieved from it using thefetch() method:

    my $seq = $db->fetch(Sequence => 'bK390B3')
or die "Can't fetch sequence 'bK390B3'";

Accessing tags in the object

The object's data tree can be accessed with the at() method. It is very helpful to have xace open on the model or example data at this stage!

    my $author = $seq->at('Origin.From_Author[1]');
print "Author of $seq is $author\n";

This call fetches the tag one hop to the right (specified by '[1]') of theFrom_Author tag. The full path to the tag through the object (ie: via Origin) must be specified with theat() method.

IMPORTANT: Everything is an object

Everything which you get from a database with AcePerl is an object. These objects automatically convert themselves into a string when called in a string context (in the print statement above for example). What actually happens internally is that thename() method is called on the object.

This can trap you when you store data retrieved with AcePerl in your Perl script (in a hash for example), because you can rapidly run out of memory as you accumulate numbers of large AcePerl objects. If, for instance, you stored the $author object above, then what you actually store is a full AcePerl object, which knows which Class it belongs to and contains a handle to its database.

To store just the string, you need to callname() directly, or put it in string context:

    my( %seq_authors ); # For storing the author of each sequence

# These two lines are equivalent:
$seq_authors{$seq} = "$author";
$seq_authors{$seq} = $author->name;

# ($seq gets stringified because hash keys
# force string context.)

Getting lists of tags

Called in array context, the at() method returns a list of objects. The following piece of code gets the column of sequence object tags to the right of the Subsequencetag, and then uses the row() method to get the two tags one hop to the right:

    my @sub_list = $seq->at('Structure.Subsequence[1]');
foreach my $subseq (@sub_list) {
my($left, $right) = $subseq->row(1);
print "Subsequence: $subseq\t$left\t$right\n";
}

Feedback
last modified Tuesday, 12th Nov, 2002