pub struct Coordinate<S: System> { /* private fields */ }Expand description
A coordinate within a genome consisting of a contig, a strand, and a position.
Implementations§
source§impl Coordinate<Zero>
impl Coordinate<Zero>
sourcepub fn lower_bound<C: TryInto<Contig>>(contig: C) -> Self
pub fn lower_bound<C: TryInto<Contig>>(contig: C) -> Self
Creates a new Coordinate with a
Value::LowerBound.
Note that a lower bound position can only sit on the
Strand::Negative, so this hardcodes the strand to
Strand::Negative.
§Examples
use omics_coordinate::Coordinate;
use omics_coordinate::Strand;
use omics_coordinate::system::Zero;
let coordinate = Coordinate::<Zero>::lower_bound("seq0");
source§impl<S: System> Coordinate<S>
impl<S: System> Coordinate<S>
sourcepub fn try_new<C: TryInto<Contig>, Q: TryInto<Strand>, P: TryInto<Position<S>>>(
contig: C,
strand: Q,
position: P,
) -> Result<Self>
pub fn try_new<C: TryInto<Contig>, Q: TryInto<Strand>, P: TryInto<Position<S>>>( contig: C, strand: Q, position: P, ) -> Result<Self>
Attempts to create a new Coordinate.
Note that a lower bound position can only sit on the
Strand::Negative, so trying to create a Coordinate with a lower
bound position on any non-negative strand will result in an
Error::LowerBoundOnNonNegativeStrand.
§Examples
use omics_coordinate::Coordinate;
use omics_coordinate::Strand;
use omics_coordinate::system::Zero;
let coordinate = Coordinate::<Zero>::try_new("seq0", "+", 1)?;
sourcepub fn contig(&self) -> &Contig
pub fn contig(&self) -> &Contig
Gets the Contig for this Coordinate by reference.
§Examples
use omics_coordinate::Coordinate;
use omics_coordinate::system::Zero;
let coordinate = "seq0:+:1".parse::<Coordinate<Zero>>()?;
assert_eq!(coordinate.contig().inner(), "seq0");
sourcepub fn into_contig(self) -> Contig
pub fn into_contig(self) -> Contig
Consumes self and returns the inner Contig from this
Coordinate.
§Examples
use omics_coordinate::Coordinate;
use omics_coordinate::system::Zero;
let coordinate = "seq0:+:1".parse::<Coordinate<Zero>>()?;
assert_eq!(coordinate.into_contig().inner(), "seq0");
sourcepub fn strand(&self) -> &Strand
pub fn strand(&self) -> &Strand
Gets the Strand for this Coordinate by reference.
§Examples
use omics_coordinate::Coordinate;
use omics_coordinate::Strand;
use omics_coordinate::system::Zero;
let coordinate = "seq0:+:1".parse::<Coordinate<Zero>>()?;
assert_eq!(coordinate.strand(), &Strand::Positive);
sourcepub fn into_strand(self) -> Strand
pub fn into_strand(self) -> Strand
Consumes self and returns the inner Strand from this
Coordinate.
§Examples
use omics_coordinate::Coordinate;
use omics_coordinate::Strand;
use omics_coordinate::system::Zero;
let coordinate = "seq0:+:1".parse::<Coordinate<Zero>>()?;
assert_eq!(coordinate.into_strand(), Strand::Positive);
sourcepub fn position(&self) -> &Position<S>
pub fn position(&self) -> &Position<S>
Gets the Position for this Coordinate by reference.
§Examples
use omics_coordinate::Coordinate;
use omics_coordinate::Position;
use omics_coordinate::system::Zero;
let coordinate = "seq0:+:1".parse::<Coordinate<Zero>>()?;
assert_eq!(coordinate.position(), &"1".parse::<Position<Zero>>()?);
sourcepub fn into_position(self) -> Position<S>
pub fn into_position(self) -> Position<S>
Consumes self and returns the inner Position from this
Coordinate.
§Examples
use omics_coordinate::Coordinate;
use omics_coordinate::Strand;
use omics_coordinate::position::Value;
use omics_coordinate::system::Zero;
let coordinate = "seq0:+:1".parse::<Coordinate<Zero>>()?;
let (contig, strand, position) = coordinate.into_parts();
assert_eq!(contig.inner(), "seq0");
assert_eq!(strand, Strand::Positive);
assert_eq!(position.inner(), &Value::Usize(1));
sourcepub fn into_parts(self) -> (Contig, Strand, Position<S>)
pub fn into_parts(self) -> (Contig, Strand, Position<S>)
Consumes self to return the parts that comprise this Coordinate.
§Examples
use omics_coordinate::Coordinate;
use omics_coordinate::position::Value;
use omics_coordinate::system::Zero;
let coordinate = "seq0:+:1".parse::<Coordinate<Zero>>()?;
assert_eq!(coordinate.into_position().inner(), &Value::Usize(1));
sourcepub fn move_forward(self, magnitude: usize) -> Result<Option<Coordinate<S>>>
pub fn move_forward(self, magnitude: usize) -> Result<Option<Coordinate<S>>>
Consumes the Coordinate to attempt to move the coordinate forward by
a specified magnitude.
A checked add (for positive strand) or subtract (for negative strand) is performed to ensure we don’t overflow.
Note that, though the position is checked for usize overflow, we don’t do any bounds checking to make sure that the coordinates fall within any given interval.
§Examples
use omics_coordinate::Coordinate;
use omics_coordinate::Strand;
use omics_coordinate::system::Zero;
let coordinate = "seq0:+:0".parse::<Coordinate<Zero>>()?;
let result = coordinate.move_forward(10)?.unwrap();
sourcepub fn move_backward(self, magnitude: usize) -> Result<Option<Coordinate<S>>>
pub fn move_backward(self, magnitude: usize) -> Result<Option<Coordinate<S>>>
Consumes the Coordinate to attempt to move the coordinate backward
by a specified magnitude.
A checked sub (for positive strand) or add (for negative strand) is performed to ensure we don’t overflow.
Note that, though the position is checked for usize overflow, we don’t do any bounds checking to make sure that the coordinates fall within any given interval.
§Examples
use omics_coordinate::Coordinate;
use omics_coordinate::Strand;
use omics_coordinate::system::Zero;
let coordinate = "seq0:+:0".parse::<Coordinate<Zero>>()?;
let result = coordinate.move_forward(10)?.unwrap();
sourcepub fn move_forward_checked_bounds(
self,
magnitude: usize,
interval: &Interval<S>,
) -> Result<Option<Coordinate<S>>>
pub fn move_forward_checked_bounds( self, magnitude: usize, interval: &Interval<S>, ) -> Result<Option<Coordinate<S>>>
Consumes self to attempt to move the Coordinate forward by the
specified magnitude while also performing a bounds check within the
provided interval.
The following steps are performed:
- First, the coordinate is moved forward by the specified magnitude. During this move, the position is checked for overflows.
- Next, the calculated result is checked to ensure it falls within the
specified interval. This is to ensure that, although the
usizelimits may not broken, the interval continues to contain the moved coordinate.
§Examples
use omics_coordinate::system::Zero;
use omics_coordinate::Coordinate;
use omics_coordinate::Interval;
use omics_coordinate::position::Value;
use omics_coordinate::Strand;
// Positive-stranded coordinate that falls within the provided interval.
let mut coordinate = Coordinate::<Zero>::try_new("seq0", Strand::Positive, 0)?;
let interval = "seq0:+:0-1000".parse::<Interval<Zero>>()?;
let result = coordinate
.move_forward_checked_bounds(10, &interval)
.unwrap()
.unwrap();
assert_eq!(result.contig().inner(), "seq0");
assert_eq!(result.position().inner(), &Value::Usize(10));
assert_eq!(result.strand(), &Strand::Positive);
// Negative-stranded position that falls within the provided interval.
let coordinate = Coordinate::try_new("seq0", Strand::Negative, 1000)?;
let interval = "seq0:-:1000-0".parse::<Interval<Zero>>()?;
let result = coordinate
.move_forward_checked_bounds(10, &interval)
.unwrap()
.unwrap();
assert_eq!(result.contig().inner(), "seq0");
assert_eq!(result.position().inner(), &Value::Usize(990));
assert_eq!(result.strand(), &Strand::Negative);
// Positive-stranded position that _does not_ fall within the provided interval.
let coordinate = Coordinate::try_new("seq0", Strand::Positive, 0)?;
let interval = "seq0:+:0-10".parse::<Interval<Zero>>()?;
let result = coordinate.move_forward_checked_bounds(10, &interval).unwrap();
assert_eq!(result, None);
// Negative-stranded position that _does not_ fall within the provided interval.
let coordinate = Coordinate::try_new("seq0", Strand::Negative, 10)?;
let interval = "seq0:-:10-0".parse::<Interval<Zero>>()?;
let result = coordinate.move_forward_checked_bounds(10, &interval).unwrap();
assert_eq!(result, None);
// Lower-bound position that _does not_ fall within interval
// (and also would not move forward due to underflow).
let coordinate = Coordinate::<Zero>::lower_bound("seq0");
let interval = "seq0:-:10-[".parse::<Interval<Zero>>()?;
let result = coordinate.move_forward_checked_bounds(1, &interval).unwrap();
assert_eq!(result, None);
sourcepub fn move_backward_checked_bounds(
self,
magnitude: usize,
interval: &Interval<S>,
) -> Result<Option<Coordinate<S>>>
pub fn move_backward_checked_bounds( self, magnitude: usize, interval: &Interval<S>, ) -> Result<Option<Coordinate<S>>>
Consumes self to attempt to move the Coordinate backward by the
specified magnitude while also performing a bounds check within the
provided interval.
The following steps are performed:
- First, the coordinate is moved backward by the specified magnitude. During this move, the position is checked for overflows.
- Next, the calculated result is checked to ensure it falls within the
specified interval. This is to ensure that, although the
usizelimits may not broken, the interval continues to contain the moved coordinate.
§Examples
use omics_coordinate::system::Zero;
use omics_coordinate::Coordinate;
use omics_coordinate::Interval;
use omics_coordinate::position::Value;
use omics_coordinate::Strand;
// Positive-stranded coordinate that falls within the provided interval.
let mut coordinate = Coordinate::<Zero>::try_new("seq0", Strand::Positive, 10)?;
let interval = "seq0:+:0-1000".parse::<Interval<Zero>>()?;
let result = coordinate
.move_backward_checked_bounds(10, &interval)
.unwrap()
.unwrap();
assert_eq!(result.contig().inner(), "seq0");
assert_eq!(result.position().inner(), &Value::Usize(0));
assert_eq!(result.strand(), &Strand::Positive);
// Negative-stranded position that falls within the provided interval.
let coordinate = Coordinate::try_new("seq0", Strand::Negative, 990)?;
let interval = "seq0:-:1000-0".parse::<Interval<Zero>>()?;
let result = coordinate
.move_backward_checked_bounds(10, &interval)
.unwrap()
.unwrap();
assert_eq!(result.contig().inner(), "seq0");
assert_eq!(result.position().inner(), &Value::Usize(1000));
assert_eq!(result.strand(), &Strand::Negative);
// Positive-stranded position that _does not_ fall within the provided interval.
let coordinate = Coordinate::try_new("seq0", Strand::Positive, 0)?;
let interval = "seq0:+:0-10".parse::<Interval<Zero>>()?;
let result = coordinate.move_backward_checked_bounds(1, &interval).unwrap();
assert_eq!(result, None);
// Negative-stranded position that _does not_ fall within the provided interval.
let coordinate = Coordinate::try_new("seq0", Strand::Negative, 10)?;
let interval = "seq0:-:10-0".parse::<Interval<Zero>>()?;
let result = coordinate.move_backward_checked_bounds(1, &interval).unwrap();
assert_eq!(result, None);
// Lower-bound position that _does not_ fall within interval
// (and also would not move forward due to underflow).
let coordinate = Coordinate::<Zero>::lower_bound("seq0");
let interval = "seq0:-:10-[".parse::<Interval<Zero>>()?;
let result = coordinate
.move_backward_checked_bounds(1, &interval)
.unwrap()
.unwrap();
assert_eq!(result.contig().inner(), "seq0");
assert_eq!(result.position().inner(), &Value::Usize(0));
assert_eq!(result.strand(), &Strand::Negative);
sourcepub fn swap_strand(self) -> Result<Coordinate<S>>
pub fn swap_strand(self) -> Result<Coordinate<S>>
Consumes self to swap the Strand of the Coordinate without
modifying the contig or the position.
§Examples
use omics_coordinate::Coordinate;
use omics_coordinate::Strand;
use omics_coordinate::position::Value;
use omics_coordinate::system::Zero;
// Swapping a positive-stranded position to a negative-stranded position.
let coordinate = "seq0:+:1000".parse::<Coordinate<Zero>>()?;
let swapped = coordinate.swap_strand()?;
assert_eq!(swapped.contig().inner(), "seq0");
assert_eq!(swapped.strand(), &Strand::Negative);
assert_eq!(swapped.position().inner(), &Value::Usize(1000));
// Swapping a negative-stranded position to a positive-stranded position.
let coordinate = "seq0:-:1000".parse::<Coordinate<Zero>>()?;
let swapped = coordinate.swap_strand()?;
assert_eq!(swapped.contig().inner(), "seq0");
assert_eq!(swapped.strand(), &Strand::Positive);
assert_eq!(swapped.position().inner(), &Value::Usize(1000));
// Failing to swap the lower bound.
let coordinate = "seq0:-:[".parse::<Coordinate<Zero>>()?;
let err = coordinate.swap_strand().unwrap_err();
assert_eq!(
err.to_string(),
String::from(
"attempted to place lower bound position on non-negative strand for coordinate"
)
);
Trait Implementations§
source§impl<S: Clone + System> Clone for Coordinate<S>
impl<S: Clone + System> Clone for Coordinate<S>
source§fn clone(&self) -> Coordinate<S>
fn clone(&self) -> Coordinate<S>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<S: System> Display for Coordinate<S>
impl<S: System> Display for Coordinate<S>
source§impl<S: System> FromStr for Coordinate<S>
impl<S: System> FromStr for Coordinate<S>
impl<S: Eq + System> Eq for Coordinate<S>
impl<S: System> StructuralPartialEq for Coordinate<S>
Auto Trait Implementations§
impl<S> Freeze for Coordinate<S>where
S: Freeze,
impl<S> RefUnwindSafe for Coordinate<S>where
S: RefUnwindSafe,
impl<S> Send for Coordinate<S>where
S: Send,
impl<S> Sync for Coordinate<S>where
S: Sync,
impl<S> Unpin for Coordinate<S>where
S: Unpin,
impl<S> UnwindSafe for Coordinate<S>where
S: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)