BioPerl

 view release on metacpan or  search on metacpan

Bio/Map/GenePosition.pm  view on Meta::CPAN


 Title   : type
 Usage   : my $type = $position->type();
           $position->type($type);
 Function: Get/set the type of this position.
 Returns : string
 Args    : none to get, OR
           string transcript|coding|exon|intron to set

=cut

sub type {
    my $self = shift;
    if (@_) {
        my $type = shift;
        if ($type !~ /transcript|coding|exon|intron/i) {
            $self->throw("type must be supplied and be one of 'transcript', 'coding', 'exon', 'intron'");
        }
        $self->{type} = $type;
    }
    return $self->{type};
}

=head2 relative

  Title   : relative
  Usage   : my $relative = $position->relative();
            $position->relative($relative);
  Function: Get/set the thing this Position's coordinates (numerical(), start(),
            end()) are relative to, as described by a RelativeI object.
  Returns : Bio::Map::GeneRelative. The default GeneRelative returned has a
            meaning that depends on the type() of GenePosition this is:
            'transcript'         : "relative to the start of the gene on the
                                    Position's map"
            'coding|exon|intron' : "relative to the start of the default
                                    transcript of the gene on the Position's map"
  Args    : none to get, OR
            Bio::Map::GeneRelative to set

=cut

sub relative {
    my ($self, $relative) = @_;
    if ($relative) {
        $self->throw("Must supply an object") unless ref($relative);
        $self->throw("This is [$relative], not a Bio::Map::GeneRelative") unless $relative->isa('Bio::Map::GeneRelative');
        $self->{_relative} = $relative;
    }
    return $self->{_relative} || $self->_default_relative;
}

=head2 seq

 Title   : seq
 Usage   : my $string = $position->seq();
 Function: Get/set the sequence as a string of letters. If no sequence is
           manually set by you, the position's map will be asked for the
           sequence, and if available, that will be returned.
 Returns : scalar
 Args    : Optionally on set the new value (a string). An optional second
           argument presets the alphabet (otherwise it will be guessed).

=cut

sub seq {
    # $shortcut is internal-use only by GeneMap
    my ($self, $str, $alpha, $shortcut) = @_;
    
    my $seq = $self->SUPER::seq($str, $alpha);
    
    if ($seq) {
        $self->length(CORE::length($seq));
        return $seq;
    }
    elsif (! $shortcut && defined(my $map = $self->map) && ! defined $self->{_getting_seq}) {
        $self->{_getting_seq} = 1;
        $seq = $map->subseq($self);
        delete $self->{_getting_seq};
        return $seq;
    }
    return;
}

# return a Relative that is suitable for the type
sub _default_relative {
    my $self = shift;
    my $type = $self->type;
    if ($type eq 'transcript') {
        return Bio::Map::GeneRelative->new(-gene => 0, -description => 'start of gene');
    }
    else {
        return Bio::Map::GeneRelative->new(-transcript => 0, -description => 'start of default transcript');
    }
}

1;



( run in 2.336 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )