@staticmethod
def compare_results(save, best_hsp, tmp_results, tmp_gene_split,
    allowed_overlap):
    """
            Function for comparing hits and saving only the best hit
        """
    hit_id = best_hsp['hit_id']
    new_start_query = best_hsp['query_start']
    new_end_query = best_hsp['query_end']
    new_start_sbjct = int(best_hsp['sbjct_start'])
    new_end_sbjct = int(best_hsp['sbjct_end'])
    new_score = best_hsp['cal_score']
    new_db_hit = best_hsp['sbjct_header']
    new_contig = best_hsp['contig_name']
    new_HSP = best_hsp['HSP_length']
    keys = list(tmp_results.keys())
    for hit in keys:
        hit_data = tmp_results[hit]
        old_start_query = hit_data['query_start']
        old_end_query = hit_data['query_end']
        old_start_sbjct = int(hit_data['sbjct_start'])
        old_end_sbjct = int(hit_data['sbjct_end'])
        old_score = hit_data['cal_score']
        old_db_hit = hit_data['sbjct_header']
        old_contig = hit_data['contig_name']
        old_HSP = hit_data['HSP_length']
        remove_old = 0
        if new_db_hit == old_db_hit:
            if old_contig != new_contig:
                if (new_db_hit in tmp_gene_split and hit_id not in
                    tmp_gene_split[new_db_hit]):
                    tmp_gene_split[new_db_hit][hit_id] = 1
            elif new_start_sbjct < old_start_sbjct or new_end_sbjct > old_end_sbjct:
                tmp_gene_split[old_db_hit][hit_id] = 1
                if hit not in tmp_gene_split[old_db_hit]:
                    tmp_gene_split[old_db_hit][hit] = 1
        if new_contig == old_contig:
            print('Same contig: {} == {}'.format(new_contig, old_contig))
            print('\t{} vs {}'.format(new_db_hit, old_db_hit))
            hit_union_length = max(old_end_query, new_end_query) - min(
                old_start_query, new_start_query)
            hit_lengths_sum = old_end_query - old_start_query + (new_end_query
                 - new_start_query)
            overlap_len = hit_lengths_sum - hit_union_length
            if overlap_len < allowed_overlap:
                print('\tignore overlap ({}): {}'.format(overlap_len,
                    new_db_hit))
                continue
            print('\toverlap found ({}): {}'.format(overlap_len, new_db_hit))
            if (old_start_query == new_start_query and old_end_query ==
                new_end_query):
                if best_hsp['perc_ident'] > hit_data['perc_ident']:
                    remove_old = 1
                    if (new_db_hit in tmp_gene_split and hit_id not in
                        tmp_gene_split[new_db_hit]):
                        tmp_gene_split[new_db_hit][hit_id] = 1
                elif best_hsp['perc_ident'] == hit_data['perc_ident']:
                    if (new_db_hit in tmp_gene_split and hit_id not in
                        tmp_gene_split[new_db_hit]):
                        tmp_gene_split[new_db_hit][hit_id] = 1
                else:
                    save = 0
                    if (new_db_hit in tmp_gene_split and hit_id in
                        tmp_gene_split[new_db_hit]):
                        del tmp_gene_split[new_db_hit][hit_id]
                    break
            elif hit_union_length <= hit_lengths_sum:
                print('\t{} <= {}'.format(hit_union_length, hit_lengths_sum))
                print('\t\tScores: {} cmp {}'.format(new_score, old_score))
                if new_score > old_score:
                    remove_old = 1
                    if (new_db_hit in tmp_gene_split and hit_id not in
                        tmp_gene_split[new_db_hit]):
                        tmp_gene_split[new_db_hit][hit_id] = 1
                elif new_score == old_score:
                    if int(best_hsp['perc_coverage']) == int(hit_data[
                        'perc_coverage']) and new_HSP > old_HSP:
                        remove_old = 1
                    elif int(best_hsp['perc_coverage']) == int(hit_data[
                        'perc_coverage']) and old_HSP > new_HSP:
                        save = 0
                    elif int(best_hsp['perc_coverage']) == int(hit_data[
                        'perc_coverage']) and old_HSP == new_HSP:
                        pass
                    if (new_db_hit in tmp_gene_split and hit_id not in
                        tmp_gene_split[new_db_hit]):
                        tmp_gene_split[new_db_hit][hit_id] = 1
                else:
                    if (new_db_hit in tmp_gene_split and hit_id in
                        tmp_gene_split[new_db_hit]):
                        del tmp_gene_split[new_db_hit][hit_id]
                    save = 0
                    break
        if remove_old == 1:
            del tmp_results[hit]
            if old_db_hit in tmp_gene_split and hit in tmp_gene_split[
                old_db_hit]:
                del tmp_gene_split[old_db_hit][hit]
    return save, tmp_gene_split, tmp_results
