Commit ·
39c52ef
1
Parent(s): 29565fb
rename data struct to easily distnguish merfish and transcriptomic dataset
Browse files
app.py
CHANGED
|
@@ -16,29 +16,9 @@ import hvplot.pandas
|
|
| 16 |
|
| 17 |
pn.extension(design="bootstrap", sizing_mode="stretch_width", throttled=True)
|
| 18 |
|
| 19 |
-
genes_families = {
|
| 20 |
-
'Htr1': ['Htr1a', 'Htr1b', 'Htr1d', 'Htr1f'],
|
| 21 |
-
'Htr2': ['Htr2a', 'Htr2b', 'Htr2c'],
|
| 22 |
-
'Htr3': ['Htr3a', 'Htr3b'],
|
| 23 |
-
'Htr4': ['Htr4'],
|
| 24 |
-
'Htr5': ['Htr5a', 'Htr5b'],
|
| 25 |
-
'Htr6': ['Htr6'],
|
| 26 |
-
'Htr7': ['Htr7']
|
| 27 |
-
}
|
| 28 |
-
base_colors = sns.color_palette("husl", n_colors=len(genes_families))
|
| 29 |
-
genes_cmap = {}
|
| 30 |
-
|
| 31 |
order_division = ['Isocortex', 'OLF', 'HPF', 'CTXsp', 'STR', 'PAL', 'TH', 'HY', 'MB',
|
| 32 |
'P', 'MY', 'CB',]
|
| 33 |
|
| 34 |
-
for idx, (family, members) in enumerate(genes_families.items()):
|
| 35 |
-
shades = sns.light_palette(base_colors[idx], n_colors=len(members) + 1)[1:]
|
| 36 |
-
for receptor, shade in zip(members, shades):
|
| 37 |
-
genes_cmap[receptor] = shade
|
| 38 |
-
|
| 39 |
-
# Convert RGB to HEX
|
| 40 |
-
|
| 41 |
-
genes_cmap_rgb = {k: plt_colors.rgb2hex(v) for k, v in genes_cmap.items()}
|
| 42 |
|
| 43 |
threshold_expression = 3.5 # for RNAseq
|
| 44 |
threshold_expression_MERFISH = .5
|
|
@@ -56,9 +36,9 @@ def percentage_above_threshold_MER(series):
|
|
| 56 |
datasets = ['Zhuang-ABCA-1','Zhuang-ABCA-2','Zhuang-ABCA-3','Zhuang-ABCA-4']
|
| 57 |
|
| 58 |
with open("./Data/sub_cell_expression.pickle", "rb") as f:
|
| 59 |
-
|
| 60 |
|
| 61 |
-
|
| 62 |
|
| 63 |
joined_sub = pd.read_csv("./Data/joined_sub.csv")
|
| 64 |
|
|
@@ -83,21 +63,21 @@ classification_cmap.update(joined_sub.drop_duplicates(subset='class').set_index(
|
|
| 83 |
class MERFISH_viz(param.Parameterized):
|
| 84 |
dataset_selector = param.Selector(objects=datasets)
|
| 85 |
brain_section_index = param.Integer(default=0, bounds=(
|
| 86 |
-
0,
|
| 87 |
gene_selector = param.ObjectSelector(default=selected_genes[0], objects=selected_genes.tolist())
|
| 88 |
-
class_selector = param.ListSelector(default=sorted(
|
| 89 |
-
objects=sorted(
|
| 90 |
-
subclass_selector = param.ListSelector(default=sorted(
|
| 91 |
-
objects=sorted(
|
| 92 |
section_updated = param.Event()
|
| 93 |
filtered_data_updated = param.Event()
|
| 94 |
dataset_updated = param.Event()
|
| 95 |
|
| 96 |
# Naming the keyword arguments `**params` is purely a convention.
|
| 97 |
-
def __init__(self,
|
| 98 |
super().__init__(**params)
|
| 99 |
-
self.
|
| 100 |
-
self.current_data = self.
|
| 101 |
self.filtered_data = self.current_data[
|
| 102 |
self.current_data['class'].isin(sel_class) & self.current_data['subclass'].isin(sel_subclass)]
|
| 103 |
|
|
@@ -204,7 +184,7 @@ class MERFISH_viz(param.Parameterized):
|
|
| 204 |
|
| 205 |
@pn.depends("dataset_selector", watch=True)
|
| 206 |
def update_current_data(self):
|
| 207 |
-
self.current_data = self.
|
| 208 |
self.brain_section_index = 0
|
| 209 |
self.param.brain_section_index.bounds = (0, self.current_data["brain_section_label"].unique().shape[0])
|
| 210 |
self.dataset_updated = True
|
|
@@ -225,8 +205,8 @@ class MERFISH_viz(param.Parameterized):
|
|
| 225 |
self.current_data[(self.current_data['class'].isin(self.class_selector))]['subclass'].unique())
|
| 226 |
|
| 227 |
|
| 228 |
-
viz = MERFISH_viz(
|
| 229 |
-
|
| 230 |
|
| 231 |
# Title of the paper and authors
|
| 232 |
# Custom HTML for the title
|
|
@@ -385,7 +365,7 @@ gene_selector = pn.widgets.Select(name='Gene', options=list(selected_genes_cl),
|
|
| 385 |
@pn.depends(group_selector, gene_selector)
|
| 386 |
def interactive_plot(group, gene):
|
| 387 |
global global_saved_fig, group_g, gene_g
|
| 388 |
-
data =
|
| 389 |
data = data.groupby(["cluster_group_name", "class", "subclass", "supertype", "cluster"])[gene].apply(
|
| 390 |
percentage_above_threshold).reset_index()
|
| 391 |
data = data[data["cluster_group_name"] != "WholeBrain"]
|
|
@@ -410,7 +390,6 @@ def interactive_plot(group, gene):
|
|
| 410 |
|
| 411 |
fig.suptitle(group, y=1.04, fontweight='bold', fontsize=20);
|
| 412 |
|
| 413 |
-
|
| 414 |
return fig
|
| 415 |
|
| 416 |
dashboard_cluster_centric = pn.Column(
|
|
|
|
| 16 |
|
| 17 |
pn.extension(design="bootstrap", sizing_mode="stretch_width", throttled=True)
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
order_division = ['Isocortex', 'OLF', 'HPF', 'CTXsp', 'STR', 'PAL', 'TH', 'HY', 'MB',
|
| 20 |
'P', 'MY', 'CB',]
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
threshold_expression = 3.5 # for RNAseq
|
| 24 |
threshold_expression_MERFISH = .5
|
|
|
|
| 36 |
datasets = ['Zhuang-ABCA-1','Zhuang-ABCA-2','Zhuang-ABCA-3','Zhuang-ABCA-4']
|
| 37 |
|
| 38 |
with open("./Data/sub_cell_expression.pickle", "rb") as f:
|
| 39 |
+
merfish_data = pickle.load(f)
|
| 40 |
|
| 41 |
+
transcriptomic_data_sub = pd.read_csv("./Data/joined_with_membership_sub.csv")
|
| 42 |
|
| 43 |
joined_sub = pd.read_csv("./Data/joined_sub.csv")
|
| 44 |
|
|
|
|
| 63 |
class MERFISH_viz(param.Parameterized):
|
| 64 |
dataset_selector = param.Selector(objects=datasets)
|
| 65 |
brain_section_index = param.Integer(default=0, bounds=(
|
| 66 |
+
0, merfish_data[datasets[0]]["brain_section_label"].unique().shape[0]))
|
| 67 |
gene_selector = param.ObjectSelector(default=selected_genes[0], objects=selected_genes.tolist())
|
| 68 |
+
class_selector = param.ListSelector(default=sorted(merfish_data[dataset]['class'].unique()),
|
| 69 |
+
objects=sorted(merfish_data[dataset]['class'].unique()))
|
| 70 |
+
subclass_selector = param.ListSelector(default=sorted(merfish_data[dataset]['subclass'].unique()),
|
| 71 |
+
objects=sorted(merfish_data[dataset]['subclass'].unique()))
|
| 72 |
section_updated = param.Event()
|
| 73 |
filtered_data_updated = param.Event()
|
| 74 |
dataset_updated = param.Event()
|
| 75 |
|
| 76 |
# Naming the keyword arguments `**params` is purely a convention.
|
| 77 |
+
def __init__(self, merfish_data, sel_dataset, sel_class, sel_subclass, brain_section_index, **params):
|
| 78 |
super().__init__(**params)
|
| 79 |
+
self.merfish_data = merfish_data
|
| 80 |
+
self.current_data = self.merfish_data[sel_dataset]
|
| 81 |
self.filtered_data = self.current_data[
|
| 82 |
self.current_data['class'].isin(sel_class) & self.current_data['subclass'].isin(sel_subclass)]
|
| 83 |
|
|
|
|
| 184 |
|
| 185 |
@pn.depends("dataset_selector", watch=True)
|
| 186 |
def update_current_data(self):
|
| 187 |
+
self.current_data = self.merfish_data[self.dataset_selector]
|
| 188 |
self.brain_section_index = 0
|
| 189 |
self.param.brain_section_index.bounds = (0, self.current_data["brain_section_label"].unique().shape[0])
|
| 190 |
self.dataset_updated = True
|
|
|
|
| 205 |
self.current_data[(self.current_data['class'].isin(self.class_selector))]['subclass'].unique())
|
| 206 |
|
| 207 |
|
| 208 |
+
viz = MERFISH_viz(merfish_data, datasets[0], merfish_data[datasets[0]]["class"].unique(),
|
| 209 |
+
merfish_data[dataset]["subclass"].unique(), 0)
|
| 210 |
|
| 211 |
# Title of the paper and authors
|
| 212 |
# Custom HTML for the title
|
|
|
|
| 365 |
@pn.depends(group_selector, gene_selector)
|
| 366 |
def interactive_plot(group, gene):
|
| 367 |
global global_saved_fig, group_g, gene_g
|
| 368 |
+
data = transcriptomic_data_sub[transcriptomic_data_sub["cluster_group_name"] == group]
|
| 369 |
data = data.groupby(["cluster_group_name", "class", "subclass", "supertype", "cluster"])[gene].apply(
|
| 370 |
percentage_above_threshold).reset_index()
|
| 371 |
data = data[data["cluster_group_name"] != "WholeBrain"]
|
|
|
|
| 390 |
|
| 391 |
fig.suptitle(group, y=1.04, fontweight='bold', fontsize=20);
|
| 392 |
|
|
|
|
| 393 |
return fig
|
| 394 |
|
| 395 |
dashboard_cluster_centric = pn.Column(
|