15
15
sys .path .append ("../processing" )
16
16
17
17
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 ):
22
19
radius_table = []
23
20
for _ , row in tqdm (table .iterrows (), total = len (table ), desc = "Collect tomo information" ):
24
21
folder = row ["Local Path" ]
@@ -41,17 +38,20 @@ def aggregate_radii(data_root, table, save_path, get_tab, include_names):
41
38
tab = pd .read_excel (tab_path )
42
39
this_tab = tab [["pool" , "radius [nm]" ]]
43
40
this_tab .insert (0 , "tomogram" , [tomo_name ] * len (this_tab ))
41
+ this_tab .insert (3 , "diameter [nm]" , this_tab ["radius [nm]" ] * 2 )
44
42
radius_table .append (this_tab )
45
43
46
44
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
-
50
45
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 )
52
47
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 )
54
52
53
+
54
+ def aggregate_diameters_imod (data_root , table , save_path , include_names , sheet_name ):
55
55
radius_table = []
56
56
for _ , row in tqdm (table .iterrows (), total = len (table ), desc = "Collect tomo information" ):
57
57
folder = row ["Local Path" ]
@@ -95,12 +95,16 @@ def aggregate_radii_imod(data_root, table, save_path, include_names):
95
95
"tomogram" : [tomo_name ] * len (radii ),
96
96
"pool" : [label_names [label_id ] for label_id in labels ],
97
97
"radius [nm]" : radii ,
98
+ "diameter [nm]" : 2 * radii ,
98
99
})
99
100
radius_table .append (this_tab )
100
101
101
102
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
104
108
105
109
106
110
def get_tab_semi_automatic (folder ):
@@ -141,20 +145,32 @@ def main():
141
145
table = parse_table (table_path , data_root )
142
146
143
147
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
- )
148
148
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" ,
152
158
)
153
159
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" ,
158
174
)
159
175
160
176
0 commit comments