Skip to content

Instantly share code, notes, and snippets.

@coela
Last active December 18, 2015 07:49
Show Gist options
  • Select an option

  • Save coela/5749544 to your computer and use it in GitHub Desktop.

Select an option

Save coela/5749544 to your computer and use it in GitHub Desktop.
use 5.16.2;
use warnings;
use Data::Dump qw/dump/;
open my $FILE, '<' , $ARGV[0] || die;
my $hit;
my $last_query = 'hoge';
while (<$FILE>) {
chomp;
my @line = split /\t/;
if ( $last_query ne $line[0] || eof ) {
for ( sort { $hit->{$a}->{e_value} <=> $hit->{$b}->{e_value} } keys %$hit ) {
say join "\t", @{$hit->{$_}->{line}};
}
$hit = {};
$hit->{$line[1]}->{e_value} = $line[-2];
$hit->{$line[1]}->{line} = \@line;
}
else {
if (! defined $hit->{$line[1]}) {
# $hit->{$line[1]}->{e_value} == $hit->{$line[1]}->{line}->[-2];
$hit->{$line[1]}->{e_value} = $line[-2];
$hit->{$line[1]}->{line} = \@line;
}
elsif ($hit->{$line[1]}->{e_value} > $line[-2]) {
$hit->{$line[1]}->{e_value} = $line[-2];
$hit->{$line[1]}->{line} = \@line;
}
}
$last_query = $line[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment