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