Skip to content

Commit 3d7d37e

Browse files
committed
More helpers
1 parent 0906c52 commit 3d7d37e

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

biocore/src/location.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ pub struct ContigPosition<Contig = String> {
1010
pub at: u64,
1111
}
1212
impl<Contig> ContigPosition<Contig> {
13+
pub fn range_to(self, to: u64) -> ContigRange<Contig> {
14+
assert!(self.at <= to, "{} <= {}", self.at, to);
15+
ContigRange {
16+
contig: self.contig,
17+
at: self.at..to,
18+
}
19+
}
1320
pub fn map_contig<NewContig>(
1421
self,
1522
f: impl FnOnce(Contig) -> NewContig,
@@ -277,6 +284,20 @@ pub mod orientation {
277284
let size = self.v.contig.size();
278285
self.flip_orientation_with(size)
279286
}
287+
288+
#[track_caller]
289+
pub fn into_orientation(mut self, orientation: SequenceOrientation) -> Self {
290+
self.set_orientation(orientation);
291+
self
292+
}
293+
#[track_caller]
294+
pub fn into_forward(self) -> Self {
295+
self.into_orientation(SequenceOrientation::Forward)
296+
}
297+
#[track_caller]
298+
pub fn into_reverse(self) -> Self {
299+
self.into_orientation(SequenceOrientation::Reverse)
300+
}
280301
}
281302
impl<C> WithOrientation<ContigPosition<C>> {
282303
#[track_caller]
@@ -317,6 +338,20 @@ pub mod orientation {
317338
self.flip_orientation_with(size)
318339
}
319340

341+
#[track_caller]
342+
pub fn into_orientation(mut self, orientation: SequenceOrientation) -> Self {
343+
self.set_orientation(orientation);
344+
self
345+
}
346+
#[track_caller]
347+
pub fn into_forward(self) -> Self {
348+
self.into_orientation(SequenceOrientation::Forward)
349+
}
350+
#[track_caller]
351+
pub fn into_reverse(self) -> Self {
352+
self.into_orientation(SequenceOrientation::Reverse)
353+
}
354+
320355
pub fn contains(&self, loc: &WithOrientation<ContigPosition<C>>) -> bool
321356
where
322357
C: PartialEq,
@@ -358,6 +393,19 @@ pub mod orientation {
358393
}
359394
}
360395
impl<C> WithOrientation<ContigRange<C>> {
396+
pub fn into_start(self) -> WithOrientation<ContigPosition<C>> {
397+
WithOrientation {
398+
orientation: self.orientation,
399+
v: self.v.into_start(),
400+
}
401+
}
402+
pub fn into_end(self) -> WithOrientation<ContigPosition<C>> {
403+
WithOrientation {
404+
orientation: self.orientation,
405+
v: self.v.into_end(),
406+
}
407+
}
408+
361409
pub fn set_orientation_with(&mut self, orientation: SequenceOrientation, size: u64) {
362410
if self.orientation != orientation {
363411
if size == 0 {

0 commit comments

Comments
 (0)