Skip to content

Commit 6d729b7

Browse files
authored
Merge pull request #18 from primitybio/zb/other-pnx
Support parametrized optional FCS keywords
2 parents 282669c + 69dd36b commit 6d729b7

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

flowio/create_fcs.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,17 @@ def _build_text(
6464
# skip it, these are allowed to be set by the user
6565
continue
6666

67-
# Check for channel parameter keywords like:
67+
# Check for channel parameter keywords that are handled in create_fcs:
6868
# Pn(B, E, G, R, N, S)
6969
pnx_match = re.match(r'^(p)(\d+)([begrns])$', key)
7070
if pnx_match is not None:
7171
# regardless of the channel parameter type, we'll skip it.
72-
# All parameter metadata is handled separately
72+
# These parameter keys are handled separately.
7373
continue
7474

7575
# check if the key is an FCS standard optional keyword
76-
if key not in FCS_STANDARD_OPTIONAL_KEYWORDS:
76+
pnx_match = re.match(r'^p\d+([dfloptv]|calibration)$', key)
77+
if key not in FCS_STANDARD_OPTIONAL_KEYWORDS and pnx_match is None:
7778
# save it for later, we'll put all the non-standard
7879
# keys at the end
7980
non_std_dict[key] = value

flowio/tests/fcs_write_tests.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ def test_create_fcs_with_std_metadata(self):
204204
if k in FCS_STANDARD_KEYWORDS:
205205
metadata_dict[k] = v
206206

207+
metadata_dict['$P1D'] = 'Linear,0,10'
208+
metadata_dict['$P1F'] = '520LP'
209+
metadata_dict['$P1L'] = '588'
210+
metadata_dict['$P1O'] = '200'
211+
metadata_dict['$P1P'] = '50'
212+
metadata_dict['$P1T'] = 'PMT9524'
213+
metadata_dict['$P1V'] = '250'
214+
metadata_dict['$VOL'] = '120'
215+
metadata_dict['$P1CALIBRATION'] = '1.234,MESF'
216+
207217
export_file_path = "examples/fcs_files/test_fcs_export.fcs"
208218
fh = open(export_file_path, 'wb')
209219
create_fcs(fh, event_data, channel_names=pnn_labels, metadata_dict=metadata_dict)
@@ -212,10 +222,16 @@ def test_create_fcs_with_std_metadata(self):
212222
exported_flow_data = FlowData(export_file_path)
213223
os.unlink(export_file_path)
214224

215-
cyt_truth = 'Main Aria (FACSAria)'
216-
cyt_value = exported_flow_data.text['cyt']
217-
218-
self.assertEqual(cyt_value, cyt_truth)
225+
self.assertEqual(exported_flow_data.text['cyt'], 'Main Aria (FACSAria)')
226+
self.assertEqual(exported_flow_data.text['p1d'], 'Linear,0,10')
227+
self.assertEqual(exported_flow_data.text['p1f'], '520LP')
228+
self.assertEqual(exported_flow_data.text['p1l'], '588')
229+
self.assertEqual(exported_flow_data.text['p1o'], '200')
230+
self.assertEqual(exported_flow_data.text['p1p'], '50')
231+
self.assertEqual(exported_flow_data.text['p1t'], 'PMT9524')
232+
self.assertEqual(exported_flow_data.text['p1v'], '250')
233+
self.assertEqual(exported_flow_data.text['vol'], '120')
234+
self.assertEqual(exported_flow_data.text['p1calibration'], '1.234,MESF')
219235

220236
def test_create_fcs_with_non_std_metadata(self):
221237
event_data = self.flow_data.events

0 commit comments

Comments
 (0)