in reply to Re: Restore the original order of an array after sort and performing some funchtion on array values
in thread Restore the original order of an array after sort and performing some funchtion on array values
Can I use the same concept on a hash value? Let's say I want to perform the same operation on values of the hash and return the sorted keys with new data. For instance:
#!/usr/local/bin/perl use strict; my %pvalues = ( 1=> 0.5453980, 2=> 0.4902384, 3=> 0.8167950, 4=> 0.2821822, 5=> 0.4693030, 6=> 0.6491767, 7=> 0.9802138, 8=> 0.1155778, 9=> 0.9585124, 10=> 0.4069490 );
They keys of course are unique but the values may not. I have done the following.
my $numberPvalues = scalar keys %pvalues; my $numberPvaluesCounter = scalar keys %pvalues; my $numberPos = 0; # now loop through all p values and calculate FDR value # store FDR values in hash, key = pos, value is FDRq my @reversPvalues =(); my %sortedTransfPvalues =(); my @inversPvalue =(); my @cumulminPvalue =(); while ($numberPvaluesCounter >= 1 ){ #Sort the original pvalue hash based on the values descen +ding manner foreach my $posCurrentPvalue (sort {$pvalues{$b} <=> $pva +lues{$a}} keys %pvalues) { #calculate the transformed pvalues based on its rank + in the sorted value in the hash my $transformedPvalue = $pvalues{$posCurrentPvalue} +* $numberPvalues / $numberPvaluesCounter; $numberPvaluesCounter--; #new indcies $numberPos++; push (@inversPvalue, $transformedPvalue); #$sortedTransfPvalues{$numberPos}{$posCurrent +Pvalue} = $transformedPvalue; #$sortedTransfPvalues{$posCurrentPvalue}{$num +berPos} = $transformedPvalue; print "$posCurrentPvalue\t$transformedPvalue\ +n"; }#end foreach and sorting values }#end while for count down
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Restore the original order of an array after sort and performing some funchtion on array values
by BrowserUk (Patriarch) on Mar 03, 2010 at 20:52 UTC | |
by sesemin (Beadle) on Mar 03, 2010 at 22:36 UTC | |
by BrowserUk (Patriarch) on Mar 03, 2010 at 23:35 UTC | |
by sesemin (Beadle) on Mar 04, 2010 at 00:29 UTC | |
by BrowserUk (Patriarch) on Mar 04, 2010 at 01:21 UTC |