<commit_before>
from __future__ import absolute_import, division

import os
import re

import pandas as pd

import pyproteome as pyp


def _prep_csv(data=None, postfix="table", folder_name=None, csv_name=None):
    if csv_name is None:
        csv_name = "{}.csv".format(
            postfix,
        )

    folder_name = pyp.utils.make_folder(
        data=data,
        folder_name=folder_name,
        sub="Tables",
    )

    return os.path.join(folder_name, csv_name)


def _get_table_title(f=None, running_title=None):
    if running_title is None:
        running_title = []

    if f is not None:
        if 'asym_fold' in f:
            running_title.append(
                "Upregulated" if f["asym_fold"] > 1 else "Downregulated"
            )

        if "p" in f:
            running_title.append(
                "p-{:.3e}".format(f["p"])
            )

        if "group_a" in f or "group_b" in f:
            running_title.append(
                "{}vs{}".format(
                    f.get("group_a", ""),
                    f.get("group_b", ""),
                )
            )

    return "-".join(running_title)


def motif_table(
    data, f,
    p=0.05,
    sort="p-value",
    folder_name=None,
    csv_name=None,
    **kwargs
):
    """
    Run a motif enrichment algorithm on a data set and display the
    significantly enriched motifs.

    Parameters
    ----------
    data : :class:`DataSet<pyproteome.data_sets.DataSet>`
    f : dict or list of dict
    p : float, optional
    sort : str, optional
    folder_name : str, optional
    csv_name : str, optional

    Returns
    -------
    :class:`pandas.DataFrame`

    See Also
    --------
    :func:`run_motif_enrichment<pyproteome.motifs.motif.run_motif_enrichment>`<commit_msg>Link function<commit_after>
from __future__ import absolute_import, division

import os
import re

import pandas as pd

import pyproteome as pyp


def _prep_csv(data=None, postfix="table", folder_name=None, csv_name=None):
    if csv_name is None:
        csv_name = "{}.csv".format(
            postfix,
        )

    folder_name = pyp.utils.make_folder(
        data=data,
        folder_name=folder_name,
        sub="Tables",
    )

    return os.path.join(folder_name, csv_name)


def _get_table_title(f=None, running_title=None):
    if running_title is None:
        running_title = []

    if f is not None:
        if 'asym_fold' in f:
            running_title.append(
                "Upregulated" if f["asym_fold"] > 1 else "Downregulated"
            )

        if "p" in f:
            running_title.append(
                "p-{:.3e}".format(f["p"])
            )

        if "group_a" in f or "group_b" in f:
            running_title.append(
                "{}vs{}".format(
                    f.get("group_a", ""),
                    f.get("group_b", ""),
                )
            )

    return "-".join(running_title)


def motif_table(
    data, f,
    p=0.05,
    sort="p-value",
    folder_name=None,
    csv_name=None,
    **kwargs
):
    """
    Run a motif enrichment algorithm on a data set and display the
    significantly enriched motifs.

    Parameters
    ----------
    data : :class:`DataSet<pyproteome.data_sets.DataSet>`
    f : dict or list of dict
    p : float, optional
    sort : str, optional
    folder_name : str, optional
    csv_name : str, optional

    Returns
    -------
    :class:`pandas.DataFrame`

    See Also
    --------
    :func:`pyproteome.motifs.motif.run_motif_enrichment`
{'fraction_non_alphanumeric': 0.1204337899543379, 'fraction_numerical': 0.0028538812785388126, 'mean_word_length': 1.896694214876033, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6485891', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1108, 'n_words': 264}