Skip to content
Snippets Groups Projects
Commit 6382c604 authored by Andy Yates's avatar Andy Yates
Browse files

Changes to allow for a global path setting to be given as well as delegating...

Changes to allow for a global path setting to be given as well as delegating to the meta table. Also made the data_file be able to hand back the external data adaptor
parent e88eb3bd
No related branches found
No related tags found
No related merge requests found
......@@ -55,6 +55,48 @@ use Bio::EnsEMBL::DBSQL::BaseAdaptor;
use Bio::EnsEMBL::Utils::Exception qw/throw warning/;
use Bio::EnsEMBL::Utils::Scalar qw/:assert/;
my $GLOBAL_BASE_PATH;
=head2 global_base_path
Arg[1] : String; base path
Example : Bio::EnsEMBL::DBSQL::DataFileAdaptor->global_base_path('/base/path');
Description : Stores a global value to be used when building data file paths
Returntype : String
Exceptions : None
=cut
sub global_base_path {
my ($class, $base_path) = @_;
return $GLOBAL_BASE_PATH unless $base_path;
$GLOBAL_BASE_PATH = $base_path;
return $GLOBAL_BASE_PATH;
}
=head2 get_base_path
Arg[1] : String; (optional) base path
Example : $dfa->get_base_path();
Description : If given the path it will return that path; if not it consults
$self->global_base_path() for a value. As a last resort
it will look at the meta table for an entry keyed by
B<data_file.base_path>
Returntype : String
Exceptions : Thrown if nothing is found after consulting all three locations
=cut
sub get_base_path {
my ($self, $path) = @_;
return $path if defined $path;
my $global_base_path = $self->global_base_path();
return $global_base_path if defined $global_base_path;
my $meta_base_path = $self->db()->get_MetaContainer()->single_value_by_key('data_file.base_path', 1);
return $meta_base_path if defined $meta_base_path;
throw "No base path discovered. Either provide a path, set a global using global_base_path() or specify 'data_file.base_path' in meta";
}
=head2 DataFile_to_extension
Arg[1] : Bio::EnsEMBL::DataFile
......
......@@ -67,6 +67,23 @@ sub new_fast {
return $self;
}
=head2 get_ExternalAdaptor
Arg[1] : Scalar; optional base path. Uses defaults if not given
Example : my $ea = $df->get_ExternalAdaptor('/base/path');
Description : Delegates to the parent adaptor to retrieve the external
adaptor for this data type
Returntype : Any; will be an adaptor that can read the given data file
Exceptions : Thrown if there is no attached adaptor. Otherwise
=cut
sub get_ExternalAdaptor {
my ($self, $base_path) = @_;
my $adaptor = $self->adaptor();
throw "No DataFileAdaptor found in this object. Cannot request ExternalAdaptor" if ! $adaptor;
return $adaptor->DataFile_to_adaptor($self, $base_path);
}
=head2 path
......@@ -75,7 +92,12 @@ sub new_fast {
Example : my $f = $df->path();
Description : Used to generate the path to the file resource. Can return a
path to the file or a URL but it is up to the using code to
know how to interprate the different returned forms
know how to interprate the different returned forms.
If the data file url is canonical then this is just returned.
If not then a path is generated of the form
B</base/path/production_name/coord_system_version/[software_version/]db_group/name.ext>
Returntype : Scalar the absolute path/url to the given resource
Exceptions : Thrown if the linked Coordinate System lacks a version and the
current database also lacks a default version
......@@ -87,12 +109,9 @@ sub new_fast {
sub path {
my ($self, $base) = @_;
if($self->absolute()) {
return $self->url();
}
if(! $base) {
throw 'No base given';
}
return $self->url() if $self->absolute();
$base = $self->adaptor()->get_base_path($base) if ! $base;
my $production_name = $self->adaptor()->db()->get_MetaContainer()->get_production_name();
my $cs_version = $self->coord_system()->version();
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment