00001 00002 =head1 LICENSE 00003 00004 Copyright [1999-2014] EMBL-European Bioinformatics Institute 00005 00006 Licensed under the Apache License, Version 2.0 (the "License"); 00007 you may not use this file except in compliance with the License. 00008 You may obtain a copy of the License at 00009 00010 http://www.apache.org/licenses/LICENSE-2.0 00011 00012 Unless required by applicable law or agreed to in writing, software 00013 distributed under the License is distributed on an "AS IS" BASIS, 00014 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 See the License for the specific language governing permissions and 00016 limitations under the License. 00017 00018 =head1 CONTACT 00019 00020 Please email comments or questions to the public Ensembl 00021 developers list at <dev@ensembl.org>. 00022 00023 Questions may also be sent to the Ensembl help desk at 00024 <helpdesk@ensembl.org>. 00025 00026 =head1 NAME 00027 00028 Bio::EnsEMBL::MetaData::DatabaseInfo 00029 00030 =head1 SYNOPSIS 00031 00032 my $info = Bio::EnsEMBL::MetaData::DatabaseInfo->new(-DBNAME=>"homo_sapiens_core_84_38", -SUBJECT=>$human_genome); 00033 print $info->dbname(); 00034 00035 =head1 DESCRIPTION 00036 00037 Object encapsulating information about a database that can be associated with genomes or releases. 00038 00039 =head1 AUTHOR 00040 00041 Dan Staines 00042 00043 =head1 SEE ALSO 00044 00045 Bio::EnsEMBL::MetaData::BaseInfo 00046 Bio::EnsEMBL::MetaData::DBSQLDatabaseInfoAdaptor 00047 00048 =cut 00049 00050 package Bio::EnsEMBL::MetaData::DatabaseInfo; 00051 use base qw/Bio::EnsEMBL::MetaData::BaseInfo/; 00052 use strict; 00053 use warnings; 00054 00055 use Bio::EnsEMBL::Utils::Argument qw(rearrange); 00056 use Bio::EnsEMBL::Utils::Exception qw(throw); 00057 00058 =head1 CONSTRUCTOR 00059 =head2 new 00060 Arg [-SUBJECT] : Bio::EnsEMBL::MetaData::GenomeInfo or Bio::EnsEMBL::MetaData::DataReleaseInfo 00061 Arg [-DBNAME] : string - database name 00062 Arg [-TYPE] : 00063 string - database type (optional - if absent derived from dbname) 00064 Arg [-DIVISION] : 00065 string : optional Ensembl division (for use when subject is DataRelease) 00066 Arg [-SPECIES_ID] : 00067 Integer - optional species_id (for use when subject is GenomeInfo) 00068 00069 Example : $info = Bio::EnsEMBL::MetaData::DatabaseInfo->new(...); 00070 Description: Creates a new database info object 00071 Returntype : Bio::EnsEMBL::MetaData::DatabaseInfo 00072 Exceptions : none 00073 Caller : general 00074 Status : Stable 00075 00076 =cut 00077 00078 sub new { 00079 my ( $class, @args ) = @_; 00080 my $self = $class->SUPER::new(@args); 00081 my $subject; 00082 ( $self->{type}, $self->{division}, $self->{dbname}, $subject, 00083 $self->{species_id} ) 00084 = rearrange( [ 'TYPE', 'DIVISION', 'DBNAME', 'SUBJECT', 'SPECIES_ID' ], 00085 @args ); 00086 if ( !defined $self->{type} ) { 00087 $self->{type} = _parse_type( $self->dbname() ); 00088 } 00089 $self->{species_id} ||= 1; 00090 $self->{subject} = $subject; 00091 return $self; 00092 } 00093 00094 =head1 ATTRIBUTE METHODS 00095 =head2 division 00096 Arg : (optional) division to set 00097 Description: Gets/sets Ensembl Genomes division 00098 Returntype : string 00099 Exceptions : none 00100 Caller : general 00101 Status : Stable 00102 =cut 00103 00104 sub division { 00105 my ( $self, $division ) = @_; 00106 $self->{division} = $division if ( defined $division ); 00107 return $self->{division}; 00108 } 00109 00110 =head2 species_id 00111 Arg : (optional) species_id to set 00112 Description: Gets/sets species_id 00113 Returntype : string 00114 Exceptions : none 00115 Caller : general 00116 Status : Stable 00117 =cut 00118 00119 sub species_id { 00120 my ( $self, $species_id ) = @_; 00121 $self->{species_id} = $species_id if ( defined $species_id ); 00122 return $self->{species_id}; 00123 } 00124 00125 =head2 dbname 00126 Arg : (optional) dbname to set 00127 Description: Gets/sets dbname 00128 Returntype : string 00129 Exceptions : none 00130 Caller : general 00131 Status : Stable 00132 =cut 00133 00134 sub dbname { 00135 my ( $self, $dbname ) = @_; 00136 if ( defined $dbname ) { 00137 $self->{dbname} = $dbname; 00138 if ( !defined $self->{type} ) { 00139 $self->{type} = _parse_type( $self->dbname() ); 00140 } 00141 } 00142 return $self->{dbname}; 00143 } 00144 00145 =head2 type 00146 Arg : (optional) database type to set 00147 Description: Gets/sets database type 00148 Returntype : string 00149 Exceptions : none 00150 Caller : general 00151 Status : Stable 00152 =cut 00153 00154 sub type { 00155 my ( $self, $type ) = @_; 00156 $self->{type} = $type if ( defined $type ); 00157 return $self->{type}; 00158 } 00159 00160 =head2 subject 00161 Arg : (optional) subject 00162 Description: Gets/sets subject that database is associated with 00163 Returntype : Bio::EnsEMBL::MetaData::GenomeInfo or Bio::EnsEMBL::MetaData::DataReleaseInfo 00164 Exceptions : none 00165 Caller : general 00166 Status : Stable 00167 =cut 00168 00169 sub subject { 00170 my ( $self, $subject ) = @_; 00171 if ( defined $subject ) { 00172 if ( !$subject->isa("Bio::EnsEMBL::MetaData::GenomeInfo") && 00173 !$subject->isa("Bio::EnsEMBL::MetaData::DataReleaseInfo") ) 00174 { 00175 throw 00176 "The subject of a DatabaseInfo object must be GenomeInfo or DataReleaseInfo"; 00177 } 00178 $self->{subject} = $subject; 00179 } 00180 return $self->{subject}; 00181 } 00182 00183 =head2 to_hash 00184 Description: Render as plain hash suitable for export as JSON/XML 00185 Returntype : Hashref 00186 Exceptions : none 00187 Caller : general 00188 Status : Stable 00189 =cut 00190 00191 sub to_hash { 00192 my ($in) = @_; 00193 return { division => $in->division(), 00194 type => $in->type(), 00195 dbname => $in->dbname(), }; 00196 } 00197 00198 =head2 to_hash 00199 Description: Render as string for display 00200 Returntype : String 00201 Exceptions : none 00202 Caller : general 00203 Status : Stable 00204 =cut 00205 00206 sub to_string { 00207 my ($self) = @_; 00208 return join( '/', $self->division(), $self->type(), $self->dbname() ); 00209 } 00210 00211 =head2 _parse_type 00212 Description: Derive type from database name 00213 Returntype : String 00214 Exceptions : none 00215 Caller : internal 00216 Status : Stable 00217 =cut 00218 00219 sub _parse_type { 00220 my ($dbname) = @_; 00221 if ( $dbname =~ m/mart/ ) { 00222 return 'mart'; 00223 } 00224 else { 00225 $dbname =~ m/^.+_([a-z]+)_[0-9]+(?:_[a-z0-9]+)?_[0-9a-z]+/; 00226 00227 if ( defined $1 ) { 00228 return $1; 00229 } 00230 else { 00231 return 'other'; 00232 } 00233 } 00234 } 00235 00236 1;