-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap_function.py
More file actions
36 lines (30 loc) · 1.33 KB
/
bootstrap_function.py
File metadata and controls
36 lines (30 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import numpy as np
def perform_bootstrap(dataframe, cell_line):
df = dataframe
cell_line_df = df[df['cell_line'] == cell_line]
TRACK_MEAN_SPEED_df = cell_line_df[['TRACK_MEAN_SPEED', 'IMAGE_SERIES']]
cell_line_list = TRACK_MEAN_SPEED_df.IMAGE_SERIES.unique()
# perform loop to identify max length for all image series for this cell line
max_length = 0
for series in cell_line_list:
series = TRACK_MEAN_SPEED_df[TRACK_MEAN_SPEED_df['IMAGE_SERIES'] == series]
series_length = len(series)
if series_length > max_length:
max_length = series_length
else:
pass
print('max_length: ', max_length)
bootstrap_dict = {}
# next, use the max length to bootstrap values for any series with fewer values than the max length
for series in cell_line_list:
series_values = TRACK_MEAN_SPEED_df[TRACK_MEAN_SPEED_df['IMAGE_SERIES'] == series]['TRACK_MEAN_SPEED']
series_length = len(series_values)
if series_length < max_length:
x = np.random.choice(series_values, size=max_length, replace=True)
bootstrap_dict[series] = x
elif series_length == max_length:
bootstrap_dict[series] = series_values
else:
print('Series length error')
print(bootstrap_dict.keys())
return bootstrap_dict