# Path: merfishtools/estimates.py
# def plot_estimate(ylim, map_value=None, credible_interval=None, legend=True):
#     if credible_interval is not None:
#         ci_lower, ci_upper = credible_interval
#         plt.fill([ci_lower, ci_upper, ci_upper, ci_lower], [0, 0, ylim[1], ylim[1]], "red", lw=0, label="95% credible interval", alpha=0.5)
#     if map_value is not None:
#         plt.vlines([map_value], *ylim, colors="red", linestyles="-", label="MAP")
#     if legend:
#         plt.legend(loc="best")
#     plt.ylim(ylim)


import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from merfishtools.estimates import plot_estimate



def read_cdf(path_or_buffer):
    cdf = pd.read_table(path_or_buffer)
    # set all but the last two values as index
    cdf.set_index(list(cdf.columns[:-2]), inplace=True)
    cdf.sort_index(inplace=True, kind="mergesort")
    return cdf


def plot_cdf(cdf, map_value=None, credible_interval=None, legend=True):
    probs = np.exp(cdf.iloc[:, 1])
    plt.step(cdf.iloc[:, 0], probs, "k-", label="", clip_on=False, zorder=2)
    ylim = plt.ylim()

# Path: merfishtools/estimates.py
# def plot_estimate(ylim, map_value=None, credible_interval=None, legend=True):
#     if credible_interval is not None:
#         ci_lower, ci_upper = credible_interval
#         plt.fill([ci_lower, ci_upper, ci_upper, ci_lower], [0, 0, ylim[1], ylim[1]], "red", lw=0, label="95% credible interval", alpha=0.5)
#     if map_value is not None:
#         plt.vlines([map_value], *ylim, colors="red", linestyles="-", label="MAP")
#     if legend:
#         plt.legend(loc="best")
#     plt.ylim(ylim)


# Path: merfishtools/cdf.py
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from merfishtools.estimates import plot_estimate




def read_cdf(path_or_buffer):
    cdf = pd.read_table(path_or_buffer)
    # set all but the last two values as index
    cdf.set_index(list(cdf.columns[:-2]), inplace=True)
    cdf.sort_index(inplace=True, kind="mergesort")
    return cdf


def plot_cdf(cdf, map_value=None, credible_interval=None, legend=True):
    probs = np.exp(cdf.iloc[:, 1])
    plt.step(cdf.iloc[:, 0], probs, "k-", label="", clip_on=False, zorder=2)
    ylim = plt.ylim()

    plot_estimate(ylim, map_value, credible_interval, legend=legend)