Spaces:
Running
Running
foz
commited on
Commit
•
29f7eb3
1
Parent(s):
6756e43
Integration tests for whole pipeline
Browse files- tests/test_results.py +150 -0
tests/test_results.py
ADDED
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import pytest
|
3 |
+
from path_analysis.analyse import *
|
4 |
+
from path_analysis.data_preprocess import RemovedPeakData
|
5 |
+
import numpy as np
|
6 |
+
from math import pi
|
7 |
+
import xml.etree.ElementTree as ET
|
8 |
+
from PIL import ImageChops
|
9 |
+
|
10 |
+
from pathlib import Path
|
11 |
+
|
12 |
+
import matplotlib
|
13 |
+
matplotlib.use('Agg')
|
14 |
+
|
15 |
+
@pytest.fixture(scope="module")
|
16 |
+
def script_loc(request):
|
17 |
+
'''Return the directory of the currently running test script'''
|
18 |
+
|
19 |
+
return Path(request.fspath).parent
|
20 |
+
|
21 |
+
def test_image_1(script_loc):
|
22 |
+
|
23 |
+
config = { 'sphere_radius': 0.1984125,
|
24 |
+
'peak_threshold': 0.4,
|
25 |
+
'xy_res': 0.0396825,
|
26 |
+
'z_res': 0.0909184,
|
27 |
+
'threshold_type': 'per-cell',
|
28 |
+
'use_corrected_positions': True,
|
29 |
+
'screening_distance': 10,
|
30 |
+
}
|
31 |
+
|
32 |
+
data_loc = script_loc.parent.parent / 'test_data' / 'hei10 ++ 15.11.19 p22s2 image 9'
|
33 |
+
|
34 |
+
|
35 |
+
image_input = data_loc / 'HEI10.tif'
|
36 |
+
path_input = data_loc / 'SNT_Data.traces'
|
37 |
+
|
38 |
+
paths, traces, fig, extracted_peaks = analyse_paths('Cell', image_input, path_input, config)
|
39 |
+
|
40 |
+
assert np.allclose(extracted_peaks['SNT_trace_length(um)'], [61.47, 70.40, 51.93, 43.94, 62.24], atol=1e-2 )
|
41 |
+
assert np.allclose(extracted_peaks['SNT_trace_length(um)'], extracted_peaks['Measured_trace_length(um)'], atol=1e-8 )
|
42 |
+
assert list(extracted_peaks['Trace_foci_number']) == [2,3,2,2,3]
|
43 |
+
|
44 |
+
def test_image_2(script_loc):
|
45 |
+
|
46 |
+
config = { 'sphere_radius': 0.1984125,
|
47 |
+
'peak_threshold': 0.4,
|
48 |
+
'xy_res': 0.0396825,
|
49 |
+
'z_res': 0.0909184,
|
50 |
+
'threshold_type': 'per-cell',
|
51 |
+
'use_corrected_positions': True,
|
52 |
+
'screening_distance': 10,
|
53 |
+
}
|
54 |
+
|
55 |
+
data_loc = script_loc.parent.parent / 'test_data' / 'z-optimised'
|
56 |
+
|
57 |
+
|
58 |
+
image_input = data_loc / 'HEI10.tif'
|
59 |
+
path_input = data_loc / 'ZYP1.traces'
|
60 |
+
|
61 |
+
paths, traces, fig, extracted_peaks = analyse_paths('Cell', image_input, path_input, config)
|
62 |
+
|
63 |
+
assert np.allclose(extracted_peaks['SNT_trace_length(um)'], extracted_peaks['Measured_trace_length(um)'], atol=1e-8 )
|
64 |
+
assert list(extracted_peaks['Trace_foci_number']) == [2,2,1,2,1]
|
65 |
+
|
66 |
+
def test_image_3(script_loc):
|
67 |
+
|
68 |
+
config = { 'sphere_radius': 0.1984125,
|
69 |
+
'peak_threshold': 0.4,
|
70 |
+
'xy_res': 0.0396825,
|
71 |
+
'z_res': 0.1095510,
|
72 |
+
'threshold_type': 'per-trace',
|
73 |
+
'use_corrected_positions': True,
|
74 |
+
'screening_distance': 10,
|
75 |
+
|
76 |
+
}
|
77 |
+
|
78 |
+
data_loc = script_loc.parent.parent / 'test_data' / 'arenosa SN A1243 image 18-20230726T142725Z-001' / 'arenosa SN A1243 image 18'
|
79 |
+
|
80 |
+
|
81 |
+
image_input = data_loc / 'HEI10.tif'
|
82 |
+
path_input = data_loc / 'SNT_Data.traces'
|
83 |
+
|
84 |
+
paths, traces, fig, extracted_peaks = analyse_paths('Cell', image_input, path_input, config)
|
85 |
+
|
86 |
+
assert np.allclose(extracted_peaks['SNT_trace_length(um)'], extracted_peaks['Measured_trace_length(um)'], atol=1e-8 )
|
87 |
+
assert list(extracted_peaks['Trace_foci_number']) == [2,1,1,1,2,1,1,1]
|
88 |
+
|
89 |
+
def test_image_4(script_loc):
|
90 |
+
|
91 |
+
config = { 'sphere_radius': 10.,
|
92 |
+
'peak_threshold': 0.4,
|
93 |
+
'xy_res': 1,
|
94 |
+
'z_res': 1,
|
95 |
+
'threshold_type': 'per-trace',
|
96 |
+
'use_corrected_positions': True,
|
97 |
+
'screening_distance': 10,
|
98 |
+
|
99 |
+
}
|
100 |
+
|
101 |
+
data_loc = script_loc.parent.parent / 'test_data' / 'mammalian 2D-20230821T180708Z-001' / 'mammalian 2D' / '1'
|
102 |
+
|
103 |
+
|
104 |
+
image_input = data_loc / 'C2-Pachytene SIM-1.tif'
|
105 |
+
path_input = data_loc / 'SNT_Data.traces'
|
106 |
+
|
107 |
+
paths, traces, fig, extracted_peaks = analyse_paths('Cell', image_input, path_input, config)
|
108 |
+
|
109 |
+
assert np.allclose(extracted_peaks['SNT_trace_length(um)'], extracted_peaks['Measured_trace_length(um)'], atol=1e-8 )
|
110 |
+
|
111 |
+
valid_results = [{1}, {1}, {2, 3}, {1, 2}, {1, 2}, {1}, {1}, {2}, {1}, {1}, {1, 2}, {1}, {1, 2}, {1, 2}, {1}, {1}, {1}, {1}, {1}]
|
112 |
+
measured = extracted_peaks['Trace_foci_number']
|
113 |
+
|
114 |
+
print(measured)
|
115 |
+
assert len(measured) == len(valid_results)
|
116 |
+
assert(all(m in v for m,v in zip(measured, valid_results)))
|
117 |
+
|
118 |
+
|
119 |
+
|
120 |
+
def test_image_5(script_loc):
|
121 |
+
|
122 |
+
config = { 'sphere_radius': 0.3,
|
123 |
+
'peak_threshold': 0.4,
|
124 |
+
'xy_res': 0.1023810,
|
125 |
+
'z_res': 1,
|
126 |
+
'threshold_type': 'per-trace',
|
127 |
+
'use_corrected_positions': True,
|
128 |
+
'screening_distance': 10,
|
129 |
+
|
130 |
+
}
|
131 |
+
|
132 |
+
data_loc = script_loc.parent.parent / 'test_data' / 'mammalian 2D-20230821T180708Z-001' / 'mammalian 2D' / '2'
|
133 |
+
|
134 |
+
|
135 |
+
image_input = data_loc / 'C1-CNTD1FHFH CSHA 1in5000 22612 Slide 6-102-1.tif'
|
136 |
+
path_input = data_loc / 'SNT_Data.traces'
|
137 |
+
|
138 |
+
paths, traces, fig, extracted_peaks = analyse_paths('Cell', image_input, path_input, config)
|
139 |
+
|
140 |
+
assert np.allclose(extracted_peaks['SNT_trace_length(um)'], extracted_peaks['Measured_trace_length(um)'], atol=1e-8 )
|
141 |
+
|
142 |
+
valid_results = [1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 2, 1, 2, 1, 1]
|
143 |
+
measured = extracted_peaks['Trace_foci_number']
|
144 |
+
|
145 |
+
assert list(measured) == valid_results
|
146 |
+
|
147 |
+
|
148 |
+
|
149 |
+
|
150 |
+
|