Bio LocatableSeq
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Summary
Bio::LocatableSeq - A Sequence object with start/end points on it
that can be projected into a MSA or have coordinates relative to
another seq.
Package variables
No package variables defined.
Included modules
Bio::Location::Fuzzy
Bio::Location::Simple
Inherit
Bio::PrimarySeq Bio::RangeI
Synopsis
    use Bio::LocatableSeq;
my $seq = new Bio::LocatableSeq(-seq => "CAGT-GGT",
-id => "seq1",
-start => 1,
-end => 7);
Description
    # a normal sequence object
$locseq->seq();
$locseq->id();
# has start,end points $locseq->start(); $locseq->end(); # inherits off RangeI, so range operations possible
Methods
new
No description
Code
startDescriptionCode
endDescriptionCode
_ungapped_len
No description
Code
strandDescriptionCode
get_nseDescriptionCode
no_gaps
No description
Code
column_from_residue_numberDescriptionCode
location_from_columnDescriptionCode
revcomDescriptionCode
truncDescriptionCode
Methods description
startcode    nextTop
 Title   : start
Usage : $obj->start($newval)
Function:
Returns : value of start
Args : newvalue (optional)
endcodeprevnextTop
 Title   : end
Usage : $obj->end($newval)
Function:
Returns : value of end
Args : newvalue (optional)
strandcodeprevnextTop
 Title   : strand
Usage : $obj->strand($newval)
Function:
Returns : value of strand
Args : newvalue (optional)
get_nsecodeprevnextTop
 Title   : get_nse
Usage :
Function: read-only name of form id/start-end
Example :
Returns :
Args :
column_from_residue_numbercodeprevnextTop
 Title   : column_from_residue_number
Usage : $col = $seq->column_from_residue_number($resnumber)
Function:
This function gives the position in the alignment (i.e. column number) of the given residue number in the sequence. For example, for the sequence Seq1/91-97 AC..DEF.GH column_from_residue_number(94) returns 5. An exception is thrown if the residue number would lie outside the length of the aligment (e.g. column_from_residue_number( "Seq2", 22 ) Returns : A column number for the position of the given residue in the given sequence (1 = first column) Args : A residue number in the whole sequence (not just that segment of it in the alignment)
location_from_columncodeprevnextTop
 Title   : location_from_column
Usage : $loc = $ali->location_from_column($column_number)
Function:
This function gives the residue number for a given position in the alignment (i.e. column number) of the given. Gaps complicate this process and force the output to be a Bio::Range where values can be undefined. For example,
for the sequence:
Seq/91-97 .AC..DEF.G. location_from_column( 3 ) position 93 location_from_column( 2 ) position 92^93 location_from_column(10 ) position 97^98 location_from_column( 1 ) position undef An exact position returns a Bio::Location::Simple object where where location_type() returns 'EXACT', if a position is between bases location_type() returns 'IN-BETWEEN'. Column before the first residue returns undef. Note that if the position is after the last residue in the alignment, that there is no guarantee that the original sequence has residues after that position. An exception is thrown if the column number is not within the sequence. Returns : Bio::Location::Simple or undef Args : A column number Throws : If column is not within the sequence
See Bio::Location::Simple for more.
revcomcodeprevnextTop
 Title   : revcom
Usage : $rev = $seq->revcom()
Function: Produces a new Bio::LocatableSeq object which
has the reversed complement of the sequence. For protein
sequences this throws an exception of "Sequence is a
protein. Cannot revcom"
Returns : A new Bio::LocatableSeq object Args : none
trunccodeprevnextTop
 Title   : trunc
Usage : $subseq = $myseq->trunc(10,100);
Function: Provides a truncation of a sequence,
Example : Returns : a fresh Bio::PrimarySeqI implementing object Args : Two integers denoting first and last columns of the sequence to be included into sub-sequence.
Methods code
newdescriptionprevnextTop
sub new {
    my ($class, @args) = @_;
    my $self = $class->SUPER::new(@args);

    my ($start,$end,$strand) =
	$self->_rearrange( [qw(START END STRAND)],
			   @args);

    defined $start && $self->start($start);
    defined $end   && $self->end($end);
    defined $strand && $self->strand($strand);

    return $self; # success - we hope!
}
startdescriptionprevnextTop
sub start {
   my $self = shift;
   if( @_ ) {
      my $value = shift;
      $self->{'start'} = $value;
  }
   return $self->{'start'} if defined $self->{'start'};
   return 1                if $self->seq;
   return;
}
enddescriptionprevnextTop
sub end {
   my $self = shift;
   if( @_ ) {
      my $value = shift;
      my $string = $self->seq;
      if ($self->seq) {
          my $len = $self->_ungapped_len;
	  my $id = $self->id;
	  $self->warn("In sequence $id residue count gives end value $len.
Overriding value [$value] with value $len for Bio::LocatableSeq::end().")
	      and $value = $len if $len != $value and $self->verbose > 0;
      }

      $self->{'end'} = $value;
    }

   return $self->{'end'} || $self->_ungapped_len;
}
_ungapped_lendescriptionprevnextTop
sub _ungapped_len {
    my $self = shift;
    my $string = $self->seq || '';
    $string =~ s/[\.\-]+//g;
    $self->seq ? (return $self->start + CORE::length($string) - 1 ) : undef;
}
stranddescriptionprevnextTop
sub strand {
   my $self = shift;
   if( @_ ) {
      my $value = shift;
      $self->{'strand'} = $value;
    }
    return $self->{'strand'};
}
get_nsedescriptionprevnextTop
sub get_nse {
   my ($self,$char1,$char2) = @_;

   $char1 ||= "/";
   $char2 ||= "-";

   $self->throw("Attribute id not set") unless defined($self->id());
   $self->throw("Attribute start not set") unless defined($self->start());
   $self->throw("Attribute end not set") unless defined($self->end());

   return $self->id() . $char1 . $self->start . $char2 . $self->end ;
}
no_gapsdescriptionprevnextTop
sub no_gaps {
    my ($self,$char) = @_;
    my ($seq, $count) = (undef, 0);

    # default gap characters
$char ||= '-.'; $self->warn("I hope you know what you are doing setting gap to [$char]") unless $char =~ /[-.]/; $seq = $self->seq; return 0 unless $seq; # empty sequence does not have gaps
$seq =~ s/^([$char]+)//; $seq =~ s/([$char]+)$//; $count++ while $seq =~ /[$char]+/g; return $count;
}
column_from_residue_numberdescriptionprevnextTop
sub column_from_residue_number {
    my ($self, $resnumber) = @_;

    $self->throw("Residue number has to be a positive integer, not [$resnumber]")
	unless $resnumber =~ /^\d+$/ and $resnumber > 0;

    if ($resnumber >= $self->start() and $resnumber <= $self->end()) {
	my @residues = split //, $self->seq;
	my $count = $self->start();
	my $i;
	my ($start,$end,$inc,$test);
        my $strand = $self->strand || 0;
	# the following bit of "magic" allows the main loop logic to be the
# same regardless of the strand of the sequence
($start,$end,$inc,$test)= ($strand == -1)? (scalar(@residues-1),0,-1,sub{$i >= $end}) : (0,scalar(@residues-1),1,sub{$i <= $end}); for ($i=$start; $test->(); $i+= $inc) { if ($residues[$i] ne '.' and $residues[$i] ne '-') { $count == $resnumber and last; $count++; } } # $i now holds the index of the column.
# The actual column number is this index + 1
return $i+1; } $self->throw("Could not find residue number $resnumber");
}
location_from_columndescriptionprevnextTop
sub location_from_column {
    my ($self, $column) = @_;

    $self->throw("Column number has to be a positive integer, not [$column]")
	unless $column =~ /^\d+$/ and $column > 0;
    $self->throw("Column number [$column] is larger than".
		 " sequence length [". $self->length. "]")
	unless $column <= $self->length;

    my ($loc);
    my $s = $self->subseq(1,$column);
    $s =~ s/[^a-zA-Z\*]//g;

    my $pos = CORE::length $s;

    my $start = $self->start || 0 ;
    my $strand = $self->strand() || 1;
    my $relative_pos = ($strand == -1)
        ? ($self->end - $pos + 1)
	: ($pos + $start - 1);
    if ($self->subseq($column, $column) =~ /[a-zA-Z\*]/ ) {
	$loc = new Bio::Location::Simple
	    (-start  => $relative_pos,
	     -end    => $relative_pos,
	     -strand => 1,
	     );
    } elsif ($pos == 0 and $self->start == 1) {
    } else {
      my ($start,$end) = ($relative_pos, $relative_pos + $strand);
      if ($strand == -1) {
	($start,$end) = ($end,$start);
      }
	$loc = new Bio::Location::Simple
	    (-start         => $start,
	     -end           => $end,
	     -strand        => 1,
	     -location_type => 'IN-BETWEEN'
	     );
    }
    return $loc;
}
revcomdescriptionprevnextTop
sub revcom {
    my ($self) = @_;

    my $new = $self->SUPER::revcom;
    $new->strand($self->strand * -1);
    $new->start($self->start) if $self->start;
    $new->end($self->end) if $self->end;
    return $new;
}
truncdescriptionprevnextTop
sub trunc {
    my ($self, $start, $end) = @_;
    my $new = $self->SUPER::trunc($start, $end);
    $new->strand($self->strand);

    # end will be automatically calculated
$start = $end if $self->strand == -1; $start = $self->location_from_column($start); $start ? ($start = $start->end) : ($start = 1); $new->start($start) if $start; return $new;
}
General documentation
FEEDBACKTop
Mailing ListsTop
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
The locatable sequence object was developed mainly because the
SimpleAlign object requires this functionality, and in the rewrite
of the Sequence object we had to decide what to do with this.
It is, to be honest, not well integrated with the rest of bioperl, for
example, the trunc() function does not return a LocatableSeq object,
as some might have thought. There are all sorts of nasty gotcha's
about interactions between coordinate systems when these sort of
objects are used.
Reporting BugsTop
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:
  http://bugzilla.open-bio.org/
APPENDIXTop
The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _
no_gapTop
 Title   : no_gaps
Usage :$self->no_gaps('.')
Function:
Gets number of gaps in the sequence. The count excludes leading or trailing gap characters. Valid bioperl sequence characters are [A-Za-z\-\.\*]. Of these, '.' and '-' are counted as gap characters unless an optional argument specifies one of them. Returns : number of internal gaps in the sequnce. Args : a gap character (optional)