Ejemplo n.º 1
0
    ax.set_xlabel("Time [s]")
    ax.set_ylabel("Activation [AU]")
    ax.set_xticks([0, 30, 60, 90, 120, 150])
    sns.despine(fig, ax)
    fig.savefig(save_folder + "ce_step_responses.pdf", type="pdf")
    fig, ax = pl.subplots()
    ax.plot(trial_time, temp_step, 'k')
    ax.set_xlabel("Time [s]")
    ax.set_ylabel("Temperature [C]")
    ax.set_xticks([0, 30, 60, 90, 120, 150])
    sns.despine(fig, ax)
    fig.savefig(save_folder + "step_stimulus.pdf", type="pdf")

    # Panel 8: PCA space comparison of zfish and c elegans gradient responses
    all_cells = np.hstack(
        (a.trial_average(all_cells_zf, 3), a.trial_average(all_cells_ce, 3))).T
    max_vals = np.max(all_cells, 1, keepdims=True)
    max_vals[max_vals == 0] = 1  # these cells do not show any response
    all_cells /= max_vals
    species_id = np.zeros(all_cells.shape[0])
    species_id[all_cells_zf.shape[1]:] = 1
    pca = PCA(4)
    pca.fit(all_cells)
    coords = pca.transform(all_cells)
    for i in range(pca.n_components):
        plot_pc(i, coords, species_id, pca.explained_variance_, "zf_ce")

    # Panel 10: Full distribution of example type removals in C.elegans
    pal = sns.color_palette()  # the default matplotlib color cycle
    plot_cols_ce = {
        0: (0.6, 0.6, 0.6),
Ejemplo n.º 2
0
    kernel = 2 ** (-kframes / tau_off) * (1 - 2 ** (-kframes / tau_on))
    kernel = kernel / kernel.sum()
    # convolve with our kernel
    for i in range(all_cells_zf.shape[1]):
        all_cells_zf[:, i] = convolve(all_cells_zf[:, i], kernel, mode='full')[:all_cells_zf.shape[0]]

    # plot colors
    pal = sns.color_palette()  # the default matplotlib color cycle
    plot_cols_zf = {0: (0.6, 0.6, 0.6), 1: pal[2], 2: (102 / 255, 45 / 255, 145 / 255), 3: pal[0], 4: pal[3], 5: pal[1],
                    6: pal[5], 7: (76 / 255, 153 / 255, 153 / 255), -1: (0.6, 0.6, 0.6)}

    # panel - all cluster activities, sorted into ON and OFF types
    n_regs = np.unique(clust_ids_zf).size - 1
    cluster_acts = np.zeros((all_cells_zf.shape[0] // 3, n_regs))
    for i in range(n_regs):
        cluster_acts[:, i] = np.mean(a.trial_average(all_cells_zf[:, clust_ids_zf == i], 3), 1)
    on_count = 0
    off_count = 0
    fig, (axes_on, axes_off) = pl.subplots(ncols=2, nrows=2, sharey=True, sharex=True)
    time = np.arange(cluster_acts.shape[0]) / GlobalDefs.frame_rate
    for i in range(n_regs):
        act = cluster_acts[:, i]
        if np.corrcoef(act, temperature[:act.size])[0, 1] < 0:
            ax_off = axes_off[0] if off_count < 2 else axes_off[1]
            ax_off.plot(time, cluster_acts[:, i], color=plot_cols_zf[i])
            off_count += 1
        else:
            ax_on = axes_on[0] if on_count < 2 else axes_on[1]
            ax_on.plot(time, cluster_acts[:, i], color=plot_cols_zf[i])
            on_count += 1
    axes_off[0].set_xticks([0, 30, 60, 90, 120, 150])
Ejemplo n.º 3
0
    def norm(trace):
        n = trace - trace.min()
        return n / n.max()

    ccm_copy = clust_corr_mat.copy()
    for i in range(np.max(ccm_copy.shape)):
        ix = np.argmax(ccm_copy)
        rw, cl = np.unravel_index(ix, ccm_copy.shape)
        ccm_copy[rw, :] = 0
        ccm_copy[:, cl] = 0
        fig, ax = pl.subplots()
        ax.plot(trial_time,
                norm(
                    np.mean(
                        a.trial_average(all_cells_zf[:, clust_ids_zf == rw],
                                        3), 1)),
                color='k')
        ax.plot(trial_time,
                norm(
                    np.mean(
                        a.trial_average(all_cells_ce[:, clust_ids_ce == cl],
                                        3), 1)),
                color='C1')
        ax.set_ylabel("Normalized activation")
        ax.set_xlabel("Time [s]")
        ax.set_title("Zf {0} vs Ce {1}. R^2 = {2}".format(
            rw, cl, np.round(clust_corr_mat[rw, cl], 2)))
        ax.set_xticks([0, 30, 60, 90, 120, 150])
        sns.despine(fig, ax)
        fig.savefig(save_folder +
                    "ZFish_C{0}_vs_CElegans_C{1}.pdf".format(rw, cl),
    tau_off *= GlobalDefs.frame_rate  # in frames
    kframes = np.arange(10 * GlobalDefs.frame_rate)  # 10 s long kernel
    kernel = 2 ** (-kframes / tau_off) * (1 - 2 ** (-kframes / tau_on))
    kernel = kernel / kernel.sum()
    # convolve with our kernel
    for i in range(all_cells.shape[1]):
        all_cells[:, i] = convolve(all_cells[:, i], kernel, mode='full')[:all_cells.shape[0]]

    # load activity clusters from file or create if necessary
    clust_ids = a.cluster_activity(8, all_cells, "cluster_info.hdf5")[0]

    # create ANN cluster centroid matrix
    ann_cluster_centroids = np.zeros((all_cells.shape[0]//3, 8))
    for i in range(8):
        centroid = np.mean(all_cells[:, clust_ids == i], 1)
        ann_cluster_centroids[:, i] = a.trial_average(centroid[:, None], 3).ravel()

    # interpolate fish calcium data to network time base
    ca_time = np.linspace(0, 165, rh_56_calcium.shape[0])
    net_time = np.linspace(0, 165, ann_cluster_centroids.shape[0])
    zf_cluster_centroids = np.zeros((net_time.size, rh_56_calcium.shape[1]))
    for i in range(rh_56_calcium.shape[1]):
        zf_cluster_centroids[:, i] = np.interp(net_time, ca_time, rh_56_calcium[:, i])

    # perform all pairwise correlations between the network and zebrafish units during sine stimulus phase
    cm_sine = create_corr_mat(ann_cluster_centroids, zf_cluster_centroids, net_time, 60, 105)
    assignment = greedy_max_clust(cm_sine, 0.6, reg_names)
    assign_labels = [assignment[k] for k in range(cm_sine.shape[0])]

    # plot correlation matrix
    fig, ax = pl.subplots()
Ejemplo n.º 5
0
    # convolve activity with nuclear gcamp calcium kernel
    tau_on = 1.4  # seconds
    tau_on *= GlobalDefs.frame_rate  # in frames
    tau_off = 2  # seconds
    tau_off *= GlobalDefs.frame_rate  # in frames
    kframes = np.arange(10 * GlobalDefs.frame_rate)  # 10 s long kernel
    kernel = 2**(-kframes / tau_off) * (1 - 2**(-kframes / tau_on))
    kernel = kernel / kernel.sum()
    # convolve with our kernel
    for i in range(all_cells.shape[1]):
        all_cells[:, i] = convolve(all_cells[:, i], kernel,
                                   mode='full')[:all_cells.shape[0]]

    # load activity clusters from file or create if necessary
    clust_ids = a.cluster_activity(8, all_cells, "cluster_info.hdf5")[0]
    f_on_data = a.trial_average(all_cells[:, clust_ids == fast_on_like], 3).T
    s_on_data = a.trial_average(all_cells[:, clust_ids == slow_on_like], 3).T
    f_off_data = a.trial_average(all_cells[:, clust_ids == fast_off_like], 3).T
    s_off_data = a.trial_average(all_cells[:, clust_ids == slow_off_like], 3).T
    trial_time = np.arange(f_on_data.shape[1]) / GlobalDefs.frame_rate

    # second panel - fish-like on types
    fig, ax = pl.subplots()
    sns.tsplot(f_on_data, trial_time, n_boot=1000, color="C3")
    sns.tsplot(s_on_data, trial_time, n_boot=1000, color="C1")
    ax.set_xlabel("Time [s]")
    ax.set_ylabel("Activation [AU]")
    ax.set_xticks([0, 30, 60, 90, 120, 150])
    sns.despine(fig, ax)
    fig.savefig(save_folder + "fishlike_on_types.pdf", type="pdf")
Ejemplo n.º 6
0
    # cluster data
    clust_ids_rl = a.cluster_activity(8, all_cells_rl, None)[0]

    # plot
    pal = sns.color_palette()  # the default matplotlib color cycle
    plot_cols_rl = {0: pal[0], 1: pal[1], 2: pal[2], 3: pal[3], 4: pal[4], 5: pal[5],
                    6: pal[6], 7: pal[7], -1: (0.6, 0.6, 0.6)}
    n_regs_rl = np.unique(clust_ids_rl).size - 1
    cluster_acts_rl = np.zeros((all_cells_rl.shape[0] // 3, n_regs_rl))
    is_on = np.zeros(n_regs_rl, dtype=bool)
    ax_ix = np.full(n_regs_rl, -1, dtype=int)
    on_count = 0
    off_count = 0
    for i in range(n_regs_rl):
        act = np.mean(a.trial_average(all_cells_rl[:, clust_ids_rl == i], 3), 1)
        cluster_acts_rl[:, i] = act
        is_on[i] = np.corrcoef(act, temperature[:act.size])[0, 1] > 0
        # correspondin axis on ON plot is simply set by order of cluster occurence
        if is_on[i]:
            ax_ix[i] = 0 if on_count < 2 else 1
            on_count += 1
        else:
            ax_ix[i] = 0 if off_count < 2 else 1
            off_count += 1

    fig, (axes_on, axes_off) = pl.subplots(ncols=2, nrows=2, sharex=True)
    time = np.arange(cluster_acts_rl.shape[0]) / GlobalDefs.frame_rate
    for i in range(n_regs_rl):
        act = cluster_acts_rl[:, i].copy()
        if not is_on[i]:
Ejemplo n.º 7
0
        4: pal[4],
        5: pal[5],
        6: pal[6],
        7: pal[7],
        -1: (0.6, 0.6, 0.6)
    }

    # panel - all cluster activities, sorted into ON and anti-correlated OFF types
    n_regs_th = np.unique(clust_ids_th).size - 1
    n_regs_zf = np.unique(clust_ids_zf).size - 1
    cluster_acts_th = np.zeros((all_cells_th.shape[0] // 3, n_regs_th))
    is_on = np.zeros(n_regs_th, dtype=bool)
    ax_ix = np.full(n_regs_th, -1, dtype=int)
    on_count = 0
    for i in range(n_regs_th):
        act = np.mean(a.trial_average(all_cells_th[:, clust_ids_th == i], 3),
                      1)
        cluster_acts_th[:, i] = act
        is_on[i] = np.corrcoef(act, temperature[:act.size])[0, 1] > 0
        # correspondin axis on ON plot is simply set by order of cluster occurence
        if is_on[i]:
            ax_ix[i] = 0 if on_count < 2 else 1
            on_count += 1
    # for off types, put them on the corresponding off axis of the most anti-correlated ON type
    type_corrs_th = np.corrcoef(cluster_acts_th.T)
    for i in range(n_regs_th):
        if not is_on[i]:
            corresponding_on = np.argmin(type_corrs_th[i, :])
            assert is_on[corresponding_on]
            ax_ix[i] = ax_ix[corresponding_on]
    fig, (axes_on, axes_off) = pl.subplots(ncols=2,