I'd do it something like this:
my @genes; # I assume these come from somewhere for my $style (qw/ g2d pocus dgp /) { my($in, $out) = ($style . "_ranking", $style . "_rankratio"); # step 1: locate and sort the relevant genes for this ranking styl +e my @set = sort { $a->{$in} <=> $b->{$in} } grep $_->{$in}, @genes; # step 2: get a count my $total = @set; # step 3: update the located genes with a rankratio for my $index (0 .. $#set) { $set[$index]{$out} = ($index + 1) / $total; } }
Notes: I select the genes that have a particular ranking specified by checking $_->{$in} in a boolean context, so that it'll be false for zero or undef without warnings; I never store the intermediate re-based ranking as it is implicit in the order of @set; I only loop over the selected genes to update them, so I won't try to update an undef value, nor (since there would be zero loop iterations) will this try to divide by zero.
This code is untested.
Hugo
In reply to Re: converting list of rankings into list of rankratio's.
by hv
in thread converting list of rankings into list of rankratio's.
by BioGeek
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |