Skip to content

Commit f48e0ea

Browse files
committed
Merge branch 'JcGKitten-master'
2 parents e5860db + f92c0a0 commit f48e0ea

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

flowio/flowdata.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ class FlowData(object):
2929
3030
:param filename_or_handle: a path string or a file handle for an FCS file
3131
:param ignore_offset_error: option to ignore data offset error (see above note), default is False
32+
:param only_text: option to only read the "text" segment of the FCS file without loading event data,
33+
default is False
3234
"""
33-
def __init__(self, filename_or_handle, ignore_offset_error=False):
35+
def __init__(self, filename_or_handle, ignore_offset_error=False, only_text=False):
3436
if isinstance(filename_or_handle, basestring):
3537
self._fh = open(str(filename_or_handle), 'rb')
3638
else:
@@ -86,12 +88,15 @@ def __init__(self, filename_or_handle, ignore_offset_error=False):
8688
if d_stop > self.file_size:
8789
raise EOFError("FCS header indicates data section greater than file size")
8890

89-
self.events = self.__parse_data(
90-
self.cur_offset,
91-
d_start,
92-
d_stop,
93-
self.text
94-
)
91+
if only_text:
92+
self.events = None
93+
else:
94+
self.events = self.__parse_data(
95+
self.cur_offset,
96+
d_start,
97+
d_stop,
98+
self.text
99+
)
95100

96101
self.channels = self._parse_channels()
97102

@@ -377,6 +382,12 @@ def write_fcs(self, filename, extra=None, extra_non_standard=None):
377382
:param extra_non_standard: an optional dictionary for adding extra non-standard keywords/values
378383
:return: None
379384
"""
385+
if self.events is None:
386+
raise AttributeError(
387+
"FlowData instance does not contain event data. This might"
388+
"occur if the FCS file was read with the only_text=True option."
389+
)
390+
380391
pnn_labels = [''] * len(self.channels)
381392
pns_labels = [''] * len(self.channels)
382393

flowio/tests/flowdata_tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ def test_event_count(self):
2727
def test_get_text(self):
2828
self.assertEqual(self.flow_data.text['cyt'], 'FACScan')
2929

30+
def test_load_only_text(self):
31+
flow_data = FlowData('examples/fcs_files/3FITC_4PE_004.fcs', only_text=True)
32+
33+
self.assertIsNone(flow_data.events)
34+
self.assertRaises(AttributeError, flow_data.write_fcs, 'delete_this_file.fcs')
35+
3036
@staticmethod
3137
def test_load_fcs_from_memory():
3238
with open('examples/fcs_files/3FITC_4PE_004.fcs', 'rb') as f:

0 commit comments

Comments
 (0)