BioPerl

 view release on metacpan or  search on metacpan

Bio/Location/Split.pm  view on Meta::CPAN

    # No sort by default because it breaks circular cut by origin features
    # (like "join(2006035..2007700,1..257)"). Sorting is user responsability.
    # Assume Start to be 1st segment start and End to be last segment End.
    my @locs = $self->sub_Location(0);
    return ( @locs ) ? $locs[0]->min_start : undef;
}

=head2 max_start

  Title   : max_start
  Usage   : my $maxstart = $location->max_start();
  Function: Get maximum starting location of feature startpoint  
  Returns : integer or undef if no maximum starting point.
  Args    : none

=cut

sub max_start {
    my ($self,$value) = @_;

    if( defined $value ) {
        $self->throw(  "Trying to set the maximum starting point of a split "
                     . "location, that is not possible, try manipulating the sub Locations");
    }
    # No sort by default because it breaks circular cut by origin features
    # (like "join(2006035..2007700,1..257)"). Sorting is user responsability.
    # Assume Start to be 1st segment start and End to be last segment End.
    my @locs = $self->sub_Location(0);
    return ( @locs ) ? $locs[0]->max_start : undef;
}

=head2 start_pos_type

  Title   : start_pos_type
  Usage   : my $start_pos_type = $location->start_pos_type();
  Function: Get start position type (ie <,>, ^) 
  Returns : type of position coded as text 
            ('BEFORE', 'AFTER', 'EXACT','WITHIN', 'BETWEEN')
  Args    : none

=cut

sub start_pos_type {
    my ($self,$value) = @_;

    if( defined $value ) {
        $self->throw(  "Trying to set the start_pos_type of a split location, "
                     . "that is not possible, try manipulating the sub Locations");
    }
    # No sort by default because it breaks circular cut by origin features
    # (like "join(2006035..2007700,1..257)"). Sorting is user responsability.
    # Assume Start to be 1st segment start and End to be last segment End.
    my @locs = $self->sub_Location(0);
    return ( @locs ) ? $locs[0]->start_pos_type : undef;
}

=head2 min_end

  Title   : min_end
  Usage   : my $minend = $location->min_end();
  Function: Get minimum ending location of feature endpoint 
  Returns : integer or undef if no minimum ending point.
  Args    : none

=cut

sub min_end {
    my ($self,$value) = @_;

    if( defined $value ) {
        $self->throw(  "Trying to set the minimum end point of a split location, "
                     . "that is not possible, try manipulating the sub Locations");
    }
    # No sort by default because it breaks circular cut by origin features
    # (like "join(2006035..2007700,1..257)"). Sorting is user responsability.
    # Assume Start to be 1st segment start and End to be last segment End.
    my @locs = $self->sub_Location(0);

    # Return the End corresponding to the same sequence as the top ('master')
    # if the top seq is undefined, take the first defined in a sublocation.
    # Example: for "join(1..100,J00194.1:100..202)", End would be 100
    my $seqid = $self->seq_id;
    my $i = 0;
    while (not defined $seqid and $i <= $#locs) {
        $seqid = $locs[$i++]->seq_id;
    }

    my @same_id_locs = ($seqid ? grep { $_->seq_id eq $seqid } @locs
                     :           @locs);
    # If there is a $seqid but no sublocations have the same id,
    # try with the first id found in the sublocations instead,
    # and if that fails return the last segment value
    if (@locs and not @same_id_locs) {
        my $first_id;
        while (not defined $first_id and $i <= $#locs) {
            $first_id = $locs[$i++]->seq_id;
        }
        @same_id_locs = ($first_id ? grep { $_->seq_id eq $first_id } @locs
                      :              @locs);
    }
    return ( @same_id_locs ) ? $same_id_locs[-1]->min_end : undef;
}

=head2 max_end

  Title   : max_end
  Usage   : my $maxend = $location->max_end();
  Function: Get maximum ending location of feature endpoint 
  Returns : integer or undef if no maximum ending point.
  Args    : none

=cut

sub max_end {
    my ($self,$value) = @_;

    if( defined $value ) {
        $self->throw(  "Trying to set the maximum end point of a split location, "
                     ."that is not possible, try manipulating the sub Locations");
    }
    # No sort by default because it breaks circular cut by origin features
    # (like "join(2006035..2007700,1..257)"). Sorting is user responsability.
    # Assume Start to be 1st segment start and End to be last segment End.
    my @locs = $self->sub_Location(0);

    # Return the End corresponding to the same sequence as the top ('master')
    # if the top seq is undefined, take the first defined in a sublocation.
    # Example: for "join(1..100,J00194.1:100..202)", End would be 100
    my $seqid = $self->seq_id;
    my $i = 0;
    while (not defined $seqid and $i <= $#locs) {
        $seqid = $locs[$i++]->seq_id;
    }

    my @same_id_locs = ($seqid ? grep { $_->seq_id eq $seqid } @locs
                     :           @locs);
    # If there is a $seqid but no sublocations have the same id,
    # try with the first id found in the sublocations instead,
    # and if that fails return the last segment value
    if (@locs and not @same_id_locs) {
        my $first_id;
        while (not defined $first_id and $i <= $#locs) {
            $first_id = $locs[$i++]->seq_id;
        }
        @same_id_locs = ($first_id ? grep { $_->seq_id eq $first_id } @locs
                      :              @locs);
    }
    return ( @same_id_locs ) ? $same_id_locs[-1]->max_end : undef;
}

=head2 end_pos_type

  Title   : end_pos_type
  Usage   : my $end_pos_type = $location->end_pos_type();
  Function: Get end position type (ie <,>, ^) 
  Returns : type of position coded as text 
            ('BEFORE', 'AFTER', 'EXACT','WITHIN', 'BETWEEN')
  Args    : none

=cut

sub end_pos_type {
    my ($self,$value) = @_;

    if( defined $value ) {
        $self->throw(  "Trying to set end_pos_type of a split location, "
                     . "that is not possible, try manipulating the sub Locations");
    }



( run in 1.898 second using v1.01-cache-2.11-cpan-437f7b0c052 )