BioPerl

 view release on metacpan or  search on metacpan

Bio/SeqFeature/Gene/GeneStructure.pm  view on Meta::CPAN

  # See documentation of methods.

=head1 DESCRIPTION

A feature representing a gene structure. As of now, a gene structure
really is only a collection of transcripts. See
L<Bio::SeqFeature::Gene::TranscriptI> (interface) and
L<Bio::SeqFeature::Gene::Transcript> (implementation) for the features
of such objects.

=head1 FEEDBACK

=head2 Mailing Lists

User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to one
of the Bioperl mailing lists.  Your participation is much appreciated.

  bioperl-l@bioperl.org                  - General discussion
  http://bioperl.org/wiki/Mailing_lists  - About the mailing lists

=head2 Support 

Please direct usage questions or support issues to the mailing list:

I<bioperl-l@bioperl.org>

rather than to the module maintainer directly. Many experienced and 
reponsive experts will be able look at the problem and quickly 
address it. Please include a thorough description of the problem 
with code and data examples if at all possible.

=head2 Reporting Bugs

Report bugs to the Bioperl bug tracking system to help us keep track
 the bugs and their resolution. Bug reports can be submitted via the
 web:

  https://github.com/bioperl/bioperl-live/issues

=head1 AUTHOR - Hilmar Lapp

Email hlapp-at-gmx.net

=head1 APPENDIX

The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _

=cut


# Let the code begin...


package Bio::SeqFeature::Gene::GeneStructure;
use vars qw($WeakRefs);
use strict;

BEGIN {
    eval "use Scalar::Util qw(weaken);";
    if ($@) {
	$Bio::SeqFeature::Gene::GeneStructure::WeakRefs = 0;  
    } else { $Bio::SeqFeature::Gene::GeneStructure::WeakRefs = 1; }
}


use base qw(Bio::SeqFeature::Generic Bio::SeqFeature::Gene::GeneStructureI);


sub new {
    my ($caller, @args) = @_;
    my $self = $caller->SUPER::new(@args);
    $self->_register_for_cleanup(\&gene_cleanup);
    my ($primary) =
	$self->_rearrange([qw(PRIMARY
			      )],@args);
    
    $primary = 'genestructure' unless $primary;
    $self->primary_tag($primary);
    $self->strand(0) if(! defined($self->strand()));
    return $self;
}

=head2 transcripts

 Title   : transcripts
 Usage   : @transcripts = $gene->transcripts();
 Function: Get the transcripts of this gene structure. Many gene structures
           will have only one transcript.

 Returns : An array of Bio::SeqFeature::Gene::TranscriptI implementing objects.
 Args    : 


=cut

sub transcripts {
    return @{shift->{'_transcripts'} || []};
}

=head2 add_transcript

 Title   : add_transcript()
 Usage   : $gene->add_transcript($transcript);
 Function: Add a transcript to this gene structure.
 Returns : 
 Args    : A Bio::SeqFeature::Gene::TranscriptI implementing object.


=cut

sub add_transcript {
    my ($self, $fea) = @_;

    if(!$fea || ! $fea->isa('Bio::SeqFeature::Gene::TranscriptI') ) {
	$self->throw("$fea does not implement Bio::SeqFeature::Gene::TranscriptI");
    }
    unless( exists $self->{'_transcripts'}  ) {
	$self->{'_transcripts'} = [];
    }
    $self->_expand_region($fea);
    if( $Bio::SeqFeature::Gene::GeneStructure::WeakRefs ) {
	$fea->parent(weaken $self);
    } else {
	$fea->parent($self);
    }
    push(@{$self->{'_transcripts'}}, $fea);
}

=head2 flush_transcripts

 Title   : flush_transcripts()
 Usage   : $gene->flush_transcripts();
 Function: Remove all transcripts from this gene structure.
 Returns : 
 Args    :


=cut

sub flush_transcripts {
    my ($self) = @_;    
    if( defined $self->{'_transcripts'} ) {
	foreach my $t ( grep {defined} @{$self->{'_transcripts'} || []} ) {
	    $t->parent(undef); # remove bkwds pointers
	    $t = undef;
	}
	delete($self->{'_transcripts'});	
    }
}

=head2 add_transcript_as_features

 Title   : add_transcript_as_features
 Usage   : $gene->add_transcript_as_features(@featurelist);
 Function: take a list of Bio::SeqFeatureI objects and turn them into a
           Bio::SeqFeature::Gene::Transcript object.  Add that transcript to the gene.
 Returns : nothing
 Args    : a list of Bio::SeqFeatureI compliant objects


=cut

sub add_transcript_as_features {
    my ($self,@features) = @_;
    my $transcript=Bio::SeqFeature::Gene::Transcript->new;
    foreach my $fea (@features) {
	if ($fea->primary_tag =~ /utr/i) { #UTR / utr/ 3' utr / utr5 etc.
	    $transcript->add_utr($fea);
	} elsif ($fea->primary_tag =~ /promot/i) { #allow for spelling differences
	    $transcript->add_promoter($fea);
	} elsif ($fea->primary_tag =~ /poly.*A/i) { #polyA, POLY_A, etc.
	    $transcript->poly_A_site($fea);
	} else {		#assume the rest are exons
	    $transcript->add_exon($fea);
	}
    }
    $self->add_transcript($transcript);
}


=head2 promoters



( run in 0.791 second using v1.01-cache-2.11-cpan-39bf76dae61 )