| 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 | |||
| 21 | =head1 CONTACT | ||
| 22 | |||
| 23 | Please email comments or questions to the public Ensembl | ||
| 24 | developers list at <http://lists.ensembl.org/mailman/listinfo/dev>. | ||
| 25 | |||
| 26 | Questions may also be sent to the Ensembl help desk at | ||
| 27 | <http://www.ensembl.org/Help/Contact>. | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | =head1 NAME | ||
| 32 | |||
| 33 | Bio::EnsEMBL::OntologyTerm | ||
| 34 | |||
| 35 | =head1 DESCRIPTION | ||
| 36 | |||
| 37 | An ontology term object, used in querying for transcripts, genes, | ||
| 38 | and translations using the relevant adaptors and methods. | ||
| 39 | |||
| 40 | =head1 METHODS | ||
| 41 | |||
| 42 | =cut | ||
| 43 | |||
| 44 | package Bio::EnsEMBL::OntologyTerm; | ||
| 45 | $Bio::EnsEMBL::OntologyTerm::VERSION = '114.0.0'; | ||
| 46 | use strict; | ||
| 47 | use warnings; | ||
| 48 | |||
| 49 | use Bio::EnsEMBL::Utils::Argument qw( rearrange ); | ||
| 50 | |||
| 51 | use base qw( Bio::EnsEMBL::Storable ); | ||
| 52 | |||
| 53 | =head2 new | ||
| 54 | |||
| 55 | Arg [-ACCESSION] : String | ||
| 56 | The accession of the ontology term. | ||
| 57 | |||
| 58 | Arg [-ONTOLOGY] : String | ||
| 59 | The ontology that the term belongs to. | ||
| 60 | |||
| 61 | Arg [-NAMESPACE] : String | ||
| 62 | The namespace of the ontology term. | ||
| 63 | |||
| 64 | Arg [-NAME] : String | ||
| 65 | The name of the ontology term. | ||
| 66 | |||
| 67 | Arg [-SUBSETS] : (optional) Listref of strings | ||
| 68 | The subsets within the ontology to which this | ||
| 69 | term belongs. | ||
| 70 | |||
| 71 | Arg [-DEFINITION] : (optional) String | ||
| 72 | The definition of the ontology term. | ||
| 73 | |||
| 74 | Arg [-SYNONYMS] : (optional) Listref of strings | ||
| 75 | The synonyms of this term. | ||
| 76 | |||
| 77 | Arg : Further arguments required for parent class | ||
| 78 | Bio::EnsEMBL::Storable. | ||
| 79 | |||
| 80 | Description : Creates an ontology term object. | ||
| 81 | |||
| 82 | Example : | ||
| 83 | |||
| 84 | my $term = Bio::EnsEMBL::OntologyTerm->new( | ||
| 85 | '-accession' => 'GO:0021785', | ||
| 86 | '-ontology' => 'GO', | ||
| 87 | '-namespace' => 'biological_process', | ||
| 88 | '-name' => 'branchiomotor neuron axon guidance', | ||
| 89 | '-definition' => 'The process in which a branchiomotor ' | ||
| 90 | . 'neuron growth cone is directed to a specific target site. ' | ||
| 91 | . 'Branchiomotor neurons are located in the hindbrain and ' | ||
| 92 | . 'innervate branchial arch-derived muscles that control jaw ' | ||
| 93 | . 'movements, facial expression, the larynx, and the pharynx.', | ||
| 94 | '-synonyms' => [ 'BMN axon guidance', | ||
| 95 | 'branchial motor axon guidance', | ||
| 96 | 'special visceral motor neuron axon guidance' ] | ||
| 97 | |||
| 98 | # ... other arguments required by Bio::EnsEMBL::Storable. | ||
| 99 | ); | ||
| 100 | |||
| 101 | Return type : Bio::EnsEMBL::OntologyTerm | ||
| 102 | |||
| 103 | =cut | ||
| 104 | |||
| 105 | sub new { | ||
| 106 | my $proto = shift(@_); | ||
| 107 | |||
| 108 | my $this = $proto->SUPER::new(@_); | ||
| 109 | |||
| 110 | my ( $accession, $ontology, $ontology_version,$namespace, $name, $definition, $is_root, $is_obsolete, $subsets ) | ||
| 111 | = rearrange( [ 'ACCESSION', 'ONTOLOGY', 'ONTOLOGY_VERSION', 'NAMESPACE', 'NAME', | ||
| 112 | 'DEFINITION', 'IS_ROOT', 'IS_OBSOLETE', 'SUBSETS' ], | ||
| 113 | @_ ); | ||
| 114 | |||
| 115 | $this->{'accession'} = $accession; | ||
| 116 | $this->{'ontology'} = $ontology; | ||
| 117 | $this->{'ontology_version'} = $ontology_version; | ||
| 118 | $this->{'namespace'} = $namespace; | ||
| 119 | $this->{'name'} = $name; | ||
| 120 | $this->{'definition'} = $definition; | ||
| 121 | $this->{'is_root'} = $is_root; | ||
| 122 | $this->{'is_obsolete'}= $is_obsolete; | ||
| 123 | $this->{'subsets'} = [ @{$subsets} ]; | ||
| 124 | |||
| 125 | $this->{'child_terms_fetched'} = 0; | ||
| 126 | $this->{'parent_terms_fetched'} = 0; | ||
| 127 | |||
| 128 | return $this; | ||
| 129 | } | ||
| 130 | |||
| 131 | =head2 accession | ||
| 132 | |||
| 133 | Arg : None | ||
| 134 | |||
| 135 | Description : Returns the accession for the ontology term in question. | ||
| 136 | |||
| 137 | Example : my $accession = $term->accession(); | ||
| 138 | |||
| 139 | Return type : String | ||
| 140 | |||
| 141 | =cut | ||
| 142 | |||
| 143 | sub accession { | ||
| 144 | my ($this) = @_; | ||
| 145 | return $this->{'accession'}; | ||
| 146 | } | ||
| 147 | |||
| 148 | =head2 ontology | ||
| 149 | |||
| 150 | Arg : None | ||
| 151 | |||
| 152 | Description : Returns the ontology for the ontology term in question. | ||
| 153 | |||
| 154 | Example : my $ontology = $term->ontology(); | ||
| 155 | |||
| 156 | Return type : String | ||
| 157 | |||
| 158 | =cut | ||
| 159 | |||
| 160 | sub ontology { | ||
| 161 | my ($this) = @_; | ||
| 162 | return $this->{'ontology'}; | ||
| 163 | } | ||
| 164 | |||
| 165 | =head2 namespace | ||
| 166 | |||
| 167 | Arg : None | ||
| 168 | |||
| 169 | Description : Returns the namespace for the ontology term in question. | ||
| 170 | |||
| 171 | Example : my $acc = $term->namespace(); | ||
| 172 | |||
| 173 | Return type : String | ||
| 174 | |||
| 175 | =cut | ||
| 176 | |||
| 177 | sub namespace { | ||
| 178 | my ($this) = @_; | ||
| 179 | return $this->{'namespace'}; | ||
| 180 | } | ||
| 181 | |||
| 182 | =head2 name | ||
| 183 | |||
| 184 | Arg : None | ||
| 185 | |||
| 186 | Description : Returns the name for the ontology term in question. | ||
| 187 | |||
| 188 | Example : my $name = $term->name(); | ||
| 189 | |||
| 190 | Return type : String | ||
| 191 | |||
| 192 | =cut | ||
| 193 | |||
| 194 | sub name { | ||
| 195 | my ($this) = @_; | ||
| 196 | return $this->{'name'}; | ||
| 197 | } | ||
| 198 | |||
| 199 | =head2 definition | ||
| 200 | |||
| 201 | Arg : None | ||
| 202 | |||
| 203 | Description : Returns the definition for the ontology term in question. | ||
| 204 | |||
| 205 | Example : my $definition = $term->definition(); | ||
| 206 | |||
| 207 | Return type : String | ||
| 208 | |||
| 209 | =cut | ||
| 210 | |||
| 211 | sub definition { | ||
| 212 | my ($this) = @_; | ||
| 213 | return $this->{'definition'}; | ||
| 214 | } | ||
| 215 | |||
| 216 | =head2 is_root | ||
| 217 | |||
| 218 | Arg : None | ||
| 219 | |||
| 220 | Description : Returns true if the term is root of its ontology | ||
| 221 | |||
| 222 | Example : my $is_root = $term->is_root(); | ||
| 223 | |||
| 224 | Return type : Boolean (TRUE if it is a root, else FALSE) | ||
| 225 | |||
| 226 | =cut | ||
| 227 | |||
| 228 | sub is_root { | ||
| 229 | my ($this) = @_; | ||
| 230 | return $this->{'is_root'}; | ||
| 231 | } | ||
| 232 | |||
| 233 | =head2 is_obsolete | ||
| 234 | |||
| 235 | Arg : None | ||
| 236 | |||
| 237 | Description : Returns true if the term is obsolete | ||
| 238 | |||
| 239 | Example : my $is_obsolete = $term->is_obsolete(); | ||
| 240 | |||
| 241 | Return type : Boolean (TRUE if it is obsolete, else FALSE) | ||
| 242 | |||
| 243 | =cut | ||
| 244 | |||
| 245 | sub is_obsolete { | ||
| 246 | my ($this) = @_; | ||
| 247 | return $this->{'is_obsolete'}; | ||
| 248 | } | ||
| 249 | |||
| 250 | |||
| 251 | |||
| 252 | =head2 synonyms | ||
| 253 | |||
| 254 | Arg : None | ||
| 255 | |||
| 256 | Description : Returns the list of synonyms defined for this term | ||
| 257 | (if any). | ||
| 258 | |||
| 259 | Example : my @synonyms = @{ $term->synonyms() }; | ||
| 260 | |||
| 261 | Return type : Listref of strings | ||
| 262 | |||
| 263 | =cut | ||
| 264 | |||
| 265 | sub synonyms { | ||
| 266 | my ($this) = @_; | ||
| 267 | |||
| 268 | if ( !exists( $this->{'synonyms'} ) ) { | ||
| 269 | $this->{'synonyms'} = | ||
| 270 | $this->adaptor()->_fetch_synonyms_by_dbID( $this->dbID() ); | ||
| 271 | } | ||
| 272 | |||
| 273 | return $this->{'synonyms'}; | ||
| 274 | } | ||
| 275 | |||
| 276 | =head2 subsets | ||
| 277 | |||
| 278 | Arg : None | ||
| 279 | |||
| 280 | Description : Returns a list of subsets that this term is part | ||
| 281 | of. The list might be empty. | ||
| 282 | |||
| 283 | Example : my @subsets = @{ $term->subsets() }; | ||
| 284 | |||
| 285 | Return type : listref of strings | ||
| 286 | |||
| 287 | =cut | ||
| 288 | |||
| 289 | sub subsets { | ||
| 290 | my ($this) = @_; | ||
| 291 | return $this->{'subsets'}; | ||
| 292 | } | ||
| 293 | |||
| 294 | =head2 children | ||
| 295 | |||
| 296 | Arg : (optional) List of strings | ||
| 297 | The type of relations to retrieve children for. | ||
| 298 | |||
| 299 | Description : Returns the children terms of this ontology term. | ||
| 300 | |||
| 301 | Example : my @children = | ||
| 302 | @{ $term->children( 'is_a', 'part_of' ) }; | ||
| 303 | |||
| 304 | Return type : listref of Bio::EnsEMBL::OntologyTerm | ||
| 305 | |||
| 306 | =cut | ||
| 307 | |||
| 308 | sub children { | ||
| 309 | my ( $this, @relations ) = @_; | ||
| 310 | |||
| 311 | my @terms = @{ $this->adaptor()->fetch_all_by_parent_term($this) }; | ||
| 312 | |||
| 313 | if (@relations) { | ||
| 314 | @terms = (); | ||
| 315 | foreach my $relation (@relations) { | ||
| 316 | if ( exists( $this->{'children'}{$relation} ) ) { | ||
| 317 | push( @terms, @{ $this->{'children'}{$relation} } ); | ||
| 318 | } | ||
| 319 | } | ||
| 320 | } | ||
| 321 | |||
| 322 | return \@terms; | ||
| 323 | } | ||
| 324 | |||
| 325 | =head2 descendants | ||
| 326 | |||
| 327 | Arg : None | ||
| 328 | |||
| 329 | Description : Returns the complete set of 'is_a' and 'part_of' | ||
| 330 | descendant terms of this ontology term, down to | ||
| 331 | and including any leaf terms. | ||
| 332 | |||
| 333 | Example : my @descendants = @{ $term->descendants() }; | ||
| 334 | |||
| 335 | Return type : listref of Bio::EnsEMBL::OntologyTerm | ||
| 336 | |||
| 337 | =cut | ||
| 338 | |||
| 339 | sub descendants { | ||
| 340 | my ($this) = @_; | ||
| 341 | return $this->adaptor()->fetch_all_by_ancestor_term($this); | ||
| 342 | } | ||
| 343 | |||
| 344 | =head2 parents | ||
| 345 | |||
| 346 | Arg : (optional) List of strings | ||
| 347 | The type of relations to retrieve parents for. | ||
| 348 | |||
| 349 | Description : Returns the parent terms of this ontology term. | ||
| 350 | |||
| 351 | Example : my @parents = | ||
| 352 | @{ $term->parents( 'is_a', 'part_of' ) }; | ||
| 353 | |||
| 354 | Return type : listref of Bio::EnsEMBL::OntologyTerm | ||
| 355 | |||
| 356 | =cut | ||
| 357 | |||
| 358 | sub parents { | ||
| 359 | my ( $this, @relations ) = @_; | ||
| 360 | |||
| 361 | my @terms = @{ $this->adaptor()->fetch_all_by_child_term($this) }; | ||
| 362 | |||
| 363 | if (@relations) { | ||
| 364 | @terms = (); | ||
| 365 | foreach my $relation (@relations) { | ||
| 366 | if ( exists( $this->{'parents'}{$relation} ) ) { | ||
| 367 | push( @terms, @{ $this->{'parents'}{$relation} } ); | ||
| 368 | } | ||
| 369 | } | ||
| 370 | } | ||
| 371 | |||
| 372 | return \@terms; | ||
| 373 | } | ||
| 374 | |||
| 375 | =head2 ancestors | ||
| 376 | |||
| 377 | Arg : None | ||
| 378 | |||
| 379 | Description : Returns the complete set of 'is_a' and 'part_of' | ||
| 380 | ancestor terms of this ontology term, up to and | ||
| 381 | including the root term. | ||
| 382 | |||
| 383 | Example : my @ancestors = @{ $term->ancestors() }; | ||
| 384 | |||
| 385 | Return type : listref of Bio::EnsEMBL::OntologyTerm | ||
| 386 | |||
| 387 | =cut | ||
| 388 | |||
| 389 | sub ancestors { | ||
| 390 | my ($this) = @_; | ||
| 391 | return $this->adaptor()->fetch_all_by_descendant_term($this); | ||
| 392 | } | ||
| 393 | |||
| 394 | =head2 ontology_version | ||
| 395 | |||
| 396 | Arg : None | ||
| 397 | |||
| 398 | Description : Returns the version of the ontology from which this term | ||
| 399 | originates. | ||
| 400 | |||
| 401 | Example : my $version = $term->ontology_version() ; | ||
| 402 | |||
| 403 | Return type : string | ||
| 404 | |||
| 405 | =cut | ||
| 406 | sub ontology_version{ | ||
| 407 | my ($this) = @_; | ||
| 408 | return $this->{ontology_version}; | ||
| 409 | } | ||
| 410 | |||
| 411 | 1; |