The output will exclude duplicate data (that's what hashes are for); in the case of distinct rows having the same key and evalue, all rows will be included in the "combined" file, and the one with the (ascii-betically) lowest value in column two will be printed to the "lowest" file (you might want to modify that, by controlling how the sort is done in the innermost "for" loop).
#!/usr/bin/perl use strict; use warnings; my %data; while ( <DATA> ) { my ( $key, $fields, $evalue ) = ( /^(\S+)\s+(.*?\s(\S+))\s*$/ ); $data{$key}{$evalue}{$fields} = undef; } open my $f1, ">", "combined.data" or die $!; open my $f2, ">", "lowest.data" or die $!; for my $key ( sort keys %data ) { my $combined = ""; my $printed_lowest = 0; for my $evalue ( sort {$a<=>$b} keys %{$data{$key}} ) { for ( sort keys %{$data{$key}{$evalue}} ) { $combined .= "\t$_"; print $f2 "$key\t$_\n" unless ($printed_lowest++); } } print $f1 "$key$combined\n"; } __DATA__ Q3KIL4_PSEPF ONE 134 380 1 252 216.3 6.3e-64 Q3M236_ANAVT TWO 107 563 1 468 203.2 5.3e-60 Q3M236_ANAVT THREE 250 494 1 277 219.1 8.6e-65 Q3M5F5_ANAVT FOUR 296 608 1 355 166.2 7.4e-49 Q3M5F5_ANAVT FIVE 299 584 1 304 188.2 1.7e-55 Q3M7Z1_ANAVT SIX 51 181 1 140 99.0 1.2e-28 Q3MAD2_ANAVT SEVEN 107 508 1 468 350.1 3.3e-104 Q3MAD2_ANAVT EIGHT 230 457 1 277 201.1 2.3e-59 Q3MBT3_ANAVT NINE 203 606 1 468 102.5 1.1e-29 Q3MBT3_ANAVT TEN 326 559 1 277 221.6 1.6e-65 Q3MBT3_ANAVT ELEVEN 134 333 1 234 -334.1 2.7e-44 Q3MD63_ANAVT TWELVE 173 491 1 355 248.5 1.2e-73
In reply to Re: how to combine?
by graff
in thread how to combine?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |