Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
whitews committed Feb 1, 2020
2 parents 26d7ec0 + a13c5d5 commit 0ae57b4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ wheels/

# Jupyter Notebook
.ipynb_checkpoints
*.ipynb
7 changes: 5 additions & 2 deletions flowkit/_models/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ def __init__(
except KeyError:
self.acquisition_date = None

# TODO: Allow user to set some sort of Sample ID or the orig filename,
# would be useful for Samples created from data arrays or if
# 2 FCS files had the same file name.
try:
self.original_filename = self.metadata['fil']
except KeyError:
Expand Down Expand Up @@ -850,15 +853,15 @@ def export(

ext = os.path.splitext(filename)[-1]

if ext == 'csv':
if ext == '.csv':
np.savetxt(
output_path,
events,
delimiter=',',
header=",".join(self.pnn_labels),
comments=''
)
elif ext == 'fcs':
elif ext == '.fcs':
fh = open(output_path, 'wb')

flowio.create_fcs(
Expand Down
8 changes: 8 additions & 0 deletions flowkit/_models/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def gate_sample(data):


def gate_samples(gating_strategy, samples, verbose):
# TODO: Looks like multiprocessing can fail for very large workloads (lots of gates), maybe due
# to running out of memory. Will investigate further, but for now maybe provide an option
# for turning off multiprocessing so end user can avoid this issue if it occurs.
if multi_proc:
if len(samples) < mp.cpu_count():
proc_count = len(samples)
Expand Down Expand Up @@ -141,8 +144,12 @@ def gates(self):

# start pass through methods for GatingStrategy
def add_gate(self, gate):
# TODO: allow adding multiple gates at once, while still allowing a single gate. Check if list or Gate instance
self.gating_strategy.add_gate(gate)

def add_sample(self, samples):
self.samples.extend(load_samples(samples))

def add_transform(self, transform):
self.gating_strategy.add_transform(transform)

Expand Down Expand Up @@ -239,6 +246,7 @@ def analyze_samples(self, verbose=False):
# indices for each sample. Add convenience functions inside
# GatingResults class for conveniently extracting information from
# the DataFrame
# TODO: should this method take a subsample option to gate on just the sub-sampled events?
results = gate_samples(self.gating_strategy, self.samples, verbose)

all_reports = [res.report for res in results]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

setup(
name='FlowKit',
version='0.3.1',
version='0.3.2',
packages=find_packages(),
package_data={'': ['*.xsd']},
include_package_data=True,
Expand Down
21 changes: 21 additions & 0 deletions unit_test/sample_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@ def test_transform_sample_hyperlog(self):

self.assertIsInstance(data1_sample._transformed_events, np.ndarray)

def test_create_fcs(self):
fcs_file_path = "examples/test_comp_example.fcs"
comp_file_path = Path("examples/comp_complete_example.csv")

sample = Sample(
fcs_path_or_data=fcs_file_path,
compensation=comp_file_path
)

sample.export("test_fcs_export.fcs", source='comp', directory="examples")

exported_fcs_file = "examples/test_fcs_export.fcs"
exported_sample = Sample(fcs_path_or_data=exported_fcs_file)
os.unlink(exported_fcs_file)

self.assertIsInstance(exported_sample, Sample)

# TODO: Excluding time channel here, as the difference was nearly 0.01. Need to investigate why the
# exported comp data isn't exactly equal
np.testing.assert_almost_equal(sample._comp_events[:, :-1], exported_sample._raw_events[:, :-1], decimal=3)


if __name__ == '__main__':
unittest.main()

0 comments on commit 0ae57b4

Please sign in to comment.