1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
//! # BEDrs
//! bedtools-like functionality for interval sets in rust
//!
//! ## Summary
//!
//! I wanted some bedtools-like functionality in rust and I made this tool to both
//! learn how to implement genomic arithmetic as well as get more comfortable with
//! generics and traits in rust.
//!
//! This library will eventually be focused towards genome-specific arithmetic
//! and focuses around a base [Coordinates] trait which includes methods to
//! retrieve `<chr, start, stop>` and a base [Container] trait which includes
//! methods to perform set operations.
//!
//! This is a work in progress and is subject to heavy changes.
//!
//! If you want a more robust interval library I recommend the following:
//!
//! - [rust_lapper](https://crates.io/crates/rust-lapper)
//! - [COITrees](https://crates.io/crates/coitrees)
//! - [rampart](https://crates.io/crates/rampart)
//!
//! This library is heavily inspired from those above.
//!
//! ## Traits
//!
//! The advantage of this library is that all of the functionality is implemented
//! via traits.
//! As a result, if you have a custom data type - if you implement the traits then
//! you get all the functionality for free. There are two main traits in this library.
//!
//! 1. [Coordinates] :: which applies to individual interval records.
//! 2. [Container] :: which applies to sets of interval records.
//!
//! ## Types
//!
//! This library has batteries included and has a few types you can use immediately or
//! as references for designing your own.
//!
//! ### Base Interval
//!
//! Here is an example of the base [Interval](types::Interval).
//!
//! This interval only has two coordinates: `start` and `end`.
//! This is the classic interval type.
//!
//! ```
//! use bedrs::{Overlap, Interval};
//!
//! let a = Interval::new(10, 20);
//! let b = Interval::new(15, 25);
//! let c = Interval::new(20, 30);
//!
//! assert!(a.overlaps(&b));
//! assert!(!a.overlaps(&c));
//! assert!(b.overlaps(&c));
//! ```
//!
//! ### Genomic Interval
//!
//! Here is an example of a [GenomicInterval](types::GenomicInterval).
//!
//! This is the bread and butter of genomic arithmetic and has three
//! coordinates: `chr`, `start`, and `end`.
//!
//! ```
//! use bedrs::{Overlap, GenomicInterval};
//!
//! let a = GenomicInterval::new(1, 10, 20);
//! let b = GenomicInterval::new(1, 15, 25);
//! let c = GenomicInterval::new(2, 15, 25);
//!
//! assert!(a.overlaps(&b));
//! assert!(!a.overlaps(&c));
//! assert!(!b.overlaps(&c));
//! ```
//!
//! ## Interval Operations
//!
//! The following operations with be shown with the base [Interval], but
//! the same operations can be done with a [GenomicInterval] or any other
//! custom type which implements the [Coordinates] trait.
//!
//! ### Overlap
//! ```
//! use bedrs::{Overlap, Interval};
//!
//! let a = Interval::new(10, 20);
//! let b = Interval::new(15, 25);
//! assert!(a.overlaps(&b));
//! ```
//!
//! ### Containment
//!
//! Whether an interval is contained by another.
//!
//! ```
//! use bedrs::{Overlap, Interval};
//!
//! let a = Interval::new(10, 30);
//! let b = Interval::new(15, 25);
//! assert!(a.contains(&b));
//! assert!(b.contained_by(&a));
//! ```
//!
//! ### Borders
//!
//! Whether an interval is bordered by another.
//!
//! ```
//! use bedrs::{Overlap, Interval};
//!
//! let a = Interval::new(10, 30);
//! let b = Interval::new(30, 50);
//! assert!(a.borders(&b));
//! ```
//!
//! ## Interval Functions
//!
//! The following are active functions to generate more intervals using
//! some query intervals.
//!
//! ### Intersect
//!
//! Here is an example of a positive intersect
//!
//! ```
//! use bedrs::{Interval, Coordinates, Intersect};
//!
//! let a = Interval::new(10, 30);
//! let b = Interval::new(20, 40);
//! let ix = a.intersect(&b).unwrap();
//! assert_eq!(ix.start(), 20);
//! assert_eq!(ix.end(), 30);
//! ```
//!
//! Here is an example of a negative intersect
//!
//! ```
//! use bedrs::{Interval, Coordinates, Intersect};
//!
//! let a = Interval::new(10, 30);
//! let b = Interval::new(30, 40);
//! let ix = a.intersect(&b);
//! assert!(ix.is_none());
//! ```
//!
//! ### Subtract
//!
//! The following method subtracts an interval from another.
//! This returns a vector of intervals, as there could be
//! either zero, one, or two possible interval returned.
//!
//! #### Left-Hand Subtraction
//!
//! ```
//! use bedrs::{Interval, Coordinates, Subtract};
//!
//! let a = Interval::new(10, 30);
//! let b = Interval::new(20, 40);
//! let sub = a.subtract(&b).unwrap();
//! assert_eq!(sub.len(), 1);
//! assert_eq!(sub[0].start(), 10);
//! assert_eq!(sub[0].end(), 20);
//! ```
//!
//! #### Right-Hand Subtraction
//!
//! ```
//! use bedrs::{Interval, Coordinates, Subtract};
//!
//! let a = Interval::new(20, 40);
//! let b = Interval::new(10, 30);
//! let sub = a.subtract(&b).unwrap();
//! assert_eq!(sub.len(), 1);
//! assert_eq!(sub[0].start(), 30);
//! assert_eq!(sub[0].end(), 40);
//! ```
//!
//! #### Contained Subtraction
//!
//! ```
//! use bedrs::{Interval, Coordinates, Subtract};
//!
//! let a = Interval::new(10, 40);
//! let b = Interval::new(20, 30);
//! let sub = a.subtract(&b).unwrap();
//! assert_eq!(sub.len(), 2);
//! assert_eq!(sub[0].start(), 10);
//! assert_eq!(sub[0].end(), 20);
//! assert_eq!(sub[1].start(), 30);
//! assert_eq!(sub[1].end(), 40);
//! ```
//!
//! #### Contained-By Subtraction
//!
//! ```
//! use bedrs::{Interval, Coordinates, Subtract};
//!
//! let a = Interval::new(20, 30);
//! let b = Interval::new(10, 40);
//! let sub = a.subtract(&b);
//! assert!(sub.is_none());
//! ```
//!
//! #### No Overlap Subtraction
//!
//! ```
//! use bedrs::{Interval, Coordinates, Subtract};
//!
//! let a = Interval::new(10, 20);
//! let b = Interval::new(20, 30);
//! let sub = a.subtract(&b).unwrap();
//! assert_eq!(sub.len(), 1);
//! assert_eq!(sub[0].start(), 10);
//! assert_eq!(sub[0].end(), 20);
//! ```
/// Traits used within the library
/// Types used within the library
pub use ;
pub use ;