tag fourth (and hopefully last) alpha
[bioperl-live.git] / branch-1-6 / Bio / DB / Ace.pm
blob75b59c52265498c50d9f8d0745ea98b779950358
2 # $Id$
4 # BioPerl module for Bio::DB::Ace
6 # Please direct questions and support issues to <bioperl-l@bioperl.org>
8 # Cared for by Ewan Birney <birney@ebi.ac.uk>
10 # Copyright Ewan Birney
12 # You may distribute this module under the same terms as perl itself
14 # POD documentation - main docs before the code
16 =head1 NAME
18 Bio::DB::Ace - Database object interface to ACeDB servers
20 =head1 SYNOPSIS
22 $db = Bio::DB::Ace->new( -server => 'myace.server.com', port => '120000');
24 $seq = $db->get_Seq_by_id('MUSIGHBA1'); # Unique ID
26 # or ...
28 $seq = $db->get_Seq_by_acc('J00522'); # Accession Number
30 =head1 DESCRIPTION
32 This provides a standard BioPerl database access to Ace, using Lincoln Steins
33 excellent AcePerl module. You need to download and install the aceperl module from
35 http://stein.cshl.org/AcePerl/
37 before this interface will work.
39 This interface is designed at the moment to work through a aceclient/aceserver
40 type mechanism
42 =head1 INSTALLING ACEPERL
44 Download the latest aceperl tar file, gunzip/untar and cd into the directory.
45 This is a standard CPAN-style directory, so if you go
47 Perl Makefile.PL
48 make
49 <become root>
50 make install
52 Then you will have installed Aceperl. Use the PREFIX mechanism to install elsewhere.
54 =head1 FEEDBACK
56 =head2 Mailing Lists
58 User feedback is an integral part of the evolution of this
59 and other Bioperl modules. Send your comments and suggestions preferably
60 to one of the Bioperl mailing lists.
61 Your participation is much appreciated.
63 bioperl-l@bioperl.org - General discussion
64 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
66 =head2 Support
68 Please direct usage questions or support issues to the mailing list:
70 I<bioperl-l@bioperl.org>
72 rather than to the module maintainer directly. Many experienced and
73 reponsive experts will be able look at the problem and quickly
74 address it. Please include a thorough description of the problem
75 with code and data examples if at all possible.
77 =head2 Reporting Bugs
79 Report bugs to the Bioperl bug tracking system to help us keep track
80 the bugs and their resolution. Bug reports can be submitted via the
81 web:
83 http://bugzilla.open-bio.org/
85 =head1 AUTHOR - Ewan Birney
87 Email birney@ebi.ac.uk
89 =head1 APPENDIX
91 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
93 =cut
95 # Let the code begin...
97 package Bio::DB::Ace;
98 use strict;
100 # Object preamble - inherits from Bio::DB::RandomAccessI
102 use Bio::Seq;
104 BEGIN {
105 eval "require Ace;";
106 if( $@) {
107 print STDERR "You have not installed Ace.pm.\n Read the docs in Bio::DB::Ace for more information about how to do this.\n It is very easy\n\nError message $@";
112 use base qw(Bio::DB::RandomAccessI);
114 # new() is inherited from Bio::DB::Abstract
116 # _initialize is where the heavy stuff will happen when new is called
118 sub new {
119 my($class,@args) = @_;
120 my $self = $class->SUPER::new(@args);
121 my ($host,$port) = $self->_rearrange([qw(
122 HOST
123 PORT
125 @args,
128 if( !$host || !$port ) {
129 $self->throw("Must have a host and port for an acedb server to work");
132 my $aceobj = Ace->connect(-host => $host,
133 -port => $port) ||
134 $self->throw("Could not make acedb object to $host:$port");
136 $self->_aceobj($aceobj);
139 return $self;
142 =head2 get_Seq_by_id
144 Title : get_Seq_by_id
145 Usage : $seq = $db->get_Seq_by_id($uid);
146 Function: Gets a Bio::Seq object by its unique identifier/name
147 Returns : a Bio::Seq object
148 Args : $id : the id (as a string) of the desired sequence entry
150 =cut
152 sub get_Seq_by_id {
153 my $self = shift;
154 my $id = shift or $self->throw("Must supply an identifier!\n");
155 my $ace = $self->_aceobj();
156 my ($seq,$dna,$out);
158 $seq = $ace->fetch( 'Sequence' , $id);
160 # get out the sequence somehow!
162 $dna = $seq->asDNA();
164 $dna =~ s/^>.*\n//;
165 $dna =~ s/\n//g;
167 $out = Bio::Seq->new( -id => $id, -alphabet => 'Dna', -seq => $dna, -name => "Sequence from Bio::DB::Ace $id");
168 return $out;
172 =head2 get_Seq_by_acc
174 Title : get_Seq_by_acc
175 Usage : $seq = $db->get_Seq_by_acc($acc);
176 Function: Gets a Bio::Seq object by its accession number
177 Returns : a Bio::Seq object
178 Args : $acc : the accession number of the desired sequence entry
181 =cut
183 sub get_Seq_by_acc {
185 my $self = shift;
186 my $acc = shift or $self->throw("Must supply an accesion number!\n");
188 return $self->get_Seq_by_id($acc);
191 =head2 _aceobj
193 Title : _aceobj
194 Usage : $ace = $db->_aceobj();
195 Function: Get/Set on the acedb object
196 Returns : Ace object
197 Args : New value of the ace object
199 =cut
201 sub _aceobj {
202 my ($self,$arg) = @_;
204 if( $arg ) {
205 $self->{'_aceobj'} = $arg;
208 return $self->{'_aceobj'};