Skip to content

Commit acb12c4

Browse files
committed
add tests and test data for SpectralMatrix class
1 parent a50e54b commit acb12c4

7 files changed

Lines changed: 115 additions & 3 deletions

File tree

12.5 KB
Binary file not shown.
512 Bytes
Binary file not shown.
4.2 MB
Binary file not shown.
4.2 MB
Binary file not shown.

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from tests.session_export_tests import SessionExportTestCase
1717
from tests.workspace_tests import WorkspaceTestCase
1818
from tests.gating_results_tests import GatingResultsTestCase
19-
from tests.matrix_tests import MatrixTestCase
19+
from tests.matrix_tests import MatrixTestCase, SpectralMatrixTestCase
2020
from tests.transform_tests import TransformsTestCase
2121
from tests.gate_tests import GateTestCase
2222
from tests.string_repr_tests import StringReprTestCase

tests/matrix_tests.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
detectors_8c,
1717
fluorochromes_8c,
1818
csv_8c_comp_null_channel_file_path,
19+
spectral_event_data,
20+
spectral_fluoro_indices,
21+
spectral_comp_matrix,
22+
spectral_all_detectors,
23+
spectral_true_detectors,
24+
spectral_sample,
25+
spectral_truth_comp_events
1926
)
2027

2128

@@ -109,3 +116,73 @@ def test_null_channels(self):
109116

110117
self.assertIsInstance(comp_events1, np.ndarray)
111118
self.assertIsInstance(comp_events2, np.ndarray)
119+
120+
class SpectralMatrixTestCase(unittest.TestCase):
121+
"""
122+
Tests related to the SpectralMatrix class
123+
"""
124+
def setUp(self):
125+
self.spectral_event_data = spectral_event_data
126+
self.spectral_fluoro_indices = spectral_fluoro_indices
127+
self.spectral_comp_matrix = spectral_comp_matrix
128+
self.spectral_all_detectors = spectral_all_detectors
129+
self.spectral_true_detectors = spectral_true_detectors
130+
131+
def test_spectral_matrix_create(self):
132+
spec_matrix = fk.SpectralMatrix(
133+
self.spectral_comp_matrix,
134+
detectors=self.spectral_all_detectors,
135+
true_detectors=self.spectral_true_detectors
136+
)
137+
self.assertIsInstance(spec_matrix, fk.SpectralMatrix)
138+
139+
def test_spectral_matrix_equal(self):
140+
spec_matrix = fk.SpectralMatrix(
141+
self.spectral_comp_matrix,
142+
detectors=self.spectral_all_detectors,
143+
true_detectors=self.spectral_true_detectors
144+
)
145+
spec_matrix2 = copy.deepcopy(spec_matrix)
146+
147+
self.assertEqual(spec_matrix, spec_matrix2)
148+
149+
def test_spectral_matrix_not_equal(self):
150+
spec_matrix = fk.SpectralMatrix(
151+
self.spectral_comp_matrix,
152+
detectors=self.spectral_all_detectors,
153+
true_detectors=self.spectral_true_detectors
154+
)
155+
spec_matrix2 = copy.deepcopy(spec_matrix)
156+
spec_matrix2.matrix += 0.00001
157+
158+
self.assertNotEqual(spec_matrix, spec_matrix2)
159+
160+
def test_spectral_matrix_as_dataframe(self):
161+
spec_matrix = fk.SpectralMatrix(
162+
self.spectral_comp_matrix,
163+
detectors=self.spectral_all_detectors,
164+
true_detectors=self.spectral_true_detectors
165+
)
166+
df_spec_matrix = spec_matrix.as_dataframe()
167+
168+
self.assertIsInstance(df_spec_matrix, pd.DataFrame)
169+
self.assertListEqual(list(df_spec_matrix.columns), spec_matrix.detectors)
170+
self.assertListEqual(list(df_spec_matrix.index), spec_matrix.true_detectors)
171+
172+
def test_spectral_matrix_apply(self):
173+
spec_matrix = fk.SpectralMatrix(
174+
self.spectral_comp_matrix,
175+
detectors=self.spectral_all_detectors,
176+
true_detectors=self.spectral_true_detectors
177+
)
178+
comp_events = spec_matrix.apply(spectral_sample)
179+
180+
# Compare only the fluoro channel events
181+
# The spectral Sample was created from a npy array and
182+
# went through the FlowIO conversion process so the events
183+
# are slightly different.
184+
np.testing.assert_array_almost_equal(
185+
spectral_truth_comp_events[:, spectral_sample.fluoro_indices],
186+
comp_events[:, spectral_sample.fluoro_indices],
187+
decimal=8
188+
)

tests/test_config.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Configuration of test data
33
"""
44
import numpy as np
5+
import os
56
import warnings
67
import flowkit as fk
78

@@ -13,10 +14,9 @@
1314
comp_file_path = "data/comp_complete_example.csv"
1415
fcs_2d_file_path = "data/test_data_2d_01.fcs"
1516
fcs_index_sorted_path = "data/index_sorted/index_sorted_example.fcs"
16-
sample_id_with_spill = "101_DEN084Y5_15_E01_008_clean.fcs"
1717
csv_8c_comp_file_path = "data/8_color_data_set/den_comp.csv"
1818
csv_8c_comp_null_channel_file_path = "data/8_color_data_set/den_comp_null_channel.csv"
19-
19+
spectral_data_dir = "data/spectral_data"
2020

2121
fcs_file_paths = ["data/100715.fcs", "data/109567.fcs", "data/113548.fcs"]
2222

@@ -28,6 +28,7 @@
2828
test_samples_base_set = fk.load_samples(fcs_file_paths)
2929
test_samples_8c_full_set = fk.load_samples("data/8_color_data_set/fcs_files")
3030
test_samples_8c_full_set_dict = {s.id: s for s in test_samples_8c_full_set}
31+
sample_id_with_spill = "101_DEN084Y5_15_E01_008_clean.fcs"
3132
sample_with_spill = test_samples_8c_full_set_dict[sample_id_with_spill]
3233

3334
with warnings.catch_warnings():
@@ -200,6 +201,40 @@
200201
spill01_data = np.array([[1, 0.02, 0.06], [0.11, 1, 0.07], [0.09, 0.01, 1]])
201202
comp_matrix_01 = fk.Matrix(spill01_data, spill01_detectors, spill01_fluoros)
202203

204+
#
205+
# Spectral Matrix
206+
#
207+
spectral_event_data = np.load(os.path.join(spectral_data_dir, "spectral_raw_events.npy"))
208+
spectral_fluoro_indices = np.load(os.path.join(spectral_data_dir, "spectral_fluoro_indices.npy"))
209+
spectral_all_detectors = [
210+
'B510-A', 'B537-A', 'B602-A', 'B660-A', 'B675-A', 'B710-A', 'B750-A', 'B810-A',
211+
'R675-A', 'R710-A', 'R780-A', 'UV379-A', 'UV446-A', 'UV515-A', 'UV585-A', 'UV610-A',
212+
'UV660-A', 'UV736-A', 'UV809-A', 'V427-A', 'V450-A', 'V510-A', 'V540-A', 'V576-A', 'V595-A',
213+
'V660-A', 'V710-A', 'V750-A', 'V785-A', 'YG585-A', 'YG602-A', 'YG730-A', 'YG780-A', 'B576-A',
214+
'R660-A', 'R680-A', 'R730-A', 'UV540-A', 'UV695-A', 'V470-A', 'V615-A', 'V680-A',
215+
'V845-A', 'YG660-A', 'YG670-A', 'YG695-A', 'YG750-A', 'YG825-A'
216+
]
217+
spectral_true_detectors = [
218+
'B510-A', 'B537-A', 'B602-A', 'B660-A', 'B675-A', 'B710-A', 'B750-A', 'B810-A',
219+
'R675-A', 'R710-A', 'R780-A', 'UV379-A', 'UV446-A', 'UV515-A', 'UV585-A', 'UV610-A',
220+
'UV660-A', 'UV736-A', 'UV809-A', 'V427-A', 'V450-A', 'V510-A', 'V540-A', 'V576-A', 'V595-A',
221+
'V660-A', 'V710-A', 'V750-A', 'V785-A', 'YG585-A', 'YG602-A', 'YG730-A', 'YG780-A'
222+
]
223+
spectral_sample_labels = [
224+
'Time', 'FSC-A', 'FSC-W', 'FSC-H','SSC-A', 'SSC-W', 'SSC-H',
225+
'UV379-A', 'UV446-A', 'UV515-A', 'UV540-A', 'UV585-A', 'UV610-A', 'UV660-A', 'UV695-A',
226+
'UV736-A', 'UV809-A', 'V427-A', 'V450-A', 'V470-A', 'V510-A', 'V540-A', 'V576-A',
227+
'V595-A', 'V615-A', 'V660-A', 'V680-A', 'V710-A', 'V750-A', 'V785-A', 'V845-A',
228+
'B510-A', 'B537-A', 'B576-A', 'B602-A', 'B660-A', 'B675-A', 'B710-A', 'B750-A',
229+
'B810-A', 'YG585-A', 'YG602-A', 'YG660-A', 'YG670-A', 'YG695-A', 'YG730-A', 'YG750-A',
230+
'YG780-A', 'YG825-A', 'R660-A', 'R675-A', 'R680-A', 'R710-A', 'R730-A', 'R780-A'
231+
]
232+
spectral_sample = fk.Sample(
233+
spectral_event_data, sample_id='spectral_sample.fcs', channel_labels=spectral_sample_labels
234+
)
235+
spectral_comp_matrix = np.load(os.path.join(spectral_data_dir, "spectral_comp_matrix.npy"))
236+
spectral_truth_comp_events = np.load(os.path.join(spectral_data_dir, "truth", "spectral_comp_events.npy"))
237+
203238
# pnn, pns lists
204239

205240
detectors_8c = [

0 commit comments

Comments
 (0)