EnsEMBL/Gene.pm untested

filter: Statementstmt 0.0% 0 / 451 Branchbran 0.0% 0 / 188 Conditioncond 0.0% 0 / 57 MC/DCmcdc 0.0% 0 / 33 Subroutinesub 0.0% 0 / 54 Podpod 0.0% 0 / 44 totaltotal 0.0% 0 / 827 CC 95 SCAR 36.1
CC
95
Cov
0%
new
110.0
transform
110.0
equals
90.0
CRAP 36.8
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::Gene - Object representing a genes
34  
35 =head1 SYNOPSIS
36  
37 my $gene = Bio::EnsEMBL::Gene->new(
38 -START => 123,
39 -END => 1045,
40 -STRAND => 1,
41 -SLICE => $slice
42 );
43  
44 # print gene information
45 print("gene start:end:strand is "
46 . join( ":", map { $gene->$_ } qw(start end strand) )
47 . "\n" );
48  
49 # set some additional attributes
50 $gene->stable_id('ENSG000001');
51 $gene->description('This is the gene description');
52  
53 =head1 DESCRIPTION
54  
55 A representation of a Gene within the Ensembl system. A gene is a set of one or
56 more alternative transcripts.
57  
58 =head1 METHODS
59  
60 =cut
61  
62 package Bio::EnsEMBL::Gene;
63 $Bio::EnsEMBL::Gene::VERSION = '114.0.0';
64 use strict;
65  
66 use POSIX;
67 use Bio::EnsEMBL::Feature;
68 use Bio::EnsEMBL::Intron;
69 use Bio::EnsEMBL::Biotype;
70 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
71 use Bio::EnsEMBL::Utils::Exception qw(throw warning);
72 use Bio::EnsEMBL::Utils::Scalar qw(assert_ref);
73  
74 use parent qw(Bio::EnsEMBL::Feature);
75  
76 use constant SEQUENCE_ONTOLOGY => {
77 acc => 'SO:0000704',
78 term => 'gene',
79 };
80  
81 =head2 new
82  
83 Arg [-START] :
84 int - start postion of the gene
85 Arg [-END] :
86 int - end position of the gene
87 Arg [-STRAND] :
88 int - 1,-1 tehe strand the gene is on
89 Arg [-SLICE] :
90 Bio::EnsEMBL::Slice - the slice the gene is on
91 Arg [-STABLE_ID] :
92 string - the stable identifier of this gene
93 Arg [-VERSION] :
94 int - the version of the stable identifier of this gene
95 Arg [-EXTERNAL_NAME] :
96 string - the external database name associated with this gene
97 Arg [-EXTERNAL_DB] :
98 string - the name of the database the external name is from
99 Arg [-EXTERNAL_STATUS]:
100 string - the status of the external identifier
101 Arg [-DISPLAY_XREF]:
102 Bio::EnsEMBL::DBEntry - The external database entry that is used
103 to label this gene when it is displayed.
104 Arg [-TRANSCRIPTS]:
105 Listref of Bio::EnsEMBL::Transcripts - this gene's transcripts
106 Arg [-CREATED_DATE]:
107 string - the date the gene was created
108 Arg [-MODIFIED_DATE]:
109 string - the date the gene was last modified
110 Arg [-DESCRIPTION]:
111 string - the genes description
112 Arg [-BIOTYPE]:
113 string - the biotype e.g. "protein_coding"
114 Arg [-SOURCE]:
115 string - the genes source, e.g. "ensembl"
116 Arg [-IS_CURRENT]:
117 Boolean - specifies if this is the current version of the gene
118 Arg [-CANONICAL_TRANSCRIPT]:
119 Bio::EnsEMBL::Transcript - the canonical transcript of this gene
120 Arg [-CANONICAL_TRANSCRIPT_ID]:
121 integer - the canonical transcript dbID of this gene, if the
122 transcript object itself is not available.
123  
124 Example : $gene = Bio::EnsEMBL::Gene->new(...);
125 Description: Creates a new gene object
126 Returntype : Bio::EnsEMBL::Gene
127 Exceptions : none
128 Caller : general
129 Status : Stable
130  
131 =cut
132  
133 sub new {
134 my $caller = shift;
135  
136 my $class = ref($caller) || $caller;
137 my $self = $class->SUPER::new(@_);
138 my (
139 $stable_id, $version,
140 $external_name, $type,
141 $external_db, $external_status,
142 $display_xref, $description,
143 $transcripts, $created_date,
144 $modified_date, $confidence,
145 $biotype, $source,
146 $is_current,
147 $canonical_transcript_id, $canonical_transcript
148 )
149 = rearrange( [
150 'STABLE_ID', 'VERSION',
151 'EXTERNAL_NAME', 'TYPE',
152 'EXTERNAL_DB', 'EXTERNAL_STATUS',
153 'DISPLAY_XREF', 'DESCRIPTION',
154 'TRANSCRIPTS', 'CREATED_DATE',
155 'MODIFIED_DATE', 'CONFIDENCE',
156 'BIOTYPE', 'SOURCE',
157 'IS_CURRENT',
158 'CANONICAL_TRANSCRIPT_ID', 'CANONICAL_TRANSCRIPT'
159 ],
160 @_
161 );
162  
163  
164 if ($transcripts) {
165 $self->{'_transcript_array'} = $transcripts;
166 $self->recalculate_coordinates();
167 }
168  
169 $self->stable_id($stable_id);
170 $self->{'created_date'} = $created_date;
171 $self->{'modified_date'} = $modified_date;
172  
173 $self->external_name($external_name) if ( defined $external_name );
174 $self->external_db($external_db) if ( defined $external_db );
175 $self->external_status($external_status)
176 if ( defined $external_status );
177 $self->display_xref($display_xref) if ( defined $display_xref );
178  
179 $self->{'biotype'} = $biotype || $type;
180  
181 $self->description($description);
182 $self->source($source);
183  
184 # Default version
185 if ( !defined($version) ) { $version = 1 }
186 $self->{'version'} = $version;
187  
188 # default to is_current
189 $is_current = 1 unless (defined($is_current));
190 $self->{'is_current'} = $is_current;
191  
192 # Add the canonical transcript if we were given one, otherwise add the
193 # canonical transcript internal ID if we were given one.
194 if ( defined($canonical_transcript) ) {
195 $self->canonical_transcript($canonical_transcript);
196 } elsif ( defined($canonical_transcript_id) ) {
197 $self->{'canonical_transcript_id'} = $canonical_transcript_id;
198 }
199  
200 return $self;
201 }
202  
203  
204  
205 =head2 external_name
206  
207 Arg [1] : (optional) String - the external name to set
208 Example : $gene->external_name('BRCA2');
209 Description: Getter/setter for attribute external_name.
210 Returntype : String or undef
211 Exceptions : none
212 Caller : general
213 Status : Stable
214  
215 =cut
216  
217 sub external_name {
218 my $self = shift;
219  
220 $self->{'external_name'} = shift if (@_);
221  
222 if (defined $self->{'external_name'}) {
223 return $self->{'external_name'};
224 }
225  
226 my $display_xref = $self->display_xref();
227  
228 if (defined $display_xref) {
229 return $display_xref->display_id();
230 } else {
231 return undef;
232 }
233 }
234  
235  
236  
237 =head2 source
238  
239 Arg [1] : (optional) String - the source to set
240 Example : $gene->source('ensembl');
241 Description: Getter/setter for attribute source
242 Returntype : String
243 Exceptions : none
244 Caller : general
245 Status : Stable
246  
247 =cut
248  
249 sub source {
250 my $self = shift;
251 $self->{'source'} = shift if( @_ );
252 return ( $self->{'source'} || "ensembl" );
253 }
254  
255  
256 =head2 external_db
257  
258 Arg [1] : (optional) String - name of external db to set
259 Example : $gene->external_db('HGNC');
260 Description: Getter/setter for attribute external_db. The db is the one that
261 belongs to the external_name.
262 Returntype : String
263 Exceptions : none
264 Caller : general
265 Status : Stable
266  
267 =cut
268  
269 sub external_db {
270 my $self = shift;
271  
272 $self->{'external_db'} = shift if( @_ );
273  
274 if( exists $self->{'external_db'} ) {
275 return $self->{'external_db'};
276 }
277  
278 my $display_xref = $self->display_xref();
279  
280 if( defined $display_xref ) {
281 return $display_xref->dbname()
282 } else {
283 return undef;
284 }
285 }
286  
287  
288 =head2 external_status
289  
290 Arg [1] : (optional) String - status of the external db
291 Example : $gene->external_status('KNOWNXREF');
292 Description: Getter/setter for attribute external_status. The status of
293 the external db of the one that belongs to the external_name.
294 Returntype : String
295 Exceptions : none
296 Caller : general
297 Status : Stable
298  
299 =cut
300  
301 sub external_status {
302 my $self = shift;
303  
304 $self->{'_ext_status'} = shift if ( @_ );
305 return $self->{'_ext_status'} if exists $self->{'_ext_status'};
306  
307 my $display_xref = $self->display_xref();
308  
309 if( defined $display_xref ) {
310 return $display_xref->status()
311 } else {
312 return undef;
313 }
314 }
315  
316  
317 =head2 description
318  
319 Arg [1] : (optional) String - the description to set
320 Example : $gene->description('This is the gene\'s description');
321 Description: Getter/setter for gene description
322 Returntype : String
323 Exceptions : none
324 Caller : general
325 Status : Stable
326  
327 =cut
328  
329 sub description {
330 my $self = shift;
331 $self->{'description'} = shift if( @_ );
332 return $self->{'description'};
333 }
334  
335  
336 =head2 equals
337  
338 Arg [1] : Bio::EnsEMBL::Gene gene
339 Example : if ($geneA->equals($geneB)) { ... }
340 Description : Compares two genes for equality.
341 The test for eqality goes through the following list
342 and terminates at the first true match:
343  
344 1. If Bio::EnsEMBL::Feature::equals() returns false,
345 then the genes are *not* equal.
346 2. If the biotypes differ, then the genes are *not*
347 equal.
348 3. If both genes have stable IDs: if these are the
349 same, the genes are equal, otherwise not.
350 4. If both genes have the same number of transcripts
351 and if these are (when compared pair-wise sorted by
352 start-position and length) the same, then they are
353 equal, otherwise not.
354  
355 Return type : Boolean (0, 1)
356  
357 Exceptions : Thrown if a non-gene is passed as the argument.
358  
359 =cut
360  
361 sub equals {
362 my ( $self, $gene ) = @_;
363  
364 if ( !defined($gene) ) { return 0 }
365 if ( $self eq $gene ) { return 1 }
366  
367 assert_ref( $gene, 'Bio::EnsEMBL::Gene' );
368  
369 my $feature_equals = $self->SUPER::equals($gene);
370 if ( defined($feature_equals) && $feature_equals == 0 ) {
371 return 0;
372 }
373  
374 if ( $self->get_Biotype->name ne $self->get_Biotype->name ) {
375 return 0;
376 }
377  
378 if ( defined( $self->stable_id() ) && defined( $gene->stable_id() ) )
379 {
380 if ( $self->stable_id() eq $gene->stable_id() ) { return 1 }
381 else { return 0 }
382 }
383  
384 my @self_transcripts = sort {
385 $a->start() <=> $b->start() ||
386 $a->length() <=> $b->length()
387 } @{ $self->get_all_Transcripts() };
388 my @gene_transcripts = sort {
389 $a->start() <=> $b->start() ||
390 $a->length() <=> $b->length()
391 } @{ $gene->get_all_Transcripts() };
392  
393 if ( scalar(@self_transcripts) != scalar(@gene_transcripts) ) {
394 return 0;
395 }
396  
397 while (@self_transcripts) {
398 my $self_transcript = shift(@self_transcripts);
399 my $gene_transcript = shift(@gene_transcripts);
400  
401 if ( !$self_transcript->equals($gene_transcript) ) {
402 return 0;
403 }
404 }
405  
406 return 1;
407 } ## end sub equals
408  
409 =head2 canonical_transcript
410  
411 Arg [1] : (optional) Bio::EnsEMBL::Transcript - canonical_transcript object
412 Example : $gene->canonical_transcript($canonical_transcript);
413 Description: Getter/setter for the canonical_transcript
414 Returntype : Bio::EnsEMBL::Transcript
415 Exceptions : Throws if argument is not a transcript object.
416 Caller : general
417 Status : Stable
418  
419 =cut
420  
421 sub canonical_transcript {
422 my ( $self, $transcript ) = @_;
423  
424 if ( defined($transcript) ) {
425 # We're attaching a new canonical transcript.
426  
427 assert_ref( $transcript, 'Bio::EnsEMBL::Transcript' );
428  
429 # If there's already a canonical transcript, make sure it doesn't
430 # think it's still canonical.
431 if ( defined( $self->{'canonical_transcript'} ) ) {
432 $self->{'canonical_transcript'}->is_canonical(0);
433 }
434  
435 $self->{'canonical_transcript'} = $transcript;
436 $self->{'canonical_transcript_id'} = $transcript->dbID();
437  
438 $transcript->is_canonical(1);
439  
440 } elsif ( !defined( $self->{'canonical_transcript'} )
441 && defined( $self->{'canonical_transcript_id'} )
442 && $self->{'canonical_transcript_id'} != 0 )
443 {
444 # We have not attached a canoncical transcript, but we have the dbID
445 # of one.
446  
447 if ( defined( $self->adaptor() ) ) {
448 my $transcript_adaptor =
449 $self->adaptor()->db()->get_TranscriptAdaptor();
450  
451 my $canonical_transcript =
452 $transcript_adaptor->fetch_by_dbID(
453 $self->{'canonical_transcript_id'} );
454  
455 if ( defined($canonical_transcript) ) {
456 # Recusive call...
457 $self->canonical_transcript($canonical_transcript);
458 }
459  
460 } else {
461 warning( "Gene has no adaptor "
462 . "when trying to fetch canonical transcript." );
463 }
464  
465 } ## end elsif ( !defined( $self->...))
466  
467 return $self->{'canonical_transcript'};
468 } ## end sub canonical_transcript
469  
470  
471 =head2 get_all_Attributes
472  
473 Arg [1] : (optional) String $attrib_code
474 The code of the attribute type to retrieve values for
475 Example : my ($author) = @{ $gene->get_all_Attributes('author') };
476 my @gene_attributes = @{ $gene->get_all_Attributes };
477 Description: Gets a list of Attributes of this gene.
478 Optionally just get Attributes for given code.
479 Returntype : Listref of Bio::EnsEMBL::Attribute
480 Exceptions : warning if gene does not have attached adaptor and attempts lazy
481 load.
482 Caller : general
483 Status : Stable
484  
485 =cut
486  
487 sub get_all_Attributes {
488 my $self = shift;
489 my $attrib_code = shift;
490  
491 if ( ! exists $self->{'attributes' } ) {
492 if (!$self->adaptor() ) {
493 return [];
494 }
495  
496 my $attribute_adaptor = $self->adaptor->db->get_AttributeAdaptor();
497 $self->{'attributes'} = $attribute_adaptor->fetch_all_by_Gene($self);
498 }
499  
500 if ( defined $attrib_code ) {
501 my @results = grep { uc($_->code()) eq uc($attrib_code) }
502 @{$self->{'attributes'}};
503 return \@results;
504 } else {
505 return $self->{'attributes'};
506 }
507 }
508  
509  
510 =head2 add_Attributes
511  
512 Arg [1-N] : list of Bio::EnsEMBL::Attribute's @attribs
513 Attribute(s) to add
514 Example : my $attrib = Bio::EnsEMBL::Attribute->new(...);
515 $gene->add_Attributes($attrib);
516 Description: Adds an Attribute to the Gene. If you add an attribute before
517 you retrieve any from database, lazy loading will be disabled.
518 Returntype : none
519 Exceptions : throw on incorrect arguments
520 Caller : general
521 Status : Stable
522  
523 =cut
524  
525 sub add_Attributes {
526 my $self = shift;
527 my @attribs = @_;
528  
529 if( ! exists $self->{'attributes'} ) {
530 $self->{'attributes'} = [];
531 }
532  
533 for my $attrib ( @attribs ) {
534 if( ! $attrib->isa( "Bio::EnsEMBL::Attribute" )) {
535 throw( "Argument to add_Attribute has to be an Bio::EnsEMBL::Attribute" );
536 }
537 push( @{$self->{'attributes'}}, $attrib );
538 }
539  
540 return;
541 }
542  
543  
544 =head2 add_DBEntry
545  
546 Arg [1] : Bio::EnsEMBL::DBEntry $dbe
547 The dbEntry to be added
548 Example : my $dbe = Bio::EnsEMBL::DBEntery->new(...);
549 $gene->add_DBEntry($dbe);
550 Description: Associates a DBEntry with this gene. Note that adding DBEntries
551 will prevent future lazy-loading of DBEntries for this gene
552 (see get_all_DBEntries).
553 Returntype : none
554 Exceptions : thrown on incorrect argument type
555 Caller : general
556 Status : Stable
557  
558 =cut
559  
560 sub add_DBEntry {
561 my $self = shift;
562 my $dbe = shift;
563  
564 unless($dbe && ref($dbe) && $dbe->isa('Bio::EnsEMBL::DBEntry')) {
565 throw('Expected DBEntry argument');
566 }
567  
568 $self->{'dbentries'} ||= [];
569 push @{$self->{'dbentries'}}, $dbe;
570 }
571  
572  
573 =head2 get_all_DBEntries
574  
575 Arg [1] : (optional) String, external database name,
576 SQL wildcard characters (_ and %) can be used to
577 specify patterns.
578  
579 Arg [2] : (optional) String, external_db type, can be one of
580 ('ARRAY','ALT_TRANS','ALT_GENE','MISC','LIT','PRIMARY_DB_SYNONYM','ENSEMBL'),
581 SQL wildcard characters (_ and %) can be used to
582 specify patterns.
583  
584 Example : my @dbentries = @{ $gene->get_all_DBEntries() };
585 @dbentries = @{ $gene->get_all_DBEntries('Uniprot%') };
586 @dbentries = @{ $gene->get_all_DBEntries('%', 'ENSEMBL') };}
587  
588 Description: Retrieves DBEntries (xrefs) for this gene. This does
589 *not* include DBEntries that are associated with the
590 transcripts and corresponding translations of this
591 gene (see get_all_DBLinks()).
592  
593 This method will attempt to lazy-load DBEntries
594 from a database if an adaptor is available and no
595 DBEntries are present on the gene (i.e. they have not
596 already been added or loaded).
597  
598 Return type: Listref of Bio::EnsEMBL::DBEntry objects
599 Exceptions : none
600 Caller : get_all_DBLinks, GeneAdaptor::store
601 Status : Stable
602  
603 =cut
604  
605 sub get_all_DBEntries {
606 my ( $self, $db_name_exp, $ex_db_type ) = @_;
607  
608 my $cache_name = 'dbentries';
609  
610 if ( defined($db_name_exp) ) {
611 $cache_name .= $db_name_exp;
612 }
613  
614 if ( defined($ex_db_type) ) {
615 $cache_name .= $ex_db_type;
616 }
617  
618 # if not cached, retrieve all of the xrefs for this gene
619 if ( !defined( $self->{$cache_name} ) && defined( $self->adaptor() ) )
620 {
621 $self->{$cache_name} =
622 $self->adaptor()->db()->get_DBEntryAdaptor()
623 ->fetch_all_by_Gene( $self, $db_name_exp, $ex_db_type );
624 }
625  
626 $self->{$cache_name} ||= [];
627  
628 return $self->{$cache_name};
629 } ## end sub get_all_DBEntries
630  
631 =head2 get_all_object_xrefs
632  
633 Arg [1] : (optional) String, external database name
634  
635 Arg [2] : (optional) String, external_db type
636  
637 Example : @oxrefs = @{ $gene->get_all_object_xrefs() };
638  
639 Description: Retrieves xrefs for this gene. This does *not*
640 include xrefs that are associated with the
641 transcripts or corresponding translations of this
642 gene (see get_all_xrefs()).
643  
644 This method will attempt to lazy-load xrefs from a
645 database if an adaptor is available and no xrefs are
646 present on the gene (i.e. they have not already been
647 added or loaded).
648  
649 NB: This method is an alias for the
650 get_all_DBentries() method.
651  
652 Return type: Listref of Bio::EnsEMBL::DBEntry objects
653  
654 Status : Stable
655  
656 =cut
657  
658 sub get_all_object_xrefs {
659 my $self = shift;
660 return $self->get_all_DBEntries(@_);
661 }
662  
663 =head2 get_all_DBLinks
664  
665 Arg [1] : String database name (optional)
666 SQL wildcard characters (_ and %) can be used to
667 specify patterns.
668  
669 Arg [2] : (optional) String, external database type, can be one of
670 ('ARRAY','ALT_TRANS','ALT_GENE','MISC','LIT','PRIMARY_DB_SYNONYM','ENSEMBL'),
671 SQL wildcard characters (_ and %) can be used to
672 specify patterns.
673  
674 Example : @dblinks = @{ $gene->get_all_DBLinks() };
675 @dblinks = @{ $gene->get_all_DBLinks('Uniprot%') };
676 @dblinks = @{ $gene->get_all_DBLinks('%', 'ENSEMBL') };}
677  
678 Description: Retrieves *all* related DBEntries for this gene. This
679 includes all DBEntries that are associated with the
680 transcripts and corresponding translations of this
681 gene.
682  
683 If you only want to retrieve the DBEntries
684 associated with the gene (and not the transcript
685 and translations) then you should use the
686 get_all_DBEntries() call instead.
687  
688 Note: Each entry may be listed more than once. No
689 uniqueness checks are done. Also if you put in an
690 incorrect external database name no checks are done
691 to see if this exists, you will just get an empty
692 list.
693  
694 Return type: Listref of Bio::EnsEMBL::DBEntry objects
695 Exceptions : none
696 Caller : general
697 Status : Stable
698  
699 =cut
700  
701 sub get_all_DBLinks {
702 my ( $self, $db_name_exp, $ex_db_type ) = @_;
703  
704 my @links =
705 @{ $self->get_all_DBEntries( $db_name_exp, $ex_db_type ) };
706  
707 # Add all of the transcript and translation xrefs to the return list.
708 foreach my $transcript ( @{ $self->get_all_Transcripts() } ) {
709 push( @links,
710 @{$transcript->get_all_DBLinks( $db_name_exp, $ex_db_type ) }
711 );
712 }
713  
714 return \@links;
715 }
716  
717 =head2 get_all_xrefs
718  
719 Arg [1] : String database name (optional)
720 SQL wildcard characters (_ and %) can be used to
721 specify patterns.
722  
723 Example : @xrefs = @{ $gene->get_all_xrefs() };
724 @xrefs = @{ $gene->get_all_xrefs('Uniprot%') };
725  
726 Description: Retrieves *all* related xrefs for this gene. This
727 includes all xrefs that are associated with the
728 transcripts and corresponding translations of this
729 gene.
730  
731 If you want to retrieve the xrefs associated
732 with only the gene (and not the transcript
733 or translations) then you should use the
734 get_all_object_xrefs() method instead.
735  
736 Note: Each entry may be listed more than once. No
737 uniqueness checks are done. Also if you put in an
738 incorrect external database name no checks are done
739 to see if this exists, you will just get an empty
740 list.
741  
742 NB: This method is an alias for the
743 get_all_DBLinks() method.
744  
745 Return type: Listref of Bio::EnsEMBL::DBEntry objects
746  
747 Status : Stable
748  
749 =cut
750  
751 sub get_all_xrefs {
752 my $self = shift;
753 return $self->get_all_DBLinks(@_);
754 }
755  
756 =head2 get_all_Exons
757  
758 Example : my @exons = @{ $gene->get_all_Exons };
759 Description: Returns a set of all the exons associated with this gene.
760 Returntype : Listref of Bio::EnsEMBL::Exon objects
761 Exceptions : none
762 Caller : general
763 Status : Stable
764  
765 =cut
766  
767  
768 sub get_all_Exons {
769 my $self = shift;
770  
771 my %h;
772 my @out = ();
773  
774 foreach my $trans ( @{$self->get_all_Transcripts} ) {
775 foreach my $e ( @{$trans->get_all_Exons} ) {
776 $h{$e->start()."-".$e->end()."-".$e->strand()."-".$e->phase()."-".$e->end_phase()} = $e;
777 }
778 }
779  
780 push @out, values %h;
781  
782 return \@out;
783 }
784  
785 =head2 get_all_Introns
786  
787 Arg [1] : none
788 Example : my @introns = @{$gene->get_all_Introns()};
789 Description: Returns an listref of the introns in this gene in order.
790 i.e. the first intron in the listref is the 5prime most exon in
791 the gene.
792 Returntype : listref to Bio::EnsEMBL::Intron objects
793 Exceptions : none
794 Caller : general
795 Status : Stable
796  
797 =cut
798  
799 sub get_all_Introns {
800 my $self = shift;
801  
802 my %h;
803 my @out = ();
804 my @introns;
805  
806 foreach my $trans ( @{$self->get_all_Transcripts} ) {
807 my @exons = @{ $trans->get_all_Exons() };
808 for (my $i = 0; $i < scalar(@exons) - 1; $i++) {
809 my $intron = new Bio::EnsEMBL::Intron($exons[$i], $exons[$i+1]);
810 push (@introns, $intron);
811 }
812 }
813  
814 return \@introns;
815 }
816  
817  
818 =head2 get_all_homologous_Genes
819  
820 Arg[1] : String The compara synonym to use when looking for a database in the
821 registry. If not provided we will use the very first compara database
822 we find.
823 Description: Queries the Ensembl Compara database and retrieves all
824 Genes from other species that are orthologous.
825 REQUIRES properly setup Registry conf file. Meaning that
826 one of the aliases for each core db has to be "Genus species"
827 e.g. "Homo sapiens" (as in the name column in genome_db table
828 in the compara database).
829  
830 The data is cached in this Object for faster re-retreival.
831 Returntype : listref [
832 Bio::EnsEMBL::Gene,
833 Bio::EnsEMBL::Compara::Homology,
834 string $species # needed as cannot get spp from Gene
835 ]
836 Exceptions : none
837 Caller : general
838 Status : Stable
839  
840 =cut
841  
842 sub get_all_homologous_Genes {
843 my ($self, $db_synonym) = @_;
844  
845 #Look for DBAdaptors which have a group of compara; these are compara DBAs.
846 #If given a synonym
847 my %args = (-GROUP => 'compara');
848 $args{-SPECIES} = $db_synonym if $db_synonym;
849 my ($compara_dba) = @{Bio::EnsEMBL::Registry->get_all_DBAdaptors(%args)};
850 unless( $compara_dba ) {
851 throw("No compara found in Bio::EnsEMBL::Registry. Please fully populate the Registry or construct a Bio::EnsEMBL::Compara::DBSQL::DBAdaptor");
852 }
853 my $compara_species = $compara_dba->species();
854 if( exists( $self->{'homologues'}->{$compara_species} ) ){
855 return $self->{'homologues'}->{$compara_species};
856 }
857 $self->{'homologues'}->{$compara_species} = [];
858  
859 # Get the compara 'member' corresponding to self
860 my $member_adaptor = $compara_dba->get_adaptor('GeneMember');
861 my $query_member = $member_adaptor->fetch_by_Gene($self);
862 unless( $query_member ){ return $self->{'homologues'}->{$compara_species} };
863  
864 # Get the compara 'homologies' corresponding to 'member'
865 my $homology_adaptor = $compara_dba->get_adaptor('Homology');
866 my @homolos = @{$homology_adaptor->fetch_all_by_Member($query_member)};
867 unless( scalar(@homolos) ){ return $self->{'homologues'}->{$compara_species} };
868  
869 # Get the ensembl 'genes' corresponding to 'homologies'
870 foreach my $homolo( @homolos ){
871 foreach my $member( @{$homolo->get_all_GeneMembers} ){
872 my $hstable_id = $member->stable_id;
873 next if ($hstable_id eq $query_member->stable_id); # Ignore self
874 my $hgene = undef;
875 eval { $hgene = $member->get_Gene;} ;
876 unless( $hgene ){
877 # Something up with DB. Create a new gene is best we can do
878 $hgene = Bio::EnsEMBL::Gene->new
879 ( -stable_id=>$hstable_id,
880 -description=>$member->description, );
881 }
882 my $hspecies = $member->genome_db->name;
883 push @{$self->{'homologues'}->{$compara_species}}, [$hgene,$homolo,$hspecies];
884 }
885 }
886 return $self->{'homologues'}->{$compara_species};
887 }
888  
889 =head2 _clear_homologues
890  
891 Description: Removes any cached homologues from the Gene which could have been
892 fetched from the C<get_all_homologous_Genes()> call.
893 Returntype : none
894 Exceptions : none
895 Caller : general
896  
897 =cut
898  
899 sub _clear_homologues {
900 my ($self) = @_;
901 delete $self->{homologues};
902 }
903  
904 =head2 add_Transcript
905  
906 Arg [1] : Bio::EnsEMBL::Transcript $trans
907 The transcript to add to the gene
908 Example : my $transcript = Bio::EnsEMBL::Transcript->new(...);
909 $gene->add_Transcript($transcript);
910 Description: Adds another Transcript to the set of alternatively
911 spliced Transcripts of this gene. If it shares exons
912 with another Transcript, these should be object-identical.
913 Returntype : none
914 Exceptions : none
915 Caller : general
916 Status : Stable
917  
918 =cut
919  
920 sub add_Transcript {
921 my ($self, $trans) = @_;
922  
923 if( !ref $trans || ! $trans->isa("Bio::EnsEMBL::Transcript") ) {
924 throw("$trans is not a Bio::EnsEMBL::Transcript!");
925 }
926  
927 $self->{'_transcript_array'} ||= [];
928 push(@{$self->{'_transcript_array'}},$trans);
929  
930 $self->recalculate_coordinates();
931 }
932  
933 sub remove_Transcript {
934 my ($self,$trans) = @_;
935 if( !ref $trans || ! $trans->isa("Bio::EnsEMBL::Transcript") ) {
936 throw("$trans is not a Bio::EnsEMBL::Transcript!");
937 }
938 # Clean transcript from live data
939 $self->get_all_Transcripts; # force lazy load.
940 my $array = $self->{_transcript_array};
941 my $db_id = $trans->dbID;
942 @$array = grep { $_->dbID != $db_id } @$array;
943 # Recalculate and store new gene coordinates
944 $self->adaptor->update_coords($self);
945 }
946  
947  
948 =head2 get_all_Transcripts
949  
950 Example : my @transcripts = @{ $gene->get_all_Transcripts };
951 Description: Returns the Transcripts in this gene.
952 Returntype : Listref of Bio::EnsEMBL::Transcript objects
953 Warning : This method returns the internal transcript array
954 used by this object. Avoid any modification
955 of this array. We class use of shift and
956 reassignment of the loop variable when iterating
957 this array as modification.
958  
959 Dereferencing the structure as shown in the example is
960 a safe way of using this data structure.
961 Exceptions : none
962 Caller : general
963 Status : Stable
964  
965 =cut
966  
967 sub get_all_Transcripts {
968 my $self = shift;
969  
970 if( ! exists $self->{'_transcript_array'} ) {
971 if( defined $self->adaptor() ) {
972 my $ta = $self->adaptor()->db()->get_TranscriptAdaptor();
973 my $transcripts = $ta->fetch_all_by_Gene( $self );
974 $self->{'_transcript_array'} = $transcripts;
975 }
976 }
977 my @array_copy;
978 if (defined $self->{'_transcript_array'}) {
979 @array_copy = @{ $self->{'_transcript_array'} } ;
980 return \@array_copy;
981 }
982 return;
983 }
984  
985  
986 =head2 get_all_alt_alleles
987  
988 Example : my @alt_genes = @{ $gene->get_all_alt_alleles };
989 foreach my $alt_gene (@alt_genes) {
990 print "Alternate allele: " . $alt_gene->stable_id() . "\n";
991 }
992 Description: Returns a listref of Gene objects that represent this Gene on
993 an alternative haplotype. Empty list if there is no such
994 Gene (eg there is no overlapping haplotype).
995 Returntype : listref of Bio::EnsEMBL::Gene objects
996 Exceptions : none
997 Caller : general
998 Status : Stable
999  
1000 =cut
1001  
1002 sub get_all_alt_alleles {
1003 my $self = shift;
1004 my $result = $self->adaptor()->fetch_all_alt_alleles( $self );
1005 return $result;
1006 }
1007  
1008  
1009 =head2 version
1010  
1011 Arg [1] : (optional) Int
1012 A version number for the stable_id
1013 Example : $gene->version(2);
1014 Description: Getter/setter for version number
1015 Returntype : Int
1016 Exceptions : none
1017 Caller : general
1018 Status : Stable
1019  
1020 =cut
1021  
1022 sub version {
1023 my $self = shift;
1024 $self->{'version'} = shift if(@_);
1025 return $self->{'version'};
1026 }
1027  
1028  
1029 =head2 stable_id
1030  
1031 Arg [1] : (optional) String - the stable ID to set
1032 Example : $gene->stable_id("ENSG0000000001");
1033 Description: Getter/setter for stable id for this gene.
1034 Returntype : String
1035 Exceptions : none
1036 Caller : general
1037 Status : Stable
1038  
1039 =cut
1040  
1041 sub stable_id {
1042 my $self = shift;
1043 $self->{'stable_id'} = shift if(@_);
1044 return $self->{'stable_id'};
1045 }
1046  
1047 =head2 stable_id_version
1048  
1049 Arg [1] : (optional) String - the stable ID with version to set
1050 Example : $gene->stable_id("ENSG0000000001.3");
1051 Description: Getter/setter for stable id with version for this gene.
1052 Returntype : String
1053 Exceptions : none
1054 Caller : general
1055 Status : Stable
1056  
1057 =cut
1058  
1059 sub stable_id_version {
1060 my $self = shift;
1061 if(my $stable_id = shift) {
1062 # See if there's an embedded period, assume that's a
1063 # version, might not work for some species but you
1064 # should use ->stable_id() and version() if you're worried
1065 # about ambiguity
1066 my $vindex = rindex($stable_id, '.');
1067 # Set the stable_id and version pair depending on if
1068 # we found a version delimiter in the stable_id
1069 ($self->{stable_id}, $self->{version}) = ($vindex > 0 ?
1070 (substr($stable_id,0,$vindex), substr($stable_id,$vindex+1)) :
1071 $stable_id, undef);
1072 }
1073 return $self->{stable_id} . ($self->{version} ? ".$self->{version}" : '');
1074 }
1075  
1076 =head2 is_current
1077  
1078 Arg [1] : Boolean $is_current
1079 Example : $gene->is_current(1)
1080 Description: Getter/setter for is_current state of this gene.
1081 Returntype : Int
1082 Exceptions : none
1083 Caller : general
1084 Status : Stable
1085  
1086 =cut
1087  
1088 sub is_current {
1089 my $self = shift;
1090 $self->{'is_current'} = shift if (@_);
1091 return $self->{'is_current'};
1092 }
1093  
1094  
1095 =head2 created_date
1096  
1097 Arg [1] : (optional) String - created date to set (as a UNIX time int)
1098 Example : $gene->created_date('1141948800');
1099 Description: Getter/setter for attribute created_date
1100 Returntype : String
1101 Exceptions : none
1102 Caller : general
1103 Status : Stable
1104  
1105 =cut
1106  
1107 sub created_date {
1108 my $self = shift;
1109 $self->{'created_date'} = shift if ( @_ );
1110 return $self->{'created_date'};
1111 }
1112  
1113  
1114 =head2 modified_date
1115  
1116 Arg [1] : (optional) String - modified date to set (as a UNIX time int)
1117 Example : $gene->modified_date('1141948800');
1118 Description: Getter/setter for attribute modified_date
1119 Returntype : String
1120 Exceptions : none
1121 Caller : general
1122 Status : Stable
1123  
1124 =cut
1125  
1126 sub modified_date {
1127 my $self = shift;
1128 $self->{'modified_date'} = shift if ( @_ );
1129 return $self->{'modified_date'};
1130 }
1131  
1132  
1133 =head2 transform
1134  
1135 Arg [1] : String - coordinate system name to transform to
1136 Arg [2] : String - coordinate system version
1137 Example : my $new_gene = $gene->transform('supercontig');
1138 Description: Moves this gene to the given coordinate system. If this gene has
1139 Transcripts attached, they move as well.
1140 Returntype : Bio::EnsEMBL::Gene
1141 Exceptions : throw on wrong parameters
1142 Caller : general
1143 Status : Stable
1144  
1145 =cut
1146  
1147 sub transform {
1148 my $self = shift;
1149  
1150 my $new_gene = $self->SUPER::transform(@_);
1151  
1152 if ( !defined($new_gene) ) {
1153 # check if this gene projects at all to requested coord system,
1154 # if not we are done.
1155 my @segments = @{ $self->project(@_) };
1156 if ( !@segments ) {
1157 return undef;
1158 }
1159 }
1160  
1161 #
1162 # If you are transforming the gene then make sure the transcripts and exons are loaded
1163 #
1164  
1165 foreach my $tran (@{$self->get_all_Transcripts}){
1166 $tran->get_all_Exons();
1167 }
1168  
1169 if( exists $self->{'_transcript_array'} ) {
1170 my @new_transcripts;
1171 my ( $strand, $slice );
1172 my $low_start = POSIX::INT_MAX;
1173 my $hi_end = POSIX::INT_MIN;
1174 for my $old_transcript ( @{$self->{'_transcript_array'}} ) {
1175 my $new_transcript = $old_transcript->transform( @_ );
1176 # this can fail if gene transform failed
1177
1178 return undef unless $new_transcript;
1179  
1180 if( ! defined $new_gene ) {
1181 if( $new_transcript->start() < $low_start ) {
1182 $low_start = $new_transcript->start();
1183 }
1184 if( $new_transcript->end() > $hi_end ) {
1185 $hi_end = $new_transcript->end();
1186 }
1187 $slice = $new_transcript->slice();
1188 $strand = $new_transcript->strand();
1189 }
1190 push( @new_transcripts, $new_transcript );
1191 }
1192  
1193 if( ! defined $new_gene ) {
1194 %$new_gene = %$self;
1195 bless $new_gene, ref( $self );
1196  
1197 $new_gene->start( $low_start );
1198 $new_gene->end( $hi_end );
1199 $new_gene->strand( $strand );
1200 $new_gene->slice( $slice );
1201 }
1202  
1203 $new_gene->{'_transcript_array'} = \@new_transcripts;
1204 }
1205  
1206 if(exists $self->{attributes}) {
1207 $new_gene->{attributes} = [@{$self->{attributes}}];
1208 }
1209  
1210 return $new_gene;
1211 }
1212  
1213  
1214 =head2 transfer
1215  
1216 Arg [1] : Bio::EnsEMBL::Slice $destination_slice
1217 Example : my $new_gene = $gene->transfer($slice);
1218 Description: Moves this Gene to given target slice coordinates. If Transcripts
1219 are attached they are moved as well. Returns a new gene.
1220 Returntype : Bio::EnsEMBL::Gene
1221 Exceptions : none
1222 Caller : general
1223 Status : Stable
1224  
1225 =cut
1226  
1227 sub transfer {
1228 my $self = shift;
1229
1230 my $new_gene = $self->SUPER::transfer( @_ );
1231 return undef unless $new_gene;
1232  
1233 if( exists $self->{'_transcript_array'} ) {
1234 my @new_transcripts;
1235 for my $old_transcript ( @{$self->{'_transcript_array'}} ) {
1236 my $new_transcript = $old_transcript->transfer( @_ );
1237 push( @new_transcripts, $new_transcript );
1238 }
1239 $new_gene->{'_transcript_array'} = \@new_transcripts;
1240 }
1241  
1242 if(exists $self->{attributes}) {
1243 $new_gene->{attributes} = [@{$self->{attributes}}];
1244 }
1245
1246 return $new_gene;
1247 }
1248  
1249  
1250 =head2 display_xref
1251  
1252 Arg [1] : (optional) Bio::EnsEMBL::DBEntry - the display xref to set
1253 Example : $gene->display_xref($db_entry);
1254 Description: Getter/setter display_xref for this gene.
1255 Returntype : Bio::EnsEMBL::DBEntry
1256 Exceptions : none
1257 Caller : general
1258 Status : Stable
1259  
1260 =cut
1261  
1262 sub display_xref {
1263 my $self = shift;
1264 $self->{'display_xref'} = shift if(@_);
1265 return $self->{'display_xref'};
1266 }
1267  
1268  
1269 =head2 display_id
1270  
1271 Example : print $gene->display_id();
1272 Description: This method returns a string that is considered to be
1273 the 'display' identifier. For genes this is (depending on
1274 availability and in this order) the stable Id, the dbID or an
1275 empty string.
1276 Returntype : String
1277 Exceptions : none
1278 Caller : web drawing code
1279 Status : Stable
1280  
1281 =cut
1282  
1283 sub display_id {
1284 my $self = shift;
1285 return $self->{'stable_id'} || $self->dbID || '';
1286 }
1287  
1288  
1289 =head2 recalculate_coordinates
1290  
1291 Example : $gene->recalculate_coordinates;
1292 Description: Called when transcript added to the gene, tries to adapt the
1293 coords for the gene.
1294 Returntype : none
1295 Exceptions : none
1296 Caller : internal
1297 Status : Stable
1298  
1299 =cut
1300  
1301 sub recalculate_coordinates {
1302 my $self = shift;
1303  
1304 my $transcripts = $self->get_all_Transcripts();
1305  
1306 return if(!$transcripts || !@$transcripts);
1307  
1308 my ( $slice, $start, $end, $strand );
1309 $slice = $transcripts->[0]->slice();
1310 $strand = $transcripts->[0]->strand();
1311 $start = $transcripts->[0]->start();
1312 $end = $transcripts->[0]->end();
1313  
1314 my $transsplicing = 0;
1315  
1316 for my $t ( @$transcripts ) {
1317 if( $t->start() < $start ) {
1318 $start = $t->start();
1319 }
1320  
1321 if( $t->end() > $end ) {
1322 $end = $t->end();
1323 }
1324  
1325 if( $t->slice()->name() ne $slice->name() ) {
1326 throw( "Transcripts with different slices not allowed on one Gene" );
1327 }
1328  
1329 if( $t->strand() != $strand ) {
1330 $transsplicing = 1;
1331 }
1332 }
1333 if( $transsplicing ) {
1334 warning( "Gene contained trans splicing event" );
1335 }
1336  
1337 $self->start( $start );
1338 $self->end( $end );
1339 $self->strand( $strand );
1340 $self->slice( $slice );
1341 }
1342  
1343  
1344 =head2 get_all_DASFactories
1345  
1346 Example : $dasref = $prot->get_all_DASFactories
1347 Description: Retrieves a listref of registered DAS objects
1348 TODO: Abstract to a DBLinkContainer obj
1349 Returntype : [ DAS_objects ]
1350 Exceptions : none
1351 Caller : general
1352 Status : Stable
1353  
1354 =cut
1355  
1356 sub get_all_DASFactories {
1357 my $self = shift;
1358 return [ $self->adaptor()->db()->_each_DASFeatureFactory ];
1359 }
1360  
1361  
1362 =head2 get_all_DAS_Features
1363  
1364 Example : $features = $prot->get_all_DAS_Features;
1365 Description: Retrieves a hash reference to a hash of DAS feature
1366 sets, keyed by the DNS, NOTE the values of this hash
1367 are an anonymous array containing:
1368 (1) a pointer to an array of features
1369 (2) a pointer to the DAS stylesheet
1370 Returntype : hashref of Bio::SeqFeatures
1371 Exceptions : none
1372 Caller : webcode
1373 Status : Stable
1374  
1375 =cut
1376  
1377 sub get_all_DAS_Features{
1378 my ($self, @args) = @_;
1379 my $slice = $self->feature_Slice;
1380 return $self->SUPER::get_all_DAS_Features($slice);
1381 }
1382  
1383  
1384 =head2 load
1385  
1386 Arg [1] : Boolean $load_xrefs
1387 Load (or don't load) xrefs. Default is to load xrefs.
1388 Example : $gene->load();
1389 Description : The Ensembl API makes extensive use of
1390 lazy-loading. Under some circumstances (e.g.,
1391 when copying genes between databases), all data of
1392 an object needs to be fully loaded. This method
1393 loads the parts of the object that are usually
1394 lazy-loaded. It will also call the equivalent
1395 method on all the transcripts of the gene.
1396 Returns :
1397  
1398 =cut
1399  
1400 sub load {
1401 my ( $self, $load_xrefs ) = @_;
1402  
1403 if ( !defined($load_xrefs) ) { $load_xrefs = 1 }
1404  
1405 foreach my $transcript ( @{ $self->get_all_Transcripts() } ) {
1406 $transcript->load($load_xrefs);
1407 }
1408  
1409 $self->analysis();
1410 $self->get_all_Attributes();
1411 $self->stable_id();
1412 $self->canonical_transcript();
1413  
1414 if ($load_xrefs) {
1415 $self->get_all_DBEntries();
1416 }
1417 }
1418  
1419 =head2 flush_Transcripts
1420  
1421 Description : Empties out caches and unsets fields of this Gene.
1422 Beware of further actions without adding some new transcripts.
1423 Example : $gene->flush_Transcripts();
1424  
1425 =cut
1426  
1427 sub flush_Transcripts {
1428 my $self = shift;
1429 $self->{'_transcript_array'} = [];
1430 $self->{'canonical_transcript_id'} = undef;
1431 $self->{'canonical_transcript'} = undef;
1432 return;
1433 }
1434  
1435 =head2 is_ref
1436  
1437 Description: getter setter for the gene attribute is_ref
1438 Arg [1] : (optional) 1 or 0
1439 return : boolean
1440  
1441 =cut
1442  
1443 sub is_reference{
1444 my ( $self, $is_ref) = @_;
1445  
1446 if(defined($is_ref)){
1447 $self->{'is_ref'} = $is_ref;
1448 }
1449 else{
1450 $self->{'is_ref'} = $self->adaptor->is_ref($self->dbID);
1451 }
1452 return $self->{'is_ref'};
1453 }
1454  
1455 =head2 summary_as_hash
1456  
1457 Example : $gene_summary = $gene->summary_as_hash();
1458 Description : Extends Feature::summary_as_hash
1459 Retrieves a summary of this Gene object.
1460
1461 Returns : hashref of arrays of descriptive strings
1462 Status : Intended for internal use
1463 =cut
1464  
1465 sub summary_as_hash {
1466 my $self = shift;
1467 my $summary_ref = $self->SUPER::summary_as_hash;
1468 $summary_ref->{'description'} = $self->description;
1469 $summary_ref->{'biotype'} = $self->get_Biotype->name;
1470 $summary_ref->{'Name'} = $self->external_name if $self->external_name;
1471 $summary_ref->{'logic_name'} = $self->analysis->logic_name() if defined $self->analysis();
1472 $summary_ref->{'source'} = $self->source();
1473 $summary_ref->{'gene_id'} = $summary_ref->{'id'};
1474  
1475 ## Will only work for for merged species
1476 my $havana_gene = $self->havana_gene();
1477 $summary_ref->{'havana_gene'} = $havana_gene->display_id() if defined $havana_gene;
1478 $summary_ref->{'havana_version'} = $havana_gene->version() if defined $havana_gene;
1479  
1480 ## Stable identifier of the parent gene this gene was projected from
1481 my $proj_parent_attributes = $self->get_all_Attributes("proj_parent_g");
1482 if (@{$proj_parent_attributes}) {
1483 $summary_ref->{'projection_parent_gene'} = $proj_parent_attributes->[0]->value;
1484 }
1485 return $summary_ref;
1486 }
1487  
1488 =head2 havana_gene
1489  
1490 Example : $havana_gene = $transcript->havana_gene();
1491 Description : Locates the corresponding havana gene
1492 Returns : Bio::EnsEMBL::DBEntry
1493 =cut
1494  
1495 sub havana_gene {
1496 my $self = shift;
1497 my @otts = @{ $self->get_all_DBEntries('Vega_gene') };
1498 my $ott;
1499 foreach my $xref (@otts) {
1500 if ($xref->display_id() =~ /OTT/) {
1501 $ott = $xref;
1502 last;
1503 }
1504 }
1505 return $ott;
1506 }
1507  
1508 =head2 get_Biotype
1509  
1510 Example : my $biotype = $gene->get_Biotype;
1511 Description: Returns the Biotype object of this gene.
1512 When no biotype exists, defaults to 'protein_coding'.
1513 When used to set to a biotype that does not exist in
1514 the biotype table, a biotype object is created with
1515 the provided argument as name and object_type gene.
1516 Returntype : Bio::EnsEMBL::Biotype
1517 Exceptions : none
1518  
1519 =cut
1520  
1521 sub get_Biotype {
1522 my ( $self ) = @_;
1523  
1524 # have a biotype object, return it
1525 if ( ref $self->{'biotype'} eq 'Bio::EnsEMBL::Biotype' ) {
1526 return $self->{'biotype'};
1527 }
1528  
1529 # biotype is first set as a string retrieved from the gene table
1530 # there is no biotype object in the gene object, retrieve it using the biotype string
1531 # if no string, default to protein_coding. this is legacy behaviour and should probably be revisited
1532 my $biotype_name = $self->{'biotype'} // 'protein_coding';
1533  
1534 return $self->set_Biotype( $biotype_name );
1535 }
1536  
1537 =head2 set_Biotype
1538  
1539 Arg [1] : Arg [1] : String - the biotype name to set
1540 Example : my $biotype = $gene->set_Biotype('protin_coding');
1541 Description: Sets the Biotype of this gene to the provided biotype name.
1542 Returns the Biotype object of this gene.
1543 When no biotype exists, defaults to 'protein_coding' name.
1544 When setting a biotype that does not exist in
1545 the biotype table, a biotype object is created with
1546 the provided argument as name and object_type gene.
1547 Returntype : Bio::EnsEMBL::Biotype
1548 Exceptions : If no argument provided
1549  
1550 =cut
1551  
1552 sub set_Biotype {
1553 my ( $self, $name ) = @_;
1554  
1555 throw('No argument provided') unless defined $name;
1556  
1557 # retrieve biotype object from the biotype adaptor
1558 if( defined $self->adaptor() ) {
1559 my $ba = $self->adaptor()->db()->get_BiotypeAdaptor();
1560 $self->{'biotype'} = $ba->fetch_by_name_object_type( $name, 'gene' );
1561 }
1562 # if $self->adaptor is unavailable, create a new biotype object containing name and object_type only
1563 else {
1564 $self->{'biotype'} = Bio::EnsEMBL::Biotype->new(
1565 -NAME => $name,
1566 -OBJECT_TYPE => 'gene',
1567 )
1568 }
1569  
1570 return $self->{'biotype'} ;
1571 }
1572  
1573 =head2 biotype
1574 Arg [1] : (optional) String - the biotype to set
1575 Example : $gene->biotype("protein_coding");
1576 Description: Getter/setter for the attribute biotype name.
1577 Recommended to use instead for a getter:
1578 $biotype = $gene->get_Biotype;
1579 and for a setter:
1580 $biotype = $gene->set_Biotype("protein_coding");
1581 The String biotype name can then be retrieved by
1582 calling name on the Biotype object:
1583 $biotype_name = $biotype->name;
1584 Returntype : String
1585 Exceptions : none
1586 Caller : general
1587 Status : Stable
1588 =cut
1589  
1590 sub biotype {
1591 my ( $self, $biotype_name) = @_;
1592  
1593 # Setter? set_Biotype()
1594 if (defined $biotype_name) {
1595 return $self->set_Biotype($biotype_name)->name;
1596 }
1597  
1598 # Getter? get_Biotype()
1599 return $self->get_Biotype->name;
1600 }
1601  
1602 1;