Exemplo n.º 1
0
def stashfig(name, **kws):
    if SAVEFIGS:
        savefig(name,
                foldername=FNAME,
                fmt=DEFAULT_FMT,
                dpi=DEFUALT_DPI,
                **kws)
Exemplo n.º 2
0
    color_graphs,
    labels=graph_type_labels,
    outer_hier_labels=side_labels,
    inner_hier_labels=simple_class_labels,
    transform="simple-all",
    height=20,
    hier_label_fontsize=22,
    sort_nodes=False,
    sizes=(4, 20),
    palette=palette,
    title=r"All paired neurons",
    font_scale=2.2,
    title_pad=260,
    legend_name="Edge type",
)
savefig("color_graphs_pretty", pad_inches=1, bbox_inches="tight", fmt="png", dpi=200)

countplot(color_graphs, graph_type_labels)
savefig(
    "color_graphs_pretty_prop", bbox_inches="tight", pad_inches=0.5, fmt="png", dpi=200
)
#%% try just one induced subgraph
# Plot left to left
color_graphs_small = [c[:n_per_side, :n_per_side] for c in color_graphs]
sns.set_palette(palette, desat=0.7)
sns.set_context("talk", font_scale=1.2)
gridplot(
    color_graphs_small,
    labels=graph_type_labels,
    inner_hier_labels=simple_class_labels[:n_per_side],
    transform="simple-all",
class_ind_map = {}
class_ids_map = {}
for i, class_name in enumerate(unique_classes):
    inds = np.where(inverse_classes == i)[0]
    ids = cell_ids[inds]
    class_ind_map[class_name] = inds
    class_ids_map[class_name] = ids
class_ind_map

#%%
plt.figure(figsize=(10, 5))
sns.distplot(adj.sum(axis=0), norm_hist=False)
plt.xlabel("Proportion of input w/in current graph")
plt.ylabel("Frequency")
plt.tight_layout()
savefig("proportion_win_graph", fmt="png")

# degreeplot(adj)

#%%
# node = str(df_ids[class_ids_map["ORN mPNs"][0]])
# neighbor_graph = nx.ego_graph(graph, node)
# neighbor_names = meta_to_array(neighbor_graph, "Class")
# neighbor_nodes = list(neighbor_graph.nodes())
# labels = dict(zip(neighbor_nodes, neighbor_names))
# plt.figure(figsize=(20, 20))
# nx.draw_networkx(neighbor_graph, labels=labels)
# plt.show()


#%%
Exemplo n.º 4
0
# Plot the adjacency matrix for the summed graph
plt.figure(figsize=(5, 5))
ax = heatmap(
    sum_adj,
    inner_hier_labels=simple_class_labels,
    transform="simple-all",
    hier_label_fontsize=18,
    sort_nodes=False,
    cbar=False,
    title="Right Mushroom Body (summed 4 channels)",
    title_pad=90,
    font_scale=1.7,
)
annotate_arrow(ax, (0.135, 0.88))
savefig("flat_mb", fmt="png", dpi=150, bbox_inches="tight", pad_inches=0.5)

# Plot the adjacency matrix for the 4-color graphs
fig, ax = plt.subplots(2, 2, figsize=(20, 20))
ax = ax.ravel()
for i, g in enumerate(color_adjs):
    heatmap(
        g,
        inner_hier_labels=simple_class_labels,
        transform="simple-all",
        hier_label_fontsize=18,
        sort_nodes=False,
        ax=ax[i],
        cbar=False,
        title=GRAPH_TYPE_LABELS[i],
        title_pad=70,
Exemplo n.º 5
0
              pred_lhn_ids).mean())  # how many of the og lhn i got
print("Precision:")
print(np.isin(pred_lhn_ids,
              true_lhn_ids).mean())  # this is how many of mine are in og
print(len(pred_lhn_ids))

# update the predicted labels and class map
pred_classes = update_classes(classes, pred_lhn_ids, "LHN")

class_ids_map, class_ind_map = update_class_map(cell_ids, pred_classes)

# plot output
if plot:
    for t in pn_types:
        incidence_plot(adj, pred_classes, t)
        savefig("lhn_" + t)
#%% Estimate CN neurons
innate_input_types = ["ORN mPNs", "ORN uPNs", "tPNs", "vPNs", "LHN"]
innate_thresh = 5 * [0.05]

mb_input_types = ["MBON"]
mb_thresh = [0.05]

pred_innate_ids = proportional_search(adj,
                                      class_ind_map,
                                      innate_input_types,
                                      cell_ids,
                                      thresh=innate_thresh)
pred_learn_ids = proportional_search(adj,
                                     class_ind_map,
                                     mb_input_types,
result_df["Left ID"] = left_nodes
result_df["Right ID"] = right_nodes
result_df["Flat Distance"] = norm_diff_summed
result_df["4color Distance"] = norm_diff_colors
result_df["Flat Rank"] = rank_summed
result_df["4color Rank"] = rank_colors
result_df["Reciprocal Rank Diff"] = reciprocal_diff
result_df["Rank Diff"] = rank_diff

plt.figure(figsize=(10, 10))
sns.set_context("talk", font_scale=1)
sns.scatterplot(data=result_df,
                x="Flat Distance",
                y="4color Distance",
                alpha=0.8)
savefig("color_distance_comparison", fmt="png", dpi=200)
plt.figure(figsize=(10, 10))

sns.scatterplot(
    data=result_df,
    x="Flat Distance",
    y="4color Distance",
    # hue="Reciprocal Rank Diff",
    alpha=0.8,
    palette="gist_heat_r",
    size="Reciprocal Rank Diff",
    sizes=(10, 1000),
)
savefig("color_distance_comparison_heat", fmt="png", dpi=200)

plt.figure(figsize=(10, 10))
Exemplo n.º 7
0
    [embed_graph],
    inner_hier_labels=hier1_labels,
    title="whole graph sorted by hierclust, n_clust=6",
    **gridplot_kws,
)

###########
#%% focus on subgraph id 2
subvert_inds = np.where(hier1_labels == 2)[0]
subgraph = embed_graph[np.ix_(subvert_inds, subvert_inds)]
subgraph = get_lcc(subgraph)

subgraph_latent = normalized_ase(subgraph, n_components=4)
dists = pairwise_distances(subgraph_latent, metric="cosine")
hierplot(dists, figsize=(20, 20))
savefig("hier2_dissim_heat", fmt="png")
#%% cluster a subgraph
hierclust = AgglomerativeClustering(
    affinity="precomputed", compute_full_tree=True, n_clusters=7, linkage="average"
)
hier2_labels = hierclust.fit_predict(dists)
gridplot([subgraph], inner_hier_labels=hier2_labels, **gridplot_kws)


#%% embed a subgraph
plt.style.use("seaborn-white")
l = normalized_ase(lcc_graph_t, n_components=6)
dists = pairwise_distances(l, metric="cosine")
c = AgglomerativeClustering(n_clusters=7, affinity="precomputed", linkage="average")
labels = c.fit_predict(dists)
np.unique(labels, return_counts=True)
Exemplo n.º 8
0
with timer(prefix='plot oof-test-distributions '):
    for c, ax in zip(oofs.columns, axes):
        sns.histplot(
            data=pd.DataFrame({
                'OOF': oofs[c],
                'Test': preds[c]
            }),
            ax=ax,
            stat='density',
            common_norm=False,
        )
        ax.set_facecolor('white')
        ax.set_title(category_id2code[c])
        ax.grid()
    fig.tight_layout()
    savefig(fig, to='out-of-fold_vs_test')

# %%

nfigs = len(oofs.columns)
ncols = 5
nrows = -(-nfigs // ncols)
fig, axes = plt.subplots(figsize=(5 * ncols, 3 * nrows),
                         ncols=ncols,
                         nrows=nrows,
                         sharex=True)
axes = np.ravel(axes)

with timer(prefix='plot oof-test-distributions '):
    for c, ax in zip(oofs.columns, axes):
        sns.histplot(
    print(graph_type)

    edgelist_path = data_path / data_date / (graph_type + ".csv")
    adj = pd.read_csv(edgelist_path, index_col=0)

    print((adj.index.values == meta_data_df.index.values).all())

    graph = df_to_nx(adj, meta_data_dict)

    nx_graphs_raw[graph_type] = graph
    df_graphs_raw[graph_type] = adj

    name = graph_type + "_raw_PTR"
    heatmap(adj.values, title=name, **heatmap_kws)
    if save_figures:
        savefig(name, fmt="png", dpi=300)

    print()

#%% Normalize weights for the raw graphs
df_graphs_norm = {}
nx_graphs_norm = {}

input_counts = input_counts_df["axon_inputs"].values
input_counts[input_counts == 0] = 1
for graph_type in ["axon-axon", "dendrite-axon"]:
    print(graph_type)
    df_adj_raw = df_graphs_raw[graph_type]
    if (input_counts_df.index.values == adj.index.values).all():
        print("Same indexing!")
    adj_raw = df_adj_raw.values
Exemplo n.º 10
0
    # uni_labels = np.unique(pred_labels)
    sankey(ax[1], class_labels, pred_labels)
    ax[1].axis("off")

    rand_perm = np.random.permutation(len(pred_labels))

    heatmap(
        binarize(adj),
        inner_hier_labels=pred_labels[rand_perm],
        # outer_hier_labels=side_labels,
        hier_label_fontsize=18,
        ax=ax[2],
        cbar=False,
        sort_nodes=True,
    )
    sankey(ax[3], class_labels, pred_labels[rand_perm])
    ax[3].axis("off")
    print(k)
    if k == 6:
        print(k)
        savefig("sankey6", fmt="png", dpi=200)

# %%

fig, ax = plt.subplots(1, 1, figsize=(20, 20))
sns.set_context("talk", font_scale=2)
sankey(ax, class_labels, pred_labels, aspect=20, fontsize=24)
ax.axis("off")

# %%