#!/usr/bin/perl -w
use strict;

#this is the blast clean results file
my $filein=shift;

my $fileout="/tmp/matches_list.txt";

open FILEIN, $filein;

my %query_matches=();

my $query='';
while (<FILEIN>){
    /^\s*Query=\s+(.+)$/ and $query=$1;
    /^\s*>\s*([^\s]+)\s/ and $query_matches{$query}=$1;
}

close FILEIN;

open FILEOUT, ">$fileout";

foreach (keys %query_matches){
    print FILEOUT "$_\t$query_matches{$_}\n";
}

close FILEOUT;
