0
|
1 package Bio::EnsEMBL::DataFile;
|
|
2
|
|
3 use strict;
|
|
4 use warnings;
|
|
5
|
|
6 use base qw/Bio::EnsEMBL::Storable/;
|
|
7
|
|
8 use Bio::EnsEMBL::ApiVersion;
|
|
9 use Bio::EnsEMBL::Utils::Argument qw/rearrange/;
|
|
10 use Bio::EnsEMBL::Utils::Exception qw/throw warning/;
|
|
11 use Bio::EnsEMBL::Utils::Scalar qw/:assert/;
|
|
12 use Bio::EnsEMBL::Utils::URI qw/is_uri/;
|
|
13 use File::Spec;
|
|
14 use Scalar::Util qw(weaken isweak);
|
|
15
|
|
16 =head2 new
|
|
17
|
|
18 Arg [-ADAPTOR] : Bio::EnsEMBL::DBSQL::DataFileAdaptor
|
|
19 Arg [-DBID] : Integer $dbID
|
|
20 Arg [-COORD_SYSTEM] : Bio::EnsEMBL::CoordSystem $coord_system
|
|
21 Arg [-ANALYSIS] : Bio::EnsEMBL::Analysis $analysis
|
|
22 Arg [-NAME] : String $name
|
|
23 Arg [-VERSION_LOCK] : Boolean $version_lock
|
|
24 Arg [-ABSOLUTE] : Boolean $absolute
|
|
25 Arg [-URL] : String $url
|
|
26 Arg [-FILE_TYPE] : String $file_type
|
|
27 Example : Bio::EnsEMBL::DataFile->new();
|
|
28 Description : Returns a new instance of this object
|
|
29 Returntype : Bio::EnsEMBL::DataFile
|
|
30 Exceptions : Thrown if data is not as expected
|
|
31
|
|
32 =cut
|
|
33
|
|
34 sub new {
|
|
35 my ($class, @args) = @_;
|
|
36 my $self = $class->SUPER::new(@args);
|
|
37 my ($coord_system, $analysis, $name, $version_lock, $absolute, $url, $file_type) =
|
|
38 rearrange([qw/coord_system analysis name version_lock absolute url file_type/], @args);
|
|
39
|
|
40 $self->coord_system($coord_system);
|
|
41 $self->analysis($analysis);
|
|
42 $self->name($name);
|
|
43 $self->version_lock($version_lock);
|
|
44 $self->absolute($absolute);
|
|
45 $self->url($url);
|
|
46 $self->file_type($file_type);
|
|
47
|
|
48 return $self;
|
|
49 }
|
|
50
|
|
51 =head2 new_fast
|
|
52
|
|
53 Arg [1] : hashref to be blessed
|
|
54 Description: Construct a new Bio::EnsEMBL::Feature using the hashref.
|
|
55 Exceptions : none
|
|
56 Returntype : Bio::EnsEMBL::Feature
|
|
57 Caller : general, subclass constructors
|
|
58 Status : Stable
|
|
59
|
|
60 =cut
|
|
61
|
|
62 sub new_fast {
|
|
63 my $class = shift;
|
|
64 my $hashref = shift;
|
|
65 my $self = bless $hashref, $class;
|
|
66 weaken($self->{adaptor}) if ( ! isweak($self->{adaptor}) );
|
|
67 return $self;
|
|
68 }
|
|
69
|
|
70 =head2 get_ExternalAdaptor
|
|
71
|
|
72 Arg[1] : Scalar; optional base path. Uses defaults if not given
|
|
73 Example : my $ea = $df->get_ExternalAdaptor('/base/path');
|
|
74 Description : Delegates to the parent adaptor to retrieve the external
|
|
75 adaptor for this data type
|
|
76 Returntype : Adaptor; will be an adaptor that can read the given data file
|
|
77 Exceptions : Thrown if there is no attached adaptor.
|
|
78
|
|
79 =cut
|
|
80
|
|
81 sub get_ExternalAdaptor {
|
|
82 my ($self, $base_path) = @_;
|
|
83 my $adaptor = $self->adaptor();
|
|
84 throw "No DataFileAdaptor found in this object. Cannot request ExternalAdaptor" if ! $adaptor;
|
|
85 return $adaptor->DataFile_to_adaptor($self, $base_path);
|
|
86 }
|
|
87
|
|
88 =head2 path
|
|
89
|
|
90 Arg[1] : Scalar base of the path to use. Can be ignored if the instance
|
|
91 already represents a canonical path
|
|
92 Example : my $f = $df->path();
|
|
93 Description : Used to generate the path to the file resource. Can return a
|
|
94 path to the file or a URL but it is up to the using code to
|
|
95 know how to interprate the different returned forms.
|
|
96
|
|
97 If the data file url is canonical then this is just returned.
|
|
98 If not then a path is generated of the form
|
|
99 B</base/path/production_name/coord_system_version/[software_version]/db_group/name.ext>
|
|
100
|
|
101 Returntype : Scalar the absolute path/url to the given resource
|
|
102 Exceptions : Thrown if the linked Coordinate System lacks a version and the
|
|
103 current database also lacks a default version
|
|
104 Caller : public
|
|
105
|
|
106 =cut
|
|
107
|
|
108
|
|
109 sub path {
|
|
110 my ($self, $base) = @_;
|
|
111 my $all_paths = $self->get_all_paths($base);
|
|
112 return $all_paths->[0];
|
|
113 }
|
|
114
|
|
115 sub get_all_paths {
|
|
116 my ($self, $base) = @_;
|
|
117
|
|
118 return [$self->url()] if $self->absolute();
|
|
119
|
|
120 my @all_paths;
|
|
121
|
|
122 $base = $self->adaptor()->get_base_path($base) if ! $base;
|
|
123
|
|
124 my $production_name = $self->adaptor()->db()->get_MetaContainer()->get_production_name();
|
|
125 my $cs_version = $self->coord_system()->version();
|
|
126 if(! $cs_version) {
|
|
127 my ($highest_cs) = @{$self->adaptor()->db()->get_CoordSystemAdaptor()->fetch_all()};
|
|
128 $cs_version = $highest_cs->version();
|
|
129 }
|
|
130 if(!$cs_version) {
|
|
131 my $name = $self->name();
|
|
132 throw "The file '${name}' in species '${$production_name} is attached to a CoordinateSystem lacking a version and has no default assembly. Please fix";
|
|
133 }
|
|
134
|
|
135 my @portions;
|
|
136 push(@portions, $production_name);
|
|
137 push(@portions, $cs_version);
|
|
138 push(@portions, software_version()) if $self->version_lock();
|
|
139 push(@portions, $self->adaptor()->db()->group());
|
|
140
|
|
141 #Targets are the files to generate
|
|
142 my @targets;
|
|
143 #If URL is populated we assume we need to add this onto the end but removing the /
|
|
144 if($self->url()) {
|
|
145 my @split = split(/\//, $self->url());
|
|
146 push(@targets, [@split]);
|
|
147 }
|
|
148 else {
|
|
149 my $extensions = $self->adaptor()->DataFile_to_extensions($self);
|
|
150 foreach my $ext (@{$extensions}) {
|
|
151 my $filename = sprintf(q{%s.%s}, $self->name(), $ext);
|
|
152 push(@targets, [$filename]);
|
|
153 }
|
|
154 }
|
|
155
|
|
156 my $is_uri = is_uri($base);
|
|
157 foreach my $t (@targets) {
|
|
158 my $path;
|
|
159 if($is_uri) {
|
|
160 $path = join(q{/}, $base, @portions, @{$t});
|
|
161 }
|
|
162 else {
|
|
163 $path = File::Spec->catfile($base, @portions, @{$t});
|
|
164 }
|
|
165 push(@all_paths, $path);
|
|
166 }
|
|
167 return \@all_paths;
|
|
168 }
|
|
169
|
|
170 =head2 coord_system
|
|
171
|
|
172 Arg[1] : Bio::EnsEMBL::CoordSystem Optional setter
|
|
173 Description : Mutator for the coord system field. All files are linked to one
|
|
174 Returntype : Bio::EnsEMBL::CoordSystem
|
|
175 Exceptions : Thrown if not of the expected type
|
|
176
|
|
177 =cut
|
|
178
|
|
179
|
|
180 sub coord_system {
|
|
181 my ($self, $coord_system) = @_;
|
|
182 if(defined $coord_system) {
|
|
183 assert_ref($coord_system, 'Bio::EnsEMBL::CoordSystem', 'coord_system');
|
|
184 $self->{'coord_system'} = $coord_system;
|
|
185 }
|
|
186 return $self->{'coord_system'};
|
|
187 }
|
|
188
|
|
189 =head2 analysis
|
|
190
|
|
191 Arg[1] : Bio::EnsEMBL::Analysis Optional setter
|
|
192 Description : Mutator for the analysis field. All files are linked to one
|
|
193 Returntype : Bio::EnsEMBL::Analysis
|
|
194 Exceptions : Thrown if not of the expected type
|
|
195
|
|
196 =cut
|
|
197
|
|
198 sub analysis {
|
|
199 my ($self, $analysis) = @_;
|
|
200 if(defined $analysis) {
|
|
201 assert_ref($analysis, 'Bio::EnsEMBL::Analysis', 'analysis');
|
|
202 $self->{'analysis'} = $analysis;
|
|
203 }
|
|
204 return $self->{'analysis'};
|
|
205 }
|
|
206
|
|
207 =head2 name
|
|
208
|
|
209 Arg[1] : String Optional setter
|
|
210 Description : Mutator for the name of the file. Can be used in file location
|
|
211 generation
|
|
212 Returntype : String
|
|
213
|
|
214 =cut
|
|
215
|
|
216 sub name {
|
|
217 my ($self, $name) = @_;
|
|
218 if(defined $name) {
|
|
219 $self->{'name'} = $name;
|
|
220 }
|
|
221 return $self->{'name'};
|
|
222 }
|
|
223
|
|
224 =head2 version_lock
|
|
225
|
|
226 Arg[1] : Boolean Optional setter
|
|
227 Description : Boolean indicating if the file is linked to the version of the
|
|
228 database it was found in.
|
|
229 Returntype : Boolean
|
|
230
|
|
231 =cut
|
|
232
|
|
233 sub version_lock {
|
|
234 my ($self, $version_lock) = @_;
|
|
235 if(defined $version_lock) {
|
|
236 assert_boolean($version_lock, 'version_lock');
|
|
237 $self->{'version_lock'} = $version_lock;
|
|
238 }
|
|
239 return $self->{'version_lock'};
|
|
240 }
|
|
241
|
|
242 =head2 absolute
|
|
243
|
|
244 Arg[1] : Boolean Optional setter
|
|
245 Description : Indicates if the URL of this file is an absolute one i.e.
|
|
246 should be used verbatim or not.
|
|
247 Returntype : Boolean
|
|
248
|
|
249 =cut
|
|
250
|
|
251 sub absolute {
|
|
252 my ($self, $absolute) = @_;
|
|
253 if(defined $absolute) {
|
|
254 assert_boolean($absolute, 'absolute');
|
|
255 $self->{'absolute'} = $absolute;
|
|
256 }
|
|
257 return $self->{'absolute'};
|
|
258 }
|
|
259
|
|
260 =head2 url
|
|
261
|
|
262 Arg[1] : String Optional setter
|
|
263 Description : Location of the file. Can be optional and if set means once
|
|
264 we are in an automatic location use this value to locate
|
|
265 the file.
|
|
266 Returntype : String
|
|
267
|
|
268 =cut
|
|
269
|
|
270 sub url {
|
|
271 my ($self, $url) = @_;
|
|
272 $self->{'url'} = $url if defined $url;
|
|
273 return $self->{'url'};
|
|
274 }
|
|
275
|
|
276 =head2 file_type
|
|
277
|
|
278 Arg[1] : String Optional setter
|
|
279 Description : The type of file we are working with. Can be used to generate
|
|
280 a file name.
|
|
281 Returntype : String
|
|
282
|
|
283 =cut
|
|
284
|
|
285 sub file_type {
|
|
286 my ($self, $file_type) = @_;
|
|
287 $self->{'file_type'} = $file_type if defined $file_type;
|
|
288 return $self->{'file_type'};
|
|
289 }
|
|
290
|
|
291 #=head2 files
|
|
292 #
|
|
293 # Args :
|
|
294 # Example : my $files = @{$df->files()};
|
|
295 # Description : Returns all the file names we expect to cover for a flat file
|
|
296 # Returntype : type return_description
|
|
297 # Exceptions :
|
|
298 # Caller : caller
|
|
299 # Status : status
|
|
300 #
|
|
301 #=cut
|
|
302 #
|
|
303 #
|
|
304 #sub files {
|
|
305 # my ($self) = @_;
|
|
306 #
|
|
307 #}
|
|
308
|
|
309 1; |