def generate_shortlist(mnx_db, shortlist):
    """
    Create a condensed cross-references format from data in long form.

    Both data frames must contain a column 'MNX_ID' and the dump is assumed
    to also have a column 'XREF'.

    Parameters
    ----------
    mnx_db : pandas.DataFrame
        The entire MetaNetX dump as a data frame.
    shortlist : pandas.DataFrame
        The shortlist of targets as a data frame.

    Returns
    -------
    pandas.DataFrame
        A condensed format with MetaNetX identifiers as the column index and
        database identifiers as the row index. Elements are lists and often
        have multiple entries.

    """
    # Reduce the whole database to targets of interest.
    xref = mnx_db.loc[mnx_db["MNX_ID"].isin(shortlist["MNX_ID"]), :]
    # Drop deprecated MetaNetX identifiers. Disabled for now.
    # xref = xref.loc[~xref["XREF"].str.startswith("deprecated", na=False), :]
    # Drop self-references for now since they don't follow the format.
    xref = xref.loc[xref["XREF"] != xref["MNX_ID"], :]
    # Split namespaces from identifiers.
    xref[["XREF_ID", "XREF"]] = xref["XREF"].str.split(":", n=1, expand=True)
    # Group the data in the xref dataframe so that one MNX ID maps to all
    # corresponding cross-references from other databases. Then list all
    # identifiers that belong to these databases:
    # MNX_ID    XREF_ID
    # MNXM0     chebi       [23367, 59999]
    #           metacyc     [UNKNOWN]
    # Make a separate column for every XREF_ID:
    # MNX_ID    chebi           metacyc
    # MNXM0     [23367, 59999]  [UNKNOWN]
    xref = xref.groupby(["MNX_ID", "XREF_ID"], as_index=False, sort=False)[
        "XREF"].apply(list).unstack('XREF_ID')
    # Re-insert MetaNetX identifiers as lists.
    # FIXME: Shouldn't we use metanetx.chemical here instead of 'mnx'?
    xref["mnx"] = [[x] for x in xref.index]
    # Transpose the data frame such that the index are now xref databases and
    # the column names are MetaNetX identifiers.
    return xref.T
Create a condensed cross-references format from data in long form.

    Both data frames must contain a column 'MNX_ID' and the dump is assumed
    to also have a column 'XREF'.

    Parameters
    ----------
    mnx_db : pandas.DataFrame
        The entire MetaNetX dump as a data frame.
    shortlist : pandas.DataFrame
        The shortlist of targets as a data frame.

    Returns
    -------
    pandas.DataFrame
        A condensed format with MetaNetX identifiers as the column index and
        database identifiers as the row index. Elements are lists and often
        have multiple entries.