EnsEMBL/Gene.pm untested

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