flow_gates/
lib.rs

1//! # flow-gates
2//!
3//! A comprehensive Rust library for working with gates in flow cytometry data analysis.
4//!
5//! This library provides tools for creating, managing, and applying gates to flow cytometry
6//! data, supporting the GatingML 2.0 standard for gate definitions and hierarchies.
7//!
8//! ## Overview
9//!
10//! Flow cytometry gates define regions of interest in multi-dimensional data space,
11//! allowing researchers to identify and analyze specific cell populations. This library
12//! provides:
13//!
14//! - **Gate Types**: Polygon, Rectangle, and Ellipse geometries
15//! - **Gate Hierarchies**: Parent-child relationships for sequential gating
16//! - **Event Filtering**: Efficient spatial indexing and filtering of cytometry events
17//! - **Statistics**: Comprehensive statistics for gated populations
18//! - **GatingML Support**: Import/export gates in GatingML 2.0 XML format
19//! - **Thread-Safe Storage**: Concurrent gate management
20//!
21//! ## Quick Start
22//!
23//! ```rust
24//! use flow_gates::*;
25//! use flow_gates::geometry::*;
26//!
27//! // Create a polygon gate
28//! let coords = vec![
29//!     (100.0, 200.0),
30//!     (300.0, 200.0),
31//!     (300.0, 400.0),
32//!     (100.0, 400.0),
33//! ];
34//! let geometry = create_polygon_geometry(coords, "FSC-A", "SSC-A")?;
35//!
36//! let gate = Gate::new(
37//!     "my-gate",
38//!     "My Gate",
39//!     geometry,
40//!     "FSC-A",
41//!     "SSC-A",
42//! );
43//!
44//! // Apply gate to FCS data
45//! let event_indices = filter_events_by_gate(&fcs_file, &gate, None)?;
46//! ```
47//!
48//! ## Core Concepts
49//!
50//! ### Gates
51//!
52//! A [`Gate`] represents a region of interest defined by:
53//! - **Geometry**: The shape (polygon, rectangle, or ellipse)
54//! - **Parameters**: The two channels (x and y) the gate operates on
55//! - **Mode**: Whether the gate applies globally or to specific files
56//!
57//! ### Gate Hierarchies
58//!
59//! Gates can be organized in parent-child relationships, where child gates
60//! are applied to events that pass through their parent gates. Use [`GateHierarchy`]
61//! to manage these relationships.
62//!
63//! ### Event Filtering
64//!
65//! The library provides efficient event filtering using spatial indexing (R*-tree)
66//! for fast point-in-gate queries. Use [`EventIndex`] for repeated filtering operations
67//! on the same dataset.
68//!
69//! ## Examples
70//!
71//! See the [README](https://github.com/jrmoynihan/flow-gates) for detailed examples
72//! including:
73//! - Creating different gate types
74//! - Building gate hierarchies
75//! - Filtering events
76//! - Calculating statistics
77//! - Application integration patterns
78//!
79//! ## Error Handling
80//!
81//! The library uses [`GateError`] for all error conditions. Most operations return
82//! [`Result<T, GateError>`](GateResult).
83
84pub mod ellipse;
85pub mod error;
86pub mod filtering;
87pub mod gatingml;
88pub mod geometry;
89pub mod hierarchy;
90pub mod polygon;
91pub mod rectangle;
92pub mod scope;
93pub mod statistics;
94pub mod traits;
95pub mod traits_tests;
96pub mod transforms;
97pub mod types;
98
99#[cfg(test)]
100mod error_tests;
101
102/// Error types for gate operations
103pub use error::{GateError, Result as GateResult};
104
105/// Event filtering and spatial indexing
106pub use filtering::{
107    EventIndex, FilterCache, FilterCacheKey, filter_events_by_gate, filter_events_by_hierarchy,
108};
109
110/// Geometry construction helpers
111pub use geometry::{create_ellipse_geometry, create_polygon_geometry, create_rectangle_geometry};
112
113/// Gate hierarchy management
114pub use hierarchy::GateHierarchy;
115
116/// Statistics for gated populations
117pub use statistics::GateStatistics;
118
119/// Core gate types and structures
120pub use types::{Gate, GateGeometry, GateMode, GateNode};
121
122// Note: FilterCache and GateStorage are application-specific and should be
123// implemented in the application crate, not in this library crate.