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

Conversation

zbjornson
Copy link
Contributor

"None" and "" in Pandas indices become NaNs, which causes problems here when writing FCS files.

Copy link

codecov bot commented Jul 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.47%. Comparing base (d9f419c) to head (37163c6).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #29      +/-   ##
===========================================
+ Coverage    91.45%   91.47%   +0.01%     
===========================================
  Files            7        7              
  Lines          433      434       +1     
===========================================
+ Hits           396      397       +1     
  Misses          37       37              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@whitews
Copy link
Owner

whitews commented Jul 3, 2024

Hi Zach,

Appreciate the PR. Can you expound more on the use case that this addresses?

Thanks,
Scott

@zbjornson
Copy link
Contributor Author

Sorry for the slow reply, I went on vacation just after opening this. Here's an example:

import flowio
import pandas
import numpy as np

df = pandas.DataFrame(
    np.random.randn(6,3),
    columns=[["Ax488-A", "PE-A", "Cluster ID"],
             ["CD3", "CD4", None]],
    dtype="float32"
)

fh = open('data_set1.fcs', 'wb')
flowio.create_fcs(
    file_handle=fh,
    event_data=df.to_numpy().flatten(),
    channel_names=df.columns.get_level_values(0).tolist(),
    opt_channel_names=df.columns.get_level_values(1).tolist()  # This is the problem line
)
fh.close()

The indicated line becomes ['CD3', 'CD4', nan] and causes this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\zachb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\flowio\create_fcs.py", line 254, in create_fcs
    text_string = _build_text(
  File "C:\Users\zachb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\flowio\create_fcs.py", line 47, in _build_text
    required_dict[key].replace(text_delimiter, text_delimiter * 2),
AttributeError: 'float' object has no attribute 'replace'

But I should probably just handle this upstream since it makes no sense to pass nan here. Sorry for the noise!

@zbjornson zbjornson closed this Jul 19, 2024
@zbjornson zbjornson deleted the no-nan-reagents branch July 19, 2024 01:09
@whitews
Copy link
Owner

whitews commented Jul 20, 2024

No worries, thanks for the update. I agree that NaN values would best be handled upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants