Coordinate

Struct Coordinate 

Source
pub struct Coordinate<S>
where S: System,
{ /* private fields */ }
Expand description

A coordinate.

Implementations§

Source§

impl Coordinate<Base>

Source

pub fn nudge_forward(self) -> Option<Coordinate<Interbase>>

Consumes self and attempts to convert the coordinate to the next interbase coordinate.

This is only useful when converting a coordinate to the other coordinate system, which is not a common operation. If, instead, you wish to move the coordinate forward within the same coordinate system, you’re almost certainly looking for move_forward().

Source

pub fn nudge_backward(self) -> Option<Coordinate<Interbase>>

Consumes self and attempts to convert the coordinate to the previous interbase coordinate.

This is only useful when converting a coordinate to the other coordinate system, which is not a common operation. If, instead, you wish to move the coordinate backward within the same coordinate system, you’re almost certainly looking for move_backward().

Source§

impl Coordinate<Interbase>

Source

pub fn nudge_forward(self) -> Option<Coordinate<Base>>

Consumes self and attempts converts the coordinate to the next in-base coordinate.

This is only useful when converting a coordinate to the other coordinate system, which is not a common operation. If, instead, you wish to move the coordinate forward within the same coordinate system, you’re almost certainly looking for move_forward().

Source

pub fn nudge_backward(self) -> Option<Coordinate<Base>>

Consumes self and converts the coordinate to the previous in-base coordinate.

This is only useful when converting a coordinate to the other coordinate system, which is not a common operation. If, instead, you wish to move the coordinate backward within the same coordinate system, you’re almost certainly looking for move_backward().

Source§

impl<S> Coordinate<S>
where S: System, Position<S>: Position<S>,

Source

pub fn new( contig: impl Into<Contig>, strand: impl Into<Strand>, position: impl Into<Position<S>>, ) -> Coordinate<S>

Creates a new coordinate;

§Examples
use omics_coordinate::Contig;
use omics_coordinate::Coordinate;
use omics_coordinate::Strand;
use omics_coordinate::position::interbase::Position;
use omics_coordinate::system::Interbase;

let contig = Contig::new("chr1");
let position = Position::new(0);
let strand = Strand::Positive;

let coordinate = Coordinate::new(contig, strand, position);
Source

pub fn try_new( contig: impl Into<Contig>, strand: impl TryInto<Strand, Error = Error>, position: u64, ) -> Result<Coordinate<S>, Error>
where Coordinate<S>: Coordinate<S>,

Attempts to create a new coordinate.

Source

pub fn contig(&self) -> &Contig

Gets the contig for this coordinate by reference.

§Examples
use omics_coordinate::Coordinate;
use omics_coordinate::system::Interbase;

let coordinate = "seq0:+:1".parse::<Coordinate<Interbase>>()?;
assert_eq!(coordinate.contig().as_str(), "seq0");
Source

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::Interbase;

let coordinate = "seq0:+:1".parse::<Coordinate<Interbase>>()?;
assert_eq!(coordinate.into_contig().into_inner(), String::from("seq0"));
Source

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::Interbase;

let coordinate = "seq0:+:1".parse::<Coordinate<Interbase>>()?;
assert_eq!(coordinate.strand(), Strand::Positive);
Source

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::Interbase;

let coordinate = "seq0:+:1".parse::<Coordinate<Interbase>>()?;
assert_eq!(coordinate.position().get(), 1);
Source

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::system::Interbase;

let coordinate = "seq0:+:1".parse::<Coordinate<Interbase>>()?;
assert_eq!(coordinate.into_position().get(), 1);
Source

pub fn into_parts(self) -> (Contig, Strand, Position<S>)

Consumes self to return the parts that comprise this coordinate.

§Examples
use omics_coordinate::Contig;
use omics_coordinate::Coordinate;
use omics_coordinate::Strand;
use omics_coordinate::system::Interbase;

let coordinate = "seq0:+:1".parse::<Coordinate<Interbase>>()?;

let (contig, strand, position) = coordinate.into_parts();
assert_eq!(contig.into_inner(), String::from("seq0"));
assert_eq!(strand, Strand::Positive);
assert_eq!(position.get(), 1);
Source

pub fn move_forward(self, magnitude: u64) -> Option<Coordinate<S>>

Consumes self and attempts to move the position forward by magnitude.

This method is dependent on the strand of the coordinate:

§Examples
use omics_coordinate::Contig;
use omics_coordinate::Coordinate;
use omics_coordinate::Position;
use omics_coordinate::Strand;
use omics_coordinate::position::Number;
use omics_coordinate::system::Base;
use omics_coordinate::system::Interbase;

// Interbase.

let start = "seq0:+:0".parse::<Coordinate<Interbase>>()?;
let coordinate = start.clone().move_forward(10).expect("coordinate to move");
assert_eq!(coordinate.contig().as_str(), "seq0");
assert_eq!(coordinate.strand(), Strand::Positive);
assert_eq!(coordinate.position().get(), 10);

let coordinate = start.move_forward(Number::MAX).expect("coordinate to move");
assert_eq!(coordinate.contig().as_str(), "seq0");
assert_eq!(coordinate.strand(), Strand::Positive);
assert_eq!(coordinate.position().get(), Number::MAX);

let coordinate = coordinate.move_forward(1);
assert!(coordinate.is_none());

// Base.

let start = "seq0:+:1".parse::<Coordinate<Base>>()?;
let coordinate = start.clone().move_forward(10).expect("coordinate to move");
assert_eq!(coordinate.contig().as_str(), "seq0");
assert_eq!(coordinate.strand(), Strand::Positive);
assert_eq!(coordinate.position().get(), 11);

let coordinate = start
    .move_forward(Number::MAX - 1)
    .expect("coordinate to move");
assert_eq!(coordinate.contig().as_str(), "seq0");
assert_eq!(coordinate.strand(), Strand::Positive);
assert_eq!(coordinate.position().get(), Number::MAX);

let coordinate = coordinate.move_forward(1);
assert!(coordinate.is_none());
Source

pub fn move_backward(self, magnitude: u64) -> Option<Coordinate<S>>

Consumes self and attempts to move the position backwards by magnitude.

This method is dependent on the strand of the coordinate:

§Examples
use omics_coordinate::Contig;
use omics_coordinate::Coordinate;
use omics_coordinate::Position;
use omics_coordinate::Strand;
use omics_coordinate::position::Number;
use omics_coordinate::system::Base;
use omics_coordinate::system::Interbase;

let value = format!("seq0:+:{}", Number::MAX);

// Interbase.

let start = value.clone().parse::<Coordinate<Interbase>>()?;
let coordinate = start.clone().move_backward(10).expect("coordinate to move");
assert_eq!(coordinate.contig().as_str(), "seq0");
assert_eq!(coordinate.strand(), Strand::Positive);
assert_eq!(coordinate.position().get(), Number::MAX - 10);

let coordinate = start
    .move_backward(Number::MAX)
    .expect("coordinate to move");
assert_eq!(coordinate.contig().as_str(), "seq0");
assert_eq!(coordinate.strand(), Strand::Positive);
assert_eq!(coordinate.position().get(), 0);

let coordinate = coordinate.move_backward(1);
assert!(coordinate.is_none());

// Base.

let start = value.parse::<Coordinate<Base>>()?;
let coordinate = start.clone().move_backward(10).expect("coordinate to move");
assert_eq!(coordinate.contig().as_str(), "seq0");
assert_eq!(coordinate.strand(), Strand::Positive);
assert_eq!(coordinate.position().get(), Number::MAX - 10);

let coordinate = start
    .move_backward(Number::MAX - 1)
    .expect("coordinate to move");
assert_eq!(coordinate.contig().as_str(), "seq0");
assert_eq!(coordinate.strand(), Strand::Positive);
assert_eq!(coordinate.position().get(), 1);

let coordinate = coordinate.move_backward(1);
assert!(coordinate.is_none());
Source

pub fn swap_strand(self) -> Coordinate<S>

Swaps the strand of the coordinate.

§Examples
use omics_coordinate::Coordinate;
use omics_coordinate::Strand;
use omics_coordinate::system::Base;
use omics_coordinate::system::Interbase;

//===========//
// Interbase //
//===========//

let coordinate = Coordinate::<Interbase>::try_new("seq0", "+", 10)?;
let swapped = coordinate.swap_strand();
assert_eq!(swapped.contig().as_str(), "seq0");
assert_eq!(swapped.strand(), Strand::Negative);
assert_eq!(swapped.position().get(), 10);

//======//
// Base //
//======//

let coordinate = Coordinate::<Base>::try_new("seq0", "-", 10)?;
let swapped = coordinate.swap_strand();
assert_eq!(swapped.contig().as_str(), "seq0");
assert_eq!(swapped.strand(), Strand::Positive);
assert_eq!(swapped.position().get(), 10);

Trait Implementations§

Source§

impl<S> Clone for Coordinate<S>
where S: Clone + System,

Source§

fn clone(&self) -> Coordinate<S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Coordinate<Base> for Coordinate<Base>

Source§

fn try_new( contig: impl Into<Contig>, strand: impl TryInto<Strand, Error = Error>, position: u64, ) -> Result<Coordinate<Base>, Error>

Attempts to create a new coordinate.
Source§

impl Coordinate<Interbase> for Coordinate<Interbase>

Source§

fn try_new( contig: impl Into<Contig>, strand: impl TryInto<Strand, Error = Error>, position: u64, ) -> Result<Coordinate<Interbase>, Error>

Attempts to create a new coordinate.
Source§

impl<S> Debug for Coordinate<S>
where S: Debug + System,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<S> Display for Coordinate<S>
where S: System,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<S> FromStr for Coordinate<S>
where S: System, Position<S>: Position<S>,

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Coordinate<S>, Error>

Parses a string s to return a value of this type. Read more
Source§

impl<S> Ord for Coordinate<S>
where S: Ord + System,

Source§

fn cmp(&self, other: &Coordinate<S>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<S> PartialEq for Coordinate<S>
where S: PartialEq + System,

Source§

fn eq(&self, other: &Coordinate<S>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S> PartialOrd for Coordinate<S>
where S: PartialOrd + System,

Source§

fn partial_cmp(&self, other: &Coordinate<S>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<S> Eq for Coordinate<S>
where S: Eq + System,

Source§

impl<S> StructuralPartialEq for Coordinate<S>
where S: System,

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.