def create_orthology_matrix(r_name, genome_to_bbh_files, pid_cutoff=None, bitscore_cutoff=None, evalue_cutoff=None,
                            outname='', outdir='', force_rerun=False):
    """Create an orthology matrix using best bidirectional BLAST hits (BBH) outputs.

    Args:
        r_name (str): Name of the reference genome
        genome_to_bbh_files (dict): Mapping of genome names to the BBH csv output from the
            :func:`~ssbio.protein.sequence.utils.blast.calculate_bbh` method
        pid_cutoff (float): Minimum percent identity between BLAST hits to filter for in the range [0, 100]
        bitscore_cutoff (float): Minimum bitscore allowed between BLAST hits
        evalue_cutoff (float): Maximum E-value allowed between BLAST hits
        outname: Name of output file of orthology matrix
        outdir: Path to output directory
        force_rerun (bool): Force recreation of the orthology matrix even if the outfile exists

    Returns:
        str: Path to orthologous genes matrix.

    """
    if outname:
        outfile = op.join(outdir, outname)
    else:
        outfile = op.join(outdir, '{}_orthology.csv'.format(r_name))

    if op.exists(outfile) and os.stat(outfile).st_size != 0 and not force_rerun:
        log.info('{}: loaded existing orthology matrix'.format(outfile))
        return outfile

    if not pid_cutoff and not bitscore_cutoff and not evalue_cutoff:
        log.warning('No cutoffs supplied, insignificant hits may be reported')

    if not pid_cutoff:
        pid_cutoff = 0
    if not bitscore_cutoff:
        bitscore_cutoff = 0
    if not evalue_cutoff:
        evalue_cutoff = float('Inf')

    out = pd.DataFrame()
    for g_name, bbh_path in genome_to_bbh_files.items():

        df_bbh = pd.read_csv(bbh_path, index_col=0)
        bidirectional = df_bbh[df_bbh.BBH == '<=>']

        data = bidirectional[(bidirectional.PID > pid_cutoff) & (bidirectional.eVal < evalue_cutoff) & (bidirectional.bitScore > bitscore_cutoff)]

        data.index = data.gene
        data2 = data[['subject']]
        if out.empty:
            out = data2
            out = out.rename(columns={'subject': g_name})
        else:
            out = pd.merge(out, data2, left_index=True, right_index=True, how='outer')
            out = out.rename(columns={'subject': g_name})

    out.to_csv(outfile)
    log.debug('{} orthologous genes saved at {}'.format(r_name, outfile))
    return outfile
Create an orthology matrix using best bidirectional BLAST hits (BBH) outputs.

    Args:
        r_name (str): Name of the reference genome
        genome_to_bbh_files (dict): Mapping of genome names to the BBH csv output from the
            :func:`~ssbio.protein.sequence.utils.blast.calculate_bbh` method
        pid_cutoff (float): Minimum percent identity between BLAST hits to filter for in the range [0, 100]
        bitscore_cutoff (float): Minimum bitscore allowed between BLAST hits
        evalue_cutoff (float): Maximum E-value allowed between BLAST hits
        outname: Name of output file of orthology matrix
        outdir: Path to output directory
        force_rerun (bool): Force recreation of the orthology matrix even if the outfile exists

    Returns:
        str: Path to orthologous genes matrix.