@@ -35,7 +35,7 @@ def _plot_all(distances):
35
35
# TODO rename the method names.
36
36
# We only care about the following distances:
37
37
# - MP-V -> PD, AZ (Boundary)
38
- # - Docked-V -> PD
38
+ # - Docked-V -> PD, AZ
39
39
# - RA-V -> Ribbon
40
40
def _plot_selected (distances , save_path = None ):
41
41
fig , axes = plt .subplots (2 , 2 )
@@ -46,7 +46,7 @@ def _plot_selected(distances, save_path=None):
46
46
47
47
def _plot (pool_name , distance_col , structure_name , ax ):
48
48
49
- this_distances = distances [distances ["pool" ] == pool_name ][["approach" , distance_col ]]
49
+ this_distances = distances [distances ["pool" ] == pool_name ][["tomogram" , " approach" , distance_col ]]
50
50
51
51
ax .set_title (f"{ pool_name } to { structure_name } " )
52
52
sns .histplot (
@@ -56,15 +56,27 @@ def _plot(pool_name, distance_col, structure_name, ax):
56
56
57
57
if save_path is not None :
58
58
approaches = pd .unique (this_distances ["approach" ])
59
- dist_values = [
60
- this_distances [this_distances ["approach" ] == approach ][distance_col ].values .tolist ()
61
- for approach in approaches
62
- ]
63
- max_len = max ([len (vals ) for vals in dist_values ])
64
- save_distances = {
65
- approach : dists + [np .nan ] * (max_len - len (dists ))
66
- for approach , dists in zip (approaches , dist_values )
67
- }
59
+ tomo_names = pd .unique (this_distances ["tomogram" ])
60
+
61
+ tomograms = []
62
+ distance_values = {approach : [] for approach in approaches }
63
+
64
+ for tomo in tomo_names :
65
+ tomo_dists = this_distances [this_distances ["tomogram" ] == tomo ]
66
+ max_vesicles = 0
67
+ for approach in approaches :
68
+ n_vesicles = len (tomo_dists [tomo_dists ["approach" ] == approach ].values )
69
+ if n_vesicles > max_vesicles :
70
+ max_vesicles = n_vesicles
71
+
72
+ for approach in approaches :
73
+ app_dists = tomo_dists [tomo_dists ["approach" ] == approach ][distance_col ].values .tolist ()
74
+ app_dists = app_dists + [np .nan ] * (max_vesicles - len (app_dists ))
75
+ distance_values [approach ].extend (app_dists )
76
+ tomograms .extend ([tomo ] * max_vesicles )
77
+
78
+ save_distances = {"tomograms" : tomograms }
79
+ save_distances .update (distance_values )
68
80
save_distances = pd .DataFrame (save_distances )
69
81
70
82
sheet_name = f"{ pool_name } _{ structure_name } "
@@ -74,9 +86,11 @@ def _plot(pool_name, distance_col, structure_name, ax):
74
86
else :
75
87
save_distances .to_excel (save_path , index = False , sheet_name = sheet_name )
76
88
89
+ # NOTE: we over-ride a plot here, should not do this in the actual version
77
90
_plot ("MP-V" , "pd_distance [nm]" , "PD" , axes [0 , 0 ])
78
91
_plot ("MP-V" , "boundary_distance [nm]" , "AZ Membrane" , axes [0 , 1 ])
79
92
_plot ("Docked-V" , "pd_distance [nm]" , "PD" , axes [1 , 0 ])
93
+ _plot ("Docked-V" , "boundary_distance [nm]" , "AZ Membrane" , axes [1 , 0 ])
80
94
_plot ("RA-V" , "ribbon_distance [nm]" , "Ribbon" , axes [1 , 1 ])
81
95
82
96
fig .tight_layout ()
@@ -87,17 +101,17 @@ def for_tomos_with_annotation(plot_all=True):
87
101
manual_assignments , semi_automatic_assignments , automatic_assignments = get_measurements_with_annotation ()
88
102
89
103
manual_distances = manual_assignments [
90
- ["pool" , "ribbon_distance [nm]" , "pd_distance [nm]" , "boundary_distance [nm]" ]
104
+ ["tomogram" , " pool" , "ribbon_distance [nm]" , "pd_distance [nm]" , "boundary_distance [nm]" ]
91
105
]
92
106
manual_distances ["approach" ] = ["manual" ] * len (manual_distances )
93
107
94
108
semi_automatic_distances = semi_automatic_assignments [
95
- ["pool" , "ribbon_distance [nm]" , "pd_distance [nm]" , "boundary_distance [nm]" ]
109
+ ["tomogram" , " pool" , "ribbon_distance [nm]" , "pd_distance [nm]" , "boundary_distance [nm]" ]
96
110
]
97
111
semi_automatic_distances ["approach" ] = ["semi_automatic" ] * len (semi_automatic_distances )
98
112
99
113
automatic_distances = automatic_assignments [
100
- ["pool" , "ribbon_distance [nm]" , "pd_distance [nm]" , "boundary_distance [nm]" ]
114
+ ["tomogram" , " pool" , "ribbon_distance [nm]" , "pd_distance [nm]" , "boundary_distance [nm]" ]
101
115
]
102
116
automatic_distances ["approach" ] = ["automatic" ] * len (automatic_distances )
103
117
@@ -113,12 +127,12 @@ def for_all_tomos(plot_all=True):
113
127
semi_automatic_assignments , automatic_assignments = get_all_measurements ()
114
128
115
129
semi_automatic_distances = semi_automatic_assignments [
116
- ["pool" , "ribbon_distance [nm]" , "pd_distance [nm]" , "boundary_distance [nm]" ]
130
+ ["tomogram" , " pool" , "ribbon_distance [nm]" , "pd_distance [nm]" , "boundary_distance [nm]" ]
117
131
]
118
132
semi_automatic_distances ["approach" ] = ["semi_automatic" ] * len (semi_automatic_distances )
119
133
120
134
automatic_distances = automatic_assignments [
121
- ["pool" , "ribbon_distance [nm]" , "pd_distance [nm]" , "boundary_distance [nm]" ]
135
+ ["tomogram" , " pool" , "ribbon_distance [nm]" , "pd_distance [nm]" , "boundary_distance [nm]" ]
122
136
]
123
137
automatic_distances ["approach" ] = ["automatic" ] * len (automatic_distances )
124
138
0 commit comments