Skip to main content

grit_genomics/
lib.rs

1// Clippy allows for the whole crate
2#![allow(clippy::too_many_arguments)]
3#![allow(clippy::should_implement_trait)]
4#![allow(clippy::type_complexity)]
5
6//! GRIT: Genomic Range Interval Toolkit
7//!
8//! This library provides efficient interval operations for genomic data analysis.
9//!
10//! # Features
11//!
12//! - **Parallel processing**: Uses Rayon for multi-core parallelism
13//! - **Streaming I/O**: Memory-efficient processing of large files
14//! - **Drop-in compatibility**: Matches bedtools CLI arguments
15//!
16//! # Example
17//!
18//! ```rust,no_run
19//! use grit_genomics::{bed, interval::Interval, commands::IntersectCommand};
20//!
21//! // Read BED files
22//! let a = bed::read_intervals("a.bed").unwrap();
23//! let b = bed::read_intervals("b.bed").unwrap();
24//!
25//! // Find intersections
26//! let cmd = IntersectCommand::new();
27//! let results = cmd.find_intersections_parallel(a, b);
28//! ```
29
30pub mod bed;
31pub mod commands;
32pub mod config;
33pub mod genome;
34pub mod index;
35pub mod interval;
36pub mod parallel;
37pub mod streaming;
38
39// Re-export commonly used types
40pub use bed::{read_intervals, read_records, BedReader};
41pub use index::IntervalIndex;
42pub use interval::{BedRecord, Interval, Strand};
43
44/// Library version
45pub const VERSION: &str = env!("CARGO_PKG_VERSION");
46
47/// Prelude module for convenient imports.
48pub mod prelude {
49    pub use crate::bed::{read_intervals, read_records, BedReader};
50    pub use crate::commands::{
51        ClosestCommand, CoverageCommand, IntersectCommand, MergeCommand, SortCommand,
52        SubtractCommand, WindowCommand,
53    };
54    pub use crate::index::IntervalIndex;
55    pub use crate::interval::{BedRecord, Interval, Strand};
56}
57
58#[cfg(test)]
59mod tests {
60    #[test]
61    fn test_basic_workflow() {
62        use crate::bed::parse_intervals;
63        use crate::commands::MergeCommand;
64
65        let content = "chr1\t100\t200\nchr1\t150\t250\nchr1\t300\t400\n";
66        let intervals = parse_intervals(content).unwrap();
67
68        let cmd = MergeCommand::new();
69        let merged = cmd.merge(intervals);
70
71        assert_eq!(merged.len(), 2);
72        assert_eq!(merged[0].start, 100);
73        assert_eq!(merged[0].end, 250);
74    }
75
76    #[test]
77    fn test_intersect_workflow() {
78        use crate::bed::parse_intervals;
79        use crate::commands::IntersectCommand;
80        use crate::index::IntervalIndex;
81
82        let a_content = "chr1\t100\t200\nchr1\t300\t400\n";
83        let b_content = "chr1\t150\t250\n";
84
85        let a = parse_intervals(a_content).unwrap();
86        let b = parse_intervals(b_content).unwrap();
87
88        let cmd = IntersectCommand::new();
89        let b_index = IntervalIndex::from_intervals(b);
90        let results = cmd.find_intersections(&a, &b_index);
91
92        assert_eq!(results.len(), 1);
93    }
94}