perl - find max value in each row, return row ID and column header of max value -


i have file (19,000 lines , 200 columns) looks like:

gene clm-mxl-acb_pbs clm-pel-acb_pbs clm-pur-acb_pbs  a1bg 2.927682 2.935334 -0.262044 a1cf -0.503390 -0.193219 0.038984 a2m -0.217628 -0.264332 -0.380048 a2ml1 -0.040747 0.566124 0.935753 

i find maximum value each row, , print max value, row id, , column header of column max found in. output like:

 a1bg clm-pel-acb_pbs 2.935334  a1cf clm-pur-acb_pbs 0.038984  a2m clm-mxl-acb_pbs -0.217628  a2ml1 clm-pur-acb_pbs 0.935753 

i have perl script not work:

my$f=shift@argv; open in, "$f";  my@line; while (<in>){     next if m/gene/;     foreach $l (@line) {         ($row_id, @row_data) = split( / /, $l ) ;         $idx = 0 ;         { $idx = $_ if $row[$_] > $row[$idx] } 1..$#row_data ;         print "$row_id $idx\n" ;         next;     } } 

can point out what's wrong code or suggest solution?

what i'd is, first, save header, can spit out column name later. then, go through each line, saving each field header name, , max number (normally i'd use list::util::max, need key max number, not max number itself, fake list::util::reduce). , can spit out discovered maximum. save bit of effort here, i'm putting data inline, can read arbitrary files well. (i use open $in, '<', $f or die "can't read $f: $!" instead of open statement, though, better error detection , handling.)

#!/opt/myperl/5.20.2/bin/perl  use 5.10.0; use list::util qw(reduce);  @header = {     $line = <data>;     split ' ', $line; };  while (<data>) {     @fields = split ' ', $_;     %data; @data{@header} = @fields;      $max_key = reduce { $data{$a} > $data{$b} ? $a : $b } @header[1..$#header];      join ' ', $data{$header[0]}, $max_key, $data{$max_key}; }   __end__ gene clm-mxl-acb_pbs clm-pel-acb_pbs clm-pur-acb_pbs  a1bg 2.927682 2.935334 -0.262044 a1cf -0.503390 -0.193219 0.038984 a2m -0.217628 -0.264332 -0.380048 a2ml1 -0.040747 0.566124 0.935753