Skip to content

Commit

Permalink
Merge pull request #26 from tristan-ranff/master
Browse files Browse the repository at this point in the history
Allow for creation of empty FCS files
  • Loading branch information
whitews committed Nov 30, 2023
2 parents b926723 + 281b1ae commit e4152e9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
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")

0 comments on commit e4152e9

Please sign in to comment.