| Crates.io | flow-fcs |
| lib.rs | flow-fcs |
| version | 0.2.0 |
| created_at | 2026-01-07 18:48:34.729848+00 |
| updated_at | 2026-01-21 19:12:19.003118+00 |
| description | High-level Flow Cytometry Standard (FCS) file struct and operations |
| homepage | |
| repository | https://github.com/jrmoynihan/flow/flow-fcs |
| max_upload_size | |
| id | 2028827 |
| size | 598,861 |
A high-performance Rust library for reading, parsing, and manipulating Flow Cytometry Standard (FCS) files.
:construction:
⚠️ Under Construction: This library is actively under development. APIs may change, and some features may be incomplete. Use with caution in production environments.
:construction:
flow-fcs provides a comprehensive, type-safe API for working with FCS files used in flow cytometry analysis. Built on top of Polars for efficient columnar data operations, the library offers zero-copy data access, SIMD-accelerated operations, and support for common flow cytometry data transformations.
Full FCS Standard Support: Supports FCS versions 1.0 through 4.0
High Performance:
Data Transformations:
Polars Integration:
Comprehensive Metadata Access:
Type Safety: Strong typing throughout with clear error messages
Add this to your Cargo.toml:
[dependencies]
flow-fcs = "0.1.0"
typescript: Generate TypeScript bindings for Rust types (requires ts-rs)[dependencies]
flow-fcs = { version = "0.1.0", features = ["typescript"] }
use flow_fcs::Fcs;
// Open an FCS file
let fcs = Fcs::open("path/to/file.fcs")?;
// Get basic information
let num_events = fcs.get_number_of_events()?;
let num_parameters = fcs.get_number_of_parameters()?;
let guid = fcs.get_guid()?;
println!("File: {} events, {} parameters", num_events, num_parameters);
println!("GUID: {}", guid);
// Get events for a specific parameter (zero-copy slice)
let fsc_data = fcs.get_parameter_events_slice("FSC-A")?;
// Get (x, y) pairs for plotting
let xy_pairs = fcs.get_xy_pairs("FSC-A", "SSC-A")?;
// Get parameter statistics using streaming (memory-efficient)
let (min, max, mean, std) = fcs.get_parameter_statistics("FL1-A")?;
println!("FL1-A: min={}, max={}, mean={:.2}, std={:.2}", min, max, mean, std);
// Apply arcsinh transformation to a parameter
let transformed = fcs.apply_arcsinh_transform("FL1-A", 200.0)?;
// Apply arcsinh to all fluorescence parameters with default cofactor
let transformed = fcs.apply_default_arcsinh_transform()?;
// Apply compensation from file's $SPILLOVER keyword
let compensated = fcs.apply_file_compensation()?;
// Apply custom compensation matrix
use ndarray::Array2;
let comp_matrix = Array2::from_shape_vec((2, 2), vec![
1.0, 0.1,
0.05, 1.0,
])?;
let channels = vec!["FL1-A", "FL2-A"];
let compensated = fcs.apply_compensation(&comp_matrix, &channels)?;
// Get keyword values
let filename = fcs.get_fil_keyword()?;
let cytometer = fcs.get_keyword_string_value("$CYT")?;
// Access parameter information
let param = fcs.find_parameter("FL1-A")?;
println!("Channel: {}, Label: {}", param.channel_name, param.label_name);
Fcs: Main struct representing an FCS fileHeader: FCS file header informationMetadata: Text segment metadata and keywordsParameter: Parameter/channel informationEventDataFrame: Polars DataFrame containing event dataFcs::open(path): Open and parse an FCS fileFcs::new(): Create an empty FCS structget_parameter_events_slice(channel_name): Get zero-copy slice of parameter dataget_xy_pairs(x_param, y_param): Get (x, y) coordinate pairs for plottingget_parameter_statistics(channel_name): Calculate min, max, mean, std (streaming)get_event_count_from_dataframe(): Get number of eventsget_parameter_count_from_dataframe(): Get number of parametersapply_arcsinh_transform(parameter, cofactor): Apply arcsinh transformationapply_arcsinh_transforms(params): Apply to multiple parametersapply_default_arcsinh_transform(): Transform all fluorescence parametersapply_compensation(matrix, channels): Apply compensation matrixapply_file_compensation(): Apply compensation from $SPILLOVER keywordapply_spectral_unmixing(matrix, channels, cofactor): Apply spectral unmixingget_guid(): Get file GUIDget_fil_keyword(): Get filenameget_keyword_string_value(keyword): Get any keyword as stringget_number_of_events(): Get total event countget_number_of_parameters(): Get parameter countfind_parameter(channel_name): Find parameter by nameThe library is optimized for performance:
The library supports FCS versions:
The library uses anyhow::Result for error handling, providing detailed error messages for common issues:
See the tests/ directory for more comprehensive examples of library usage.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.