perl - How to print result with maximum value under each header? -


i have data , perl code following. trying find letter combination maximum score (last column) under each header (>dna1, >dna2) , print it. wrote code in perl following:

use strict; use warnings; ($line); $max = 0; @prediction; foreach $line (<data>) {     chomp($line);     if ($line =~ /^>/) {         print "$line";     }     else {         @split = split(/\s+/,$line);         $score = pop @split;         if ($max < $score) {             $max = $score;             @prediction = @split;             push @prediction, $max;         }     #print "$domain\n";     }     print "@prediction\n"; } __data__ >dna1 d   124.6 d t   137.5 g   -3.4 g t   9.5 t   12.9 >dna2   196.3 k   186.5 k h   192.7 h m   206.2 m   200 

the output

>dna1 d 124.6 d t 137.5 d t 137.5 d t 137.5 d t 137.5 >dna2d t 137.5 196.3 196.3 196.3 h m 206.2 h m 206.2 

could please me figure out how can output final combination max score following:

>dna1 d t 137.5 >dna2 h m 206.2 

thanks!

the following produces expected output:

#!/usr/bin/perl use warnings; use strict;  ($max_score, $max_combination); while (my $line = <data>) {     if ($line =~ /^>/) {         print "$max_combination $max_score\n" if $max_combination;          print $line;         $max_score = 0;      } elsif (my ($combination, $score) = $line =~ /(.*)\s+([0-9.]+)/) {         if ($score > $max_score) {             $max_score       = $score;             $max_combination = $combination;         }     } } print "$max_combination $max_score\n"; 

the main difference need print result when new group starts, or @ end.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -