-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_haystack.py
More file actions
68 lines (47 loc) · 1.91 KB
/
run_haystack.py
File metadata and controls
68 lines (47 loc) · 1.91 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import sys
from haystack import Haystack, load_config, parse
def run():
# parse command line arguments for stack/directory path, and whether previous rois are used
PATH, ROIS_EXIST = parse_args()
# load_config if using yaml file
config = load_config()
# initialize haystacl class
hs = Haystack(PATH)
# choose the desired colormap for detected cells
hs.choose_colormap(config['clustering']['colormap'])
# choose detection or roi load
if ROIS_EXIST:
# if cellpose has already been run, we can reload the rois directly
hs.load_rois_directly()
else:
# if not then run cellpose on the stack
hs.detect_cells(model_path=config['cellpose']['model_path'],
cellprob_threshold=config['cellpose']['cellprob_threshold'],
channels=[config['cellpose']['channels']])
# run clustering algorithm
hs.cluster_cells(min_samples=config['clustering']['min_samples'],
max_clustering_distance=config['clustering']['max_clustering_distance'])
# show all processes
hs.show_stack()
hs.show_detections_stack()
hs.show_detections_stack(on_frames=True)
hs.show_cumulative_stack()
hs.show_clustering()
hs.show_clustered_cells()
# save all processes and clustered cell coordinates
hs.save_all_processing_images()
hs.save_cells_as_coords()
def parse_args():
if len(sys.argv) == 1:
raise KeyError("No directory specififed")
elif len(sys.argv) == 2:
path = parse.path(sys.argv[1])
rois_exist = False
elif len(sys.argv) == 3:
path = parse.path(sys.argv[1])
rois_exist = parse.rois_exist(sys.argv[2])
else:
raise KeyError("Too many input arguments")
return path, rois_exist
if __name__ == "__main__":
run()