Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
flow-gates
A comprehensive Rust library for working with gates in flow cytometry data analysis. This library provides tools for creating, managing, and applying gates to flow cytometry data, supporting the GatingML 2.0 standard for gate definitions and hierarchies.
Features
- Multiple Gate Types: Polygon, Rectangle, and Ellipse geometries
- Gate Hierarchies: Parent-child relationships for sequential gating strategies
- Efficient Event Filtering: Spatial indexing (R*-tree) for fast point-in-gate queries
- Comprehensive Statistics: Detailed statistical analysis of gated populations
- GatingML 2.0 Support: Import/export gates in standard XML format
- Thread-Safe Storage: Concurrent gate management with optional persistence
- Zero-Copy Operations: Efficient data access using slices where possible
Installation
Add this to your Cargo.toml:
[]
= { = "../flow-gates" }
= { = "../flow-fcs" } # Required for FCS file support
Quick Start
Creating a Gate
use *;
use *;
// Create a polygon gate from coordinates
let coords = vec!;
let geometry = create_polygon_geometry?;
let gate = new;
Filtering Events
use ;
use Fcs;
// Load FCS file
let fcs = from_file?;
// Filter events by gate
let event_indices = filter_events_by_gate?;
println!;
Calculating Statistics
use GateStatistics;
let stats = calculate?;
println!;
println!;
println!;
println!;
Core Concepts
Gates
A Gate represents a region of interest in 2D parameter space. Each gate has:
- Geometry: The shape (polygon, rectangle, or ellipse)
- Parameters: Two channels (x and y) the gate operates on
- Mode: Scope (global, file-specific, or file group)
- ID and Name: Unique identifier and human-readable name
Gate Types
Polygon Gates
Polygon gates are defined by a series of vertices forming a closed or open polygon:
use ;
let coords = vec!;
let geometry = create_polygon_geometry?;
let gate = new;
Rectangle Gates
Rectangle gates are axis-aligned rectangular regions:
let coords = vec!;
let geometry = create_rectangle_geometry?;
let gate = new;
Ellipse Gates
Ellipse gates are elliptical regions with optional rotation:
let coords = vec!;
let geometry = create_ellipse_geometry?;
let gate = new;
Gate Modes
Gates can be scoped to apply globally or to specific files:
use GateMode;
// Global gate (applies to all files)
let global_gate = new;
// Gate mode defaults to Global
// File-specific gate
let mut file_gate = new;
file_gate.mode = FileSpecific ;
// File group gate
let mut group_gate = new;
group_gate.mode = FileGroup ;
Advanced Usage
Gate Hierarchies
Gate hierarchies allow sequential gating where child gates are applied to events that pass parent gates:
use GateHierarchy;
let mut hierarchy = new;
// Build hierarchy: root -> parent -> child
hierarchy.add_child;
hierarchy.add_child;
// Get chain from root to a specific gate
let chain = hierarchy.get_chain_to_root;
// Returns: ["root-gate", "parent-gate", "child-gate"]
// Get ancestors
let ancestors = hierarchy.get_ancestors;
// Returns: ["parent-gate", "root-gate"]
// Get descendants
let descendants = hierarchy.get_descendants;
// Returns: ["parent-gate", "child-gate"]
Hierarchical Event Filtering
Filter events through a chain of gates:
use ;
// Build gate chain from hierarchy
let gate_chain: = hierarchy
.get_chain_to_root
.iter
.filter_map
.collect;
// Filter through hierarchy
let indices = filter_events_by_hierarchy?;
Spatial Indexing for Performance
For repeated filtering operations, use a spatial index:
use ;
// Build index once
let x_slice = fcs.get_parameter_events_slice?;
let y_slice = fcs.get_parameter_events_slice?;
let index = build?;
// Reuse index for multiple gates (much faster!)
let indices1 = filter_events_by_gate?;
let indices2 = filter_events_by_gate?;
let indices3 = filter_events_by_gate?;
Gate Storage
Thread-safe gate storage with optional persistence:
use GateStorage;
use PathBuf;
// Create storage with auto-save
let storage = with_save_path;
// Load existing gates
storage.load?;
// Insert gates
storage.insert;
storage.insert;
// Query gates
let file_gates = storage.gates_for_file;
let param_gates = storage.gates_for_parameters;
let specific_gates = storage.gates_for_file_and_parameters;
// Manual save (auto-save is enabled by default)
storage.save?;
GatingML Import/Export
Export gates to GatingML 2.0 format:
use gates_to_gatingml;
let gates = vec!;
let xml = gates_to_gatingml?;
// Save to file
write?;
Import gates from GatingML format:
use gatingml_to_gates;
let xml = read_to_string?;
let gates = gatingml_to_gates?;
Application Integration Examples
Example 1: Basic Gate Application
use *;
use Fcs;
Example 2: Hierarchical Gating Pipeline
use *;
use Fcs;
Example 3: Batch Processing with Caching
use *;
use Fcs;
use Arc;
use HashMap;
Example 4: Statistics Dashboard
use *;
use Fcs;
Example 5: Interactive Gate Editor Integration
use *;
use *;
// User draws polygon on plot
// Update gate after user edits
Performance Considerations
Spatial Indexing
For repeated filtering operations on the same dataset, use EventIndex:
- Build time: O(n log n) - one-time cost
- Query time: O(log n) per gate - much faster than O(n) linear scan
- Memory: O(n) - stores all event points
Caching
Implement the FilterCache trait for your application to cache filter results:
use ;
use Arc;
Error Handling
The library uses GateError for all error conditions. Most operations return Result<T, GateError>:
use ;
match create_polygon_geometry
Thread Safety
Most types in this library are thread-safe:
GateStorage: Thread-safe concurrent accessEventIndex: Immutable after construction, safe to shareGate,GateGeometry,GateNode: Clone to share between threadsGateHierarchy: Use synchronization primitives for concurrent access
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.