Skip to content

Commit

Permalink
Merge pull request #18 from primitybio/zb/other-pnx
Browse files Browse the repository at this point in the history
Support parametrized optional FCS keywords
  • Loading branch information
whitews authored Jan 23, 2023
2 parents 282669c + 69dd36b commit 6d729b7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
7 changes: 4 additions & 3 deletions flowio/create_fcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,17 @@ def _build_text(
# skip it, these are allowed to be set by the user
continue

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

# check if the key is an FCS standard optional keyword
if key not in FCS_STANDARD_OPTIONAL_KEYWORDS:
pnx_match = re.match(r'^p\d+([dfloptv]|calibration)$', key)
if key not in FCS_STANDARD_OPTIONAL_KEYWORDS and pnx_match is None:
# save it for later, we'll put all the non-standard
# keys at the end
non_std_dict[key] = value
Expand Down
24 changes: 20 additions & 4 deletions flowio/tests/fcs_write_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ def test_create_fcs_with_std_metadata(self):
if k in FCS_STANDARD_KEYWORDS:
metadata_dict[k] = v

metadata_dict['$P1D'] = 'Linear,0,10'
metadata_dict['$P1F'] = '520LP'
metadata_dict['$P1L'] = '588'
metadata_dict['$P1O'] = '200'
metadata_dict['$P1P'] = '50'
metadata_dict['$P1T'] = 'PMT9524'
metadata_dict['$P1V'] = '250'
metadata_dict['$VOL'] = '120'
metadata_dict['$P1CALIBRATION'] = '1.234,MESF'

export_file_path = "examples/fcs_files/test_fcs_export.fcs"
fh = open(export_file_path, 'wb')
create_fcs(fh, event_data, channel_names=pnn_labels, metadata_dict=metadata_dict)
Expand All @@ -212,10 +222,16 @@ def test_create_fcs_with_std_metadata(self):
exported_flow_data = FlowData(export_file_path)
os.unlink(export_file_path)

cyt_truth = 'Main Aria (FACSAria)'
cyt_value = exported_flow_data.text['cyt']

self.assertEqual(cyt_value, cyt_truth)
self.assertEqual(exported_flow_data.text['cyt'], 'Main Aria (FACSAria)')
self.assertEqual(exported_flow_data.text['p1d'], 'Linear,0,10')
self.assertEqual(exported_flow_data.text['p1f'], '520LP')
self.assertEqual(exported_flow_data.text['p1l'], '588')
self.assertEqual(exported_flow_data.text['p1o'], '200')
self.assertEqual(exported_flow_data.text['p1p'], '50')
self.assertEqual(exported_flow_data.text['p1t'], 'PMT9524')
self.assertEqual(exported_flow_data.text['p1v'], '250')
self.assertEqual(exported_flow_data.text['vol'], '120')
self.assertEqual(exported_flow_data.text['p1calibration'], '1.234,MESF')

def test_create_fcs_with_non_std_metadata(self):
event_data = self.flow_data.events
Expand Down

0 comments on commit 6d729b7

Please sign in to comment.