Skip to content

Commit 9728951

Browse files
Update vesicle diameter analysis
1 parent 59a38db commit 9728951

File tree

2 files changed

+38
-154
lines changed

2 files changed

+38
-154
lines changed

scripts/inner_ear/analysis/analyze_vesicle_diameters.py

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
sys.path.append("../processing")
1616

1717

18-
def aggregate_radii(data_root, table, save_path, get_tab, include_names):
19-
if os.path.exists(save_path):
20-
return
21-
18+
def aggregate_diameters(data_root, table, save_path, get_tab, include_names, sheet_name):
2219
radius_table = []
2320
for _, row in tqdm(table.iterrows(), total=len(table), desc="Collect tomo information"):
2421
folder = row["Local Path"]
@@ -41,17 +38,20 @@ def aggregate_radii(data_root, table, save_path, get_tab, include_names):
4138
tab = pd.read_excel(tab_path)
4239
this_tab = tab[["pool", "radius [nm]"]]
4340
this_tab.insert(0, "tomogram", [tomo_name] * len(this_tab))
41+
this_tab.insert(3, "diameter [nm]", this_tab["radius [nm]"] * 2)
4442
radius_table.append(this_tab)
4543

4644
radius_table = pd.concat(radius_table)
47-
print("Saving table for", len(radius_table), "vesicles to", save_path)
48-
radius_table.to_excel(save_path, index=False)
49-
5045

51-
def aggregate_radii_imod(data_root, table, save_path, include_names):
46+
print("Saving table for", len(radius_table), "vesicles to", save_path, sheet_name)
5247
if os.path.exists(save_path):
53-
return
48+
with pd.ExcelWriter(save_path, engine="openpyxl", mode="a") as writer:
49+
radius_table.to_excel(writer, sheet_name=sheet_name, index=False)
50+
else:
51+
radius_table.to_excel(save_path, sheet_name=sheet_name, index=False)
5452

53+
54+
def aggregate_diameters_imod(data_root, table, save_path, include_names, sheet_name):
5555
radius_table = []
5656
for _, row in tqdm(table.iterrows(), total=len(table), desc="Collect tomo information"):
5757
folder = row["Local Path"]
@@ -95,12 +95,16 @@ def aggregate_radii_imod(data_root, table, save_path, include_names):
9595
"tomogram": [tomo_name] * len(radii),
9696
"pool": [label_names[label_id] for label_id in labels],
9797
"radius [nm]": radii,
98+
"diameter [nm]": 2 * radii,
9899
})
99100
radius_table.append(this_tab)
100101

101102
radius_table = pd.concat(radius_table)
102-
print("Saving table for", len(radius_table), "vesicles to", save_path)
103-
radius_table.to_excel(save_path, index=False)
103+
print("Saving table for", len(radius_table), "vesicles to", save_path, sheet_name)
104+
radius_table.to_excel(save_path, index=False, sheet_name=sheet_name)
105+
106+
man_tomos = pd.unique(radius_table.tomogram)
107+
return man_tomos
104108

105109

106110
def get_tab_semi_automatic(folder):
@@ -141,20 +145,32 @@ def main():
141145
table = parse_table(table_path, data_root)
142146

143147
all_tomos = get_finished_tomos()
144-
aggregate_radii(
145-
data_root, table, save_path="./results/vesicle_radii_semi_automatic.xlsx", get_tab=get_tab_semi_automatic,
146-
include_names=all_tomos
147-
)
148148

149-
aggregate_radii(
150-
data_root, table, save_path="./results/vesicle_radii_proofread.xlsx", get_tab=get_tab_proofread,
151-
include_names=all_tomos
149+
print("All tomograms")
150+
save_path = "./results/vesicle_diameters_all_tomos.xlsx"
151+
aggregate_diameters(
152+
data_root, table, save_path=save_path, get_tab=get_tab_semi_automatic, include_names=all_tomos,
153+
sheet_name="Semi-automatic",
154+
)
155+
aggregate_diameters(
156+
data_root, table, save_path=save_path, get_tab=get_tab_proofread, include_names=all_tomos,
157+
sheet_name="Proofread",
152158
)
153159

154-
# aggregate_radii(data_root, table, save_path="./results/vesicle_radii_manual.xlsx", get_tab=get_tab_manual)
155-
aggregate_radii_imod(
156-
data_root, table, save_path="./results/vesicle_radii_manual.xlsx",
157-
include_names=all_tomos
160+
print()
161+
print("Tomograms with manual annotations")
162+
# aggregate_diameters(data_root, table, save_path="./results/vesicle_radii_manual.xlsx", get_tab=get_tab_manual)
163+
save_path = "./results/vesicle_diameters_tomos_with_manual_annotations.xlsx"
164+
man_tomos = aggregate_diameters_imod(
165+
data_root, table, save_path=save_path, include_names=all_tomos, sheet_name="Manual",
166+
)
167+
aggregate_diameters(
168+
data_root, table, save_path=save_path, get_tab=get_tab_semi_automatic, include_names=man_tomos,
169+
sheet_name="Semi-automatic",
170+
)
171+
aggregate_diameters(
172+
data_root, table, save_path=save_path, get_tab=get_tab_proofread, include_names=man_tomos,
173+
sheet_name="Proofread",
158174
)
159175

160176

scripts/inner_ear/analysis/analyze_vesicle_radii.py

Lines changed: 0 additions & 132 deletions
This file was deleted.

0 commit comments

Comments
 (0)