pub struct Coordinate<S>where
S: System,{ /* private fields */ }Expand description
A coordinate.
Implementations§
Source§impl Coordinate<Base>
impl Coordinate<Base>
Sourcepub fn nudge_forward(self) -> Option<Coordinate<Interbase>>
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().
Sourcepub fn nudge_backward(self) -> Option<Coordinate<Interbase>>
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>
impl Coordinate<Interbase>
Sourcepub fn nudge_forward(self) -> Option<Coordinate<Base>>
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().
Sourcepub fn nudge_backward(self) -> Option<Coordinate<Base>>
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>
impl<S> Coordinate<S>
Sourcepub fn new(
contig: impl Into<Contig>,
strand: impl Into<Strand>,
position: impl Into<Position<S>>,
) -> Coordinate<S>
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);Sourcepub fn try_new(
contig: impl Into<Contig>,
strand: impl TryInto<Strand, Error = Error>,
position: u64,
) -> Result<Coordinate<S>, Error>where
Coordinate<S>: Coordinate<S>,
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.
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::Interbase;
let coordinate = "seq0:+:1".parse::<Coordinate<Interbase>>()?;
assert_eq!(coordinate.contig().as_str(), "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::Interbase;
let coordinate = "seq0:+:1".parse::<Coordinate<Interbase>>()?;
assert_eq!(coordinate.into_contig().into_inner(), String::from("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::Interbase;
let coordinate = "seq0:+:1".parse::<Coordinate<Interbase>>()?;
assert_eq!(coordinate.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::Interbase;
let coordinate = "seq0:+:1".parse::<Coordinate<Interbase>>()?;
assert_eq!(coordinate.position().get(), 1);
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::system::Interbase;
let coordinate = "seq0:+:1".parse::<Coordinate<Interbase>>()?;
assert_eq!(coordinate.into_position().get(), 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::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);
Sourcepub fn move_forward(self, magnitude: u64) -> Option<Coordinate<S>>
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:
- a coordinate on the
Strand::Positivemoves positively, and - a coordinate on the
Strand::Negativemove negatively.
§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());
Sourcepub fn move_backward(self, magnitude: u64) -> Option<Coordinate<S>>
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:
- a coordinate on the
Strand::Positivemoves negatively, and - a coordinate on the
Strand::Negativemove positively.
§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());
Sourcepub fn swap_strand(self) -> Coordinate<S>
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>
impl<S> 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 more