[Bioperl-l] true inserts into a SimpleAlign

Mark A. Jensen maj at fortinbras.us
Tue Feb 3 19:06:12 EST 2009


Folks-

I was desiring to make a true insertion of a LocatableSeq into a SimpleAlign,
rather than just adding it to the end as
 $aln->add_seq($lseq)
would do. This:
 $aln->add_seq($lseq,$order)
currently stomps on whatever is stored at $order in the index. The patch at 
the bottom of the post allows a true insertion (if something exists at index 
location $order, the minimum number of entries from that point on are moved 
down to make room.)

Might be useful for others. All t/Align/SimpleAlign.t tests pass. Lemme know-

Mark

---

 Index: SimpleAlign.pm
 ===================================================================
 --- SimpleAlign.pm (revision 15496)
 +++ SimpleAlign.pm (working copy) 
 @@ -304,8 +304,22 @@
      else {
   $self->debug( "Assigning $name to $order\n");
  
 - $self->{'_order'}->{$order} = $name;
 + my $ordh = $self->{'_order'};
 + if ($ordh->{$order}) {
 +     # make space to insert
 +     # $c->() returns (in reverse order) the first subsequence 
 +     # of consecutive integers; i.e., $c->(1,2,3,5,6,7) returns
 +     # (3,2,1), and $c->(2,4,5) returns (2).
 +     my $c;
 +     $c = sub { return (($_[1]-$_[0] == 1) ? ($c->(@_[1..$#_]),$_[0]) : $_[0]); };
 +     map { 
 +  $ordh->{$_+1} = $ordh->{$_}
 +     } $c->(sort {$a <=> $b} grep {$_ >= $order} keys %{$ordh});
 
 + }
 + $ordh->{$order} = $name;
 +
 +
   unless( exists( $self->{'_start_end_lists'}->{$id})) {
       $self->{'_start_end_lists'}->{$id} = [];
   }
 


More information about the Bioperl-l mailing list