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

Allow for creation of empty FCS files #26

Merged
merged 2 commits into from
Nov 30, 2023
Merged
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
5 changes: 0 additions & 5 deletions flowio/create_fcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ def create_fcs(

n_points = len(event_data)

if n_points == 0:
raise ValueError(
"'event_data' array provided was empty"
)

if not n_points % n_channels == 0:
raise ValueError(
"Number of data points is not a multiple of the number of channels"
Expand Down
25 changes: 25 additions & 0 deletions flowio/tests/fcs_write_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,28 @@ def test_create_fcs_with_2byte_char(self):
os.unlink(export_file_path)

self.assertEqual(flow_data.events[0], exported_flow_data.events[0])

def test_create_and_read_empty_fcs(self):
event_data = []
pnn_labels = [v["PnN"] for k, v in self.flow_data.channels.items()]
pns_labels = [v["PnS"] for k, v in self.flow_data.channels.items()]

metadata_dict = {"p9g": "2"}

export_file_path = "examples/fcs_files/test_fcs_export_empty.fcs"
with open(export_file_path, "wb") as export_file:
create_fcs(
export_file,
event_data,
channel_names=pnn_labels,
opt_channel_names=pns_labels,
metadata_dict=metadata_dict,
)

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

self.assertIsInstance(exported_flow_data, FlowData)
self.assertEqual(len(exported_flow_data.events), 0)
self.assertEqual(exported_flow_data.channels, self.flow_data.channels)
self.assertEqual(exported_flow_data.text["p9g"], "2")