def usearch_cluster_seqs_ref(
        fasta_filepath,
        output_filepath=None,
        percent_id=0.97,
        sizein=True,
        sizeout=True,
        w=64,
        slots=16769023,
        maxrejects=64,
        log_name="usearch_cluster_seqs.log",
        usersort=True,
        HALT_EXEC=False,
        save_intermediate_files=False,
        remove_usearch_logs=False,
        suppress_new_clusters=False,
        refseqs_fp=None,
        output_dir=None,
        working_dir=None,
        rev=False):
    if not output_filepath:
        _, output_filepath = mkstemp(prefix='usearch_cluster_ref_based',
                                     suffix='.uc')
    log_filepath = join(working_dir, log_name)
    uc_filepath = join(working_dir, "clustered_seqs_post_chimera.uc")
    params = {'--sizein': sizein,
              '--sizeout': sizeout,
              '--id': percent_id,
              '--w': w,
              '--slots': slots,
              '--maxrejects': maxrejects}
    app = Usearch(params, WorkingDir=working_dir, HALT_EXEC=HALT_EXEC)
    if usersort:
        app.Parameters['--usersort'].on()
    if rev:
        app.Parameters['--rev'].on()
    data = {'--query': fasta_filepath,
            '--uc': uc_filepath,
            '--db': refseqs_fp
            }
    if not remove_usearch_logs:
        data['--log'] = log_filepath
    app_result = app(data)
    files_to_remove = []
    if suppress_new_clusters:
        output_fna_filepath = join(output_dir, 'ref_clustered_seqs.fasta')
        output_filepath, labels_hits = get_fasta_from_uc_file(fasta_filepath,
                                                              uc_filepath, hit_type="H", output_dir=output_dir,
                                                              output_fna_filepath=output_fna_filepath)
        files_to_remove.append(uc_filepath)
    else:
        output_fna_clustered = join(output_dir, 'ref_clustered_seqs.fasta')
        output_filepath_ref_clusters,  labels_hits =\
            get_fasta_from_uc_file(fasta_filepath, uc_filepath, hit_type="H",
                                   output_dir=output_dir, output_fna_filepath=output_fna_clustered)
        output_fna_failures =\
            join(output_dir, 'ref_clustered_seqs_failures.fasta')
        output_filepath_failures, labels_hits =\
            get_fasta_from_uc_file(fasta_filepath,
                                   uc_filepath, hit_type="N", output_dir=output_dir,
                                   output_fna_filepath=output_fna_failures)
        app_result, output_filepath_clustered_failures =\
            usearch_cluster_seqs(output_fna_failures, output_filepath=
                                 join(
                                     output_dir,
                                     'clustered_seqs_reference_failures.fasta'),
                                 percent_id=percent_id, sizein=sizein, sizeout=sizeout, w=w,
                                 slots=slots, maxrejects=maxrejects,
                                 save_intermediate_files=save_intermediate_files,
                                 remove_usearch_logs=remove_usearch_logs, working_dir=working_dir)
        output_filepath = concatenate_fastas(output_fna_clustered,
                                             output_fna_failures, output_concat_filepath=join(
                                                 output_dir,
                                                 'concatenated_reference_denovo_clusters.fasta'))
        files_to_remove.append(output_fna_clustered)
        files_to_remove.append(output_fna_failures)
        files_to_remove.append(output_filepath_clustered_failures)
    if not save_intermediate_files:
        remove_files(files_to_remove)
    return app_result, output_filepath