[Bioperl-l] Fwd: SimpleAlign bug?

Spiros Denaxas spiros at lokku.com
Wed Apr 11 11:51:27 EDT 2007


This looks like the case of cmp vs <=> I think !

my @array = (1,10,2,3,4,5,6,7,8,9) ;
print join(",", @array), "\n";
my @sorted1 = sort(@array) ;
print join(",", @sorted1), "\n";
my @sorted2 = (sort { $a <=> $b } @array);
print join(",", @sorted2), "\n";

idaru:/tmp spiros$ perl koko.pl
1,10,2,3,4,5,6,7,8,9 # normal array
1,10,2,3,4,5,6,7,8,9 # sorted with sort
1,2,3,4,5,6,7,8,9,10 # sorted with <=>

Spiros



On 4/11/07, Kevin Brown <Kevin.M.Brown at asu.edu> wrote:
> > What is going on here? Can anyone remember doing this?
> >
> >       -Heikki
> >
> > Please can I ask what is the purpose of the line @pos = sort
> > @pos; in the select_noncont subroutine of SimpleAlign.pm.
> >
> >
> >
> > In previous versions this line was not present and I could
> > use the function to reorder the alignment e.g in an alignment
> > with 5 sequences I could reorder it to put the second
> > sequence last using $aln->select_noncont(1,3,4,5,2). The sort
> > function stops this, but even if the idea is to sort
> > numerically this dos not work since the sort function as is
> > will put 10 before 2, so that
> > ->select_noncont(1,2,3,4,5,6,7,8,9,10) would reorder the sequences in
> > the alignment to be 1, 10, 2, 3, 4,5, 6, 7, 8,9 .
>
> Not sure why 10 would come before 2 since perl would interpret that list
> as a series of integers even if they were entered as strings and do the
> sort.
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l
>


More information about the Bioperl-l mailing list