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