Ejemplo n.º 1
0
def _hist(res, save_path):
    ## distribution
    def histogram(real, label, bin, range, ax):
        density, bins = np.histogram(real, bins=bin, density=True, range=range)
        unity_density = density / density.sum()
        widths = bins[:-1] - bins[1:]
        ax.bar(bins[1:], unity_density, width=widths, alpha=.5, label=label)

    for mouse in np.unique(res['mouse']):
        pt_csp = filter.filter(res, {'mouse': mouse, 'odor_valence': 'PT CS+'})
        csp = filter.filter(res, {'mouse': mouse})
        csm = filter.filter(res, {'mouse': mouse})

        data = pt_csp['velocity']
        start = pt_csp['on'][0]
        end = pt_csp['end'][0]
        data_before = data[:, :start].flatten()
        data_during = data[:, start:end].flatten()
        data_after = data[:, end:].flatten()

        bins = 50
        range = [-70, 70]
        fig = plt.figure(figsize=(2, 1.5))
        ax = fig.add_axes([0.2, 0.2, 0.7, 0.7])
        histogram(data_before, 'before', bin=bins, range=range, ax=ax)
        histogram(data_during, 'during', bin=bins, range=range, ax=ax)
        plt.xlim([range[0] - 0.5, range[1] + .5])
        ax.spines["right"].set_visible(False)
        ax.spines["top"].set_visible(False)
        ax.xaxis.set_ticks_position('bottom')
        ax.yaxis.set_ticks_position('left')
        rs = ranksums(data_before, data_during)[-1]
        xlim = plt.xlim()
        ylim = plt.ylim()
        x = xlim[0] + .7 * (xlim[1] - xlim[0])
        y = ylim[0] + .7 * (ylim[1] - ylim[0])
        plot.significance_str(x, y, rs)
        name = 'before_during_mouse_{}'.format(mouse)
        plot._easy_save(save_path, name=name)

        fig = plt.figure(figsize=(2, 1.5))
        ax = fig.add_axes([0.2, 0.2, 0.7, 0.7])
        histogram(data_during, 'before', bin=bins, range=range, ax=ax)
        histogram(data_after, 'during', bin=bins, range=range, ax=ax)
        plt.xlim([range[0] - 0.5, range[1] + .5])
        ax.spines["right"].set_visible(False)
        ax.spines["top"].set_visible(False)
        ax.xaxis.set_ticks_position('bottom')
        ax.yaxis.set_ticks_position('left')
        rs = ranksums(data_during, data_after)[-1]
        xlim = plt.xlim()
        ylim = plt.ylim()
        x = xlim[0] + .7 * (xlim[1] - xlim[0])
        y = ylim[0] + .7 * (ylim[1] - ylim[0])
        plot.significance_str(x, y, rs)
        name = 'during_after_mouse_{}'.format(mouse)
        plot._easy_save(save_path, name=name)
Ejemplo n.º 2
0
def distribution_dff(res,
                     start_days,
                     end_days,
                     arg,
                     valence,
                     figure_path,
                     hist_range=(-.05, 1.2)):
    list_of_days = list(zip(start_days, end_days))
    res = filter.filter_days_per_mouse(res, days_per_mouse=list_of_days)
    res = filter.filter(res, {'odor_valence': valence})
    new = _compare_dff(res, loop_keys=['mouse', 'odor'], arg=arg)

    #
    def _helper(real, label, bin=20):
        density, bins = np.histogram(real,
                                     bins=bin,
                                     density=True,
                                     range=hist_range)
        unity_density = density / density.sum()
        widths = bins[:-1] - bins[1:]
        ax.bar(bins[1:], unity_density, width=widths, alpha=.5, label=label)

    fig = plt.figure(figsize=(2, 1.5))
    ax = fig.add_axes([0.2, 0.2, 0.7, 0.7])

    x = np.concatenate(new['day_0'])
    y = np.concatenate(new['day_1'])
    sr = wilcoxon(x, y)[-1]
    _helper(x, 'Before')
    _helper(y, 'After')

    ax.set_xlabel('Amplitude')
    ax.set_ylabel('Density')
    ax.spines["right"].set_visible(False)
    ax.spines["top"].set_visible(False)
    ax.xaxis.set_ticks_position('bottom')
    ax.yaxis.set_ticks_position('left')
    plt.legend(frameon=False)
    ylim = plt.ylim()
    xlim = plt.xlim()
    sig_str = plot.significance_str(x=(xlim[-1] - ylim[0]) * .7,
                                    y=.7 * (ylim[-1] - ylim[0]),
                                    val=sr)
    _easy_save(os.path.join(figure_path, 'dff_distribution'),
               valence,
               dpi=300,
               pdf=True)

    print('Before mean: {}'.format(np.mean(x)))
    print('After mean: {}'.format(np.mean(y)))
    print('wilcoxon: {}'.format(sr))
Ejemplo n.º 3
0
                      select_dict={'phase_odor_valence': phase},
                      ax_args=ax_args_cur,
                      plot_function=plt.errorbar,
                      plot_args=error_args,
                      fig_size=[2, 1.5],
                      path=save_path, reuse=True, save=False)

        plt.xlim(-1, 2)

        test = filter.filter(res_, {'phase_odor_valence': phase})
        ixs = test['condition'] == 'Y'
        x = test[keyword][ixs]
        y = test[keyword][np.invert(ixs)]
        ylim = plt.gca().get_ylim()
        rs = ranksums(x, y)
        sig_str = plot.significance_str(x=.4, y= .7 * (ylim[-1] - ylim[0]), val= rs[-1])
        plot._easy_save(path, name, pdf=True)

        print('Phase: {}'.format(phase))
        print('YFP: {}'.format(np.mean(x)))
        print('YFP: {}'.format(x))
        print('HALO: {}'.format(np.mean(y)))
        print('HALO: {}'.format(y))

        print(rs)

    print(summary_res[keyword])
    print(summary_res['odor_valence_condition'])
    print(summary_res['phase_odor_valence'])

if 'trials_per_day' in plotting:
                                       rect=(.3, .3, .6, .6),
                                       plot_function=plt.scatter,
                                       plot_args=scatter_args_copy,
                                       ax_args=ax_args_local,
                                       colors=color,
                                       save=False,
                                       path=save_path)
        plt.plot([0, 5], [0, 5], '--', color='gray')

        try:
            stat_res = filter.filter(res_use, {'odor_valence': valence})
            a, b = stat_res[before_key], stat_res[after_key]
            stat = wilcoxon(a, b)
            ylim = plt.gca().get_ylim()
            sig_str = plot.significance_str(x=.4,
                                            y=.7 * (ylim[-1] - ylim[0]),
                                            val=stat[-1])
            plot._easy_save(path, name)
            print('Before: {}, After: {}'.format(np.mean(a), np.mean(b)))
            print(stat)
        except:
            print('no stats')

if 'summary_mouse_line' in experiments:
    _collapse_conditions(all_res, control_condition='YFP', str=collapse_arg)
    ykey = reduce_key_raw + '_mean'
    for i, v in enumerate(all_res[reduce_key_raw]):
        all_res[ykey].append(np.mean(v[v > 0]))
    all_res[ykey] = np.array(all_res[ykey])

    res_modified = reduce.new_filter_reduce(