3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
6 Licensed under the Apache License, Version 2.0 (the
"License");
7 you may not use
this file except in compliance with the License.
8 You may obtain a copy of the License at
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an
"AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License
for the specific language governing permissions and
16 limitations under the License.
20 package Bio::EnsEMBL::DataFile;
37 Arg [-DBID] : Integer $dbID
40 Arg [-NAME] : String $name
41 Arg [-VERSION_LOCK] : Boolean $version_lock
42 Arg [-ABSOLUTE] : Boolean $absolute
43 Arg [-URL] : String $url
44 Arg [-FILE_TYPE] : String $file_type
46 Description : Returns a
new instance of
this object
48 Exceptions : Thrown
if data is not as expected
53 my ($class, @args) = @_;
54 my $self = $class->SUPER::new(@args);
55 my ($coord_system, $analysis, $name, $version_lock, $absolute, $url, $file_type) =
56 rearrange([qw/coord_system analysis name version_lock absolute url file_type/], @args);
58 $self->coord_system($coord_system);
59 $self->analysis($analysis);
61 $self->version_lock($version_lock);
62 $self->absolute($absolute);
64 $self->file_type($file_type);
70 =head2 get_ExternalAdaptor
72 Arg[1] : Scalar; (optional) base path. Uses defaults
if not given
73 Arg[2] : Scalar; (optional) file type
74 Example : my $ea = $df->get_ExternalAdaptor(
'/base/path');
75 Description : Delegates to the parent adaptor to retrieve the external
76 adaptor
for this data type
77 Returntype : Adaptor; will be an adaptor that can read the given data file
78 Exceptions : Thrown
if there is no attached adaptor.
82 sub get_ExternalAdaptor {
83 my ($self, $base_path, $requested_type) = @_;
84 my $adaptor = $self->adaptor();
85 throw "No DataFileAdaptor found in this object. Cannot request ExternalAdaptor" if ! $adaptor;
86 return $adaptor->DataFile_to_adaptor($self, $base_path, $requested_type);
91 Arg[1] : Scalar base of the path to use. Can be ignored
if the instance
92 already represents a canonical path
93 Example : my $f = $df->path();
94 Description : Used to generate the path to the file resource. Can
return a
95 path to the file or a URL but it is up to the
using code to
96 know how to interprate the different returned forms.
98 If the data file url is canonical then
this is just returned.
99 If not then a path is generated of the form
100 B</base/path/production_name/coord_system_version/[software_version]/db_group/name.ext>
102 Returntype : Scalar the absolute path/url to the given resource
103 Exceptions : Thrown
if the linked Coordinate System lacks a version and the
104 current database also lacks a
default version
111 my ($self, $base) = @_;
112 my $all_paths = $self->get_all_paths($base);
113 return $all_paths->[0];
117 my ($self, $base) = @_;
119 return [$self->url()]
if $self->absolute();
123 $base = $self->adaptor()->get_base_path($base)
if ! $base;
125 my $production_name = $self->adaptor()->db()->get_MetaContainer()->get_production_name();
126 my $cs_version = $self->coord_system()->version();
128 my ($highest_cs) = @{$self->adaptor()->db()->get_CoordSystemAdaptor()->fetch_all()};
129 $cs_version = $highest_cs->version();
132 my $name = $self->name();
133 throw "The file '${name}' in species '${$production_name} is attached to a CoordinateSystem lacking a version and has no default assembly. Please fix";
137 push(@portions, $production_name);
138 push(@portions, $cs_version);
139 push(@portions, software_version())
if $self->version_lock();
140 push(@portions, $self->adaptor()->db()->group());
142 #Targets are the files to generate
144 #If URL is populated we assume we need to add this onto the end but removing the /
147 push(@targets, [@split]);
150 my $extensions = $self->adaptor()->DataFile_to_extensions($self);
151 foreach my $ext (@{$extensions}) {
152 my $filename = sprintf(q{%s.%s}, $self->name(), $ext);
153 push(@targets, [$filename]);
157 my $is_uri = is_uri($base);
158 foreach my $t (@targets) {
161 $path = join(q{/}, $base, @portions, @{$t});
164 $path = File::Spec->catfile($base, @portions, @{$t});
166 push(@all_paths, $path);
174 Description : Mutator
for the coord system field. All files are linked to one
176 Exceptions : Thrown
if not of the expected type
182 my ($self, $coord_system) = @_;
183 if(defined $coord_system) {
184 assert_ref($coord_system,
'Bio::EnsEMBL::CoordSystem',
'coord_system');
185 $self->{
'coord_system'} = $coord_system;
187 return $self->{
'coord_system'};
193 Description : Mutator
for the analysis field. All files are linked to one
195 Exceptions : Thrown
if not of the expected type
200 my ($self, $analysis) = @_;
201 if(defined $analysis) {
202 assert_ref($analysis,
'Bio::EnsEMBL::Analysis',
'analysis');
203 $self->{
'analysis'} = $analysis;
205 return $self->{
'analysis'};
210 Arg[1] : String Optional setter
211 Description : Mutator
for the name of the file. Can be used in file location
218 my ($self, $name) = @_;
220 $self->{
'name'} = $name;
222 return $self->{
'name'};
227 Arg[1] : Boolean Optional setter
228 Description : Boolean indicating
if the file is linked to the version of the
229 database it was found in.
235 my ($self, $version_lock) = @_;
236 if(defined $version_lock) {
237 assert_boolean($version_lock,
'version_lock');
238 $self->{
'version_lock'} = $version_lock;
240 return $self->{
'version_lock'};
245 Arg[1] : Boolean Optional setter
246 Description : Indicates
if the URL of
this file is an absolute one i.e.
247 should be used verbatim or not.
253 my ($self, $absolute) = @_;
254 if(defined $absolute) {
255 assert_boolean($absolute,
'absolute');
256 $self->{
'absolute'} = $absolute;
258 return $self->{
'absolute'};
263 Arg[1] : String Optional setter
264 Description : Location of the file. Can be optional and
if set means once
265 we are in an automatic location use
this value to locate
272 my ($self, $url) = @_;
273 $self->{
'url'} = $url
if defined $url;
274 return $self->{
'url'};
279 Arg[1] : String Optional setter
280 Description : The type of file we are working with. Can be used to generate
287 my ($self, $file_type) = @_;
288 $self->{
'file_type'} = $file_type
if defined $file_type;
289 return $self->{
'file_type'};
295 # Example : my $files = @{$df->files()};
296 # Description : Returns all the file names we expect to cover for a flat file
297 # Returntype : type return_description