Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore NaN reagents in create_fcs #29

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/flowio/create_fcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ def create_fcs(
# PnS - optional channel label
if opt_channel_names is not None:
# cannot have zero-length values in FCS keyword values
if opt_channel_names[i] not in [None, '']:
# equality test omits NaNs (result from "None" and "" in Pandas indices)
opt_channel_name = opt_channel_names[i]
if opt_channel_name not in [None, ''] and opt_channel_name == opt_channel_name:
text['P%dS' % chan_num] = opt_channel_names[i]

# Calculate initial text size, but it's tricky b/c the text contains the
Expand Down
20 changes: 20 additions & 0 deletions tests/test_fcs_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,26 @@ def test_create_fcs_with_opt_channel_labels(self):

self.assertEqual(p5s_label_value, p5s_label_truth)

def test_create_fcs_with_opt_channel_labels_none(self):
event_data = self.flow_data.events
channel_names = self.flow_data.channels
pnn_labels = [v['PnN'] for k, v in channel_names.items()]
pns_labels = [v['PnS'] for k, v in channel_names.items()]
pns_labels[0] = None
pns_labels[1] = float("nan")
pns_labels[2] = ""

export_file_path = "examples/fcs_files/test_fcs_export.fcs"
with open(export_file_path, 'wb') as fh:
create_fcs(fh, event_data, channel_names=pnn_labels, opt_channel_names=pns_labels)

exported_flow_data = FlowData(export_file_path)
os.unlink(export_file_path)

self.assertNotIn("p1s", exported_flow_data.text)
self.assertNotIn("p2s", exported_flow_data.text)
self.assertNotIn("p3s", exported_flow_data.text)

def test_create_fcs_with_std_metadata(self):
event_data = self.flow_data.events
channel_names = self.flow_data.channels
Expand Down