Skip to content

Instantly share code, notes, and snippets.

@BjornFJohansson
Last active June 23, 2023 14:16
Show Gist options
  • Save BjornFJohansson/fca0176710f380b34b8737c42820edf6 to your computer and use it in GitHub Desktop.
Save BjornFJohansson/fca0176710f380b34b8737c42820edf6 to your computer and use it in GitHub Desktop.
# Flow Cytometry Standard file format --> csv
# https://stackoverflow.com/questions/70348405/how-to-convert-lmd-file-to-csv-flow-cytometry-data
# https://pypi.org/project/fcsparser/
"""
This script collects all files in the same directory as the script (or cwd) with
the file ending "fcs". These files are assumed to be in the Flow Cytometry Standard file format
anhd converted to CSV using pandas, and fcsparser. To install requirements:
pip install fcsparser pandas
"""
import pandas as pd
import fcsparser
from pathlib import Path
for pth in Path(".").glob("*.fcs"):
print(pth)
meta = fcsparser.parse(pth,meta_data_only=True)
meta, data = fcsparser.parse(pth, meta_data_only=False, reformat_meta=True)
df = pd.DataFrame(data)
df.to_csv(pth.with_suffix(".csv"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment