#!/usr/local/bin/perl $I = 20 ; $throw = 3 ; $alpha1=40; $alpha0=0.4; # throw away the first column, leave the second as 0-1, the third on # log scale from 0.4 to 40 (no, linear) # then others scale down to 0-1. while ( <> ) { s/^\s*//; # get rid of initial gap on line ($c,$p,$alpha,@w)=split ; # @w=split ; # (/[ \t\n]+/, $_ , $I ; # if ( (@w[1] <0.0) || (@w[1] >1.0) ) # { print STDERR "skip line\n" ; next ; } # $p = $w[1] ; # $alpha = $w[2] ; if ( ($p <0.0) || ($p >1.0) || ($#w < $I-2) || ($c =~ /\#/) ) { print STDERR "skip line\n" ; next ; } $sum = 0.0 ; for ( $i = 0 ; $i < $I ; $i++ ) { $sum += $w[$i] ; } if ( $alpha != 0 ) { # $la = log( $alpha / $alpha0 ) / log($alpha1/$alpha0) ; $la = $alpha / $alpha1 ; } else { $la = 0.0 ; print STDERR "eek: alpha = ",$alpha," p = ", $p,"\n",@w ; } $row ++ ; $out = "" ; for ( $i = 0 ; $i < $I ; $i++ ) { $w[$i] /= $sum ; $out .= sprintf ( "%6.4f ", $w[$i] ) ; } $out .= sprintf ( "0.0 %6.4f 0.0 %6.4f" , $p , $la ); $out .= sprintf ("\n") ; # if ( $sum != $alpha ) { print STDERR "check " ,$sum," = ", $alpha , "\n"; # } $arr[$row] = $out ; $pr{$out} = $p ; $alr[$row] = $alpha ; } @final = sort bypr @arr ; print @final ; sub bypr { $pr{$a} <=> $pr{$b} ; }