Interval

Struct Interval 

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

An interval.

Implementations§

Source§

impl Interval<Base>

Source

pub fn into_equivalent_interbase(self) -> Interval<Interbase>

Consumes self and returns the equivalent interbase interval.

§Examples
use omics_coordinate::Interval;
use omics_coordinate::system::Base;
use omics_coordinate::system::Interbase;

let interval = "seq0:+:1-1000".parse::<Interval<Base>>()?;
let equivalent = interval.into_equivalent_interbase();

assert_eq!("seq0:+:0-1000".parse::<Interval<Interbase>>()?, equivalent);
Source§

impl Interval<Interbase>

Source

pub fn contains_next_entity(&self, coordinate: Coordinate) -> Option<bool>

Checks whether the interbase interval contains the entity after the specified interbase coordinate.

This method returns an Option because the next coordinate may or may not be a valid position—if you’d like to handle that separately, you can do so with the check on the option.

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

let interval = "seq0:+:10-1000".parse::<Interval<Interbase>>()?;

assert!(
    !interval
        .contains_next_entity("seq0:+:9".parse::<Coordinate<Interbase>>()?)
        .unwrap()
);

assert!(
    interval
        .contains_next_entity("seq0:+:10".parse::<Coordinate<Interbase>>()?)
        .unwrap()
);

assert!(
    interval
        .contains_next_entity("seq0:+:999".parse::<Coordinate<Interbase>>()?)
        .unwrap()
);

assert!(
    !interval
        .contains_next_entity("seq0:+:1000".parse::<Coordinate<Interbase>>()?)
        .unwrap()
);
Source

pub fn contains_prev_entity(&self, coordinate: Coordinate) -> Option<bool>

Checks whether the interbase interval contains the entity before the specified interbase coordinate.

This method returns an Option because the next coordinate may or may not be a valid position—if you’d like to handle that separately, you can do so with the check on the option.

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

let interval = "seq0:+:10-1000".parse::<Interval<Interbase>>()?;

assert!(
    !interval
        .contains_prev_entity("seq0:+:10".parse::<Coordinate<Interbase>>()?)
        .unwrap()
);

assert!(
    interval
        .contains_prev_entity("seq0:+:11".parse::<Coordinate<Interbase>>()?)
        .unwrap()
);

assert!(
    interval
        .contains_prev_entity("seq0:+:1000".parse::<Coordinate<Interbase>>()?)
        .unwrap()
);

assert!(
    !interval
        .contains_prev_entity("seq0:+:1001".parse::<Coordinate<Interbase>>()?)
        .unwrap()
);
Source

pub fn into_equivalent_base(self) -> Interval<Base>

Consumes self and returns the equivalent in-base interval.

§Examples
use omics_coordinate::Interval;
use omics_coordinate::system::Base;
use omics_coordinate::system::Interbase;

let interval = "seq0:+:0-1000".parse::<Interval<Interbase>>()?;
let equivalent = interval.into_equivalent_base();

assert_eq!("seq0:+:1-1000".parse::<Interval<Base>>()?, equivalent);
Source§

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

Source

pub fn try_new(start: Coordinate<S>, end: Coordinate<S>) -> Result<Interval<S>>

Creates a new interval if the following invariants are upheld.

  • The contigs of the two coordinates must match.
  • The strands of the two coordinates must match.
  • The start must come before or be equal to the end in that (a) on positive strand, start <= end, or, (b) on the negative strand, end <= start. This ensures that the interval is always oriented from start to end of the molecule.
§Examples
use omics_coordinate::Coordinate;
use omics_coordinate::Interval;
use omics_coordinate::system::Base;
use omics_coordinate::system::Interbase;

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

// Positive strand.

let start = Coordinate::<Interbase>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Interbase>::try_new("seq0", "+", 20)?;
let interval = Interval::try_new(start, end)?;

// Negative strand.

let start = Coordinate::<Interbase>::try_new("seq0", "-", 20)?;
let end = Coordinate::<Interbase>::try_new("seq0", "-", 10)?;
let interval = Interval::try_new(start, end)?;

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

// Positive strand.

let start = Coordinate::<Base>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Base>::try_new("seq0", "+", 20)?;
let interval = Interval::try_new(start, end)?;

// Negative strand.

let start = Coordinate::<Base>::try_new("seq0", "-", 20)?;
let end = Coordinate::<Base>::try_new("seq0", "-", 10)?;
let interval = Interval::try_new(start, end)?;
Source

pub fn start(&self) -> &Coordinate<S>

Gets a reference to the start coordinate.

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

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

let start = Coordinate::<Interbase>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Interbase>::try_new("seq0", "+", 20)?;
let interval = Interval::try_new(start.clone(), end)?;

assert_eq!(interval.start(), &start);

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

let start = Coordinate::<Base>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Base>::try_new("seq0", "+", 20)?;
let interval = Interval::try_new(start.clone(), end)?;

assert_eq!(interval.start(), &start);
Source

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

Consumes self and returns the start coordinate.

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

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

let start = Coordinate::<Interbase>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Interbase>::try_new("seq0", "+", 20)?;
let interval = Interval::try_new(start.clone(), end)?;

assert_eq!(interval.into_start(), start);

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

let start = Coordinate::<Base>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Base>::try_new("seq0", "+", 20)?;
let interval = Interval::try_new(start.clone(), end)?;

assert_eq!(interval.into_start(), start);
Source

pub fn end(&self) -> &Coordinate<S>

Gets a reference to the end coordinate.

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

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

let start = Coordinate::<Interbase>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Interbase>::try_new("seq0", "+", 20)?;
let interval = Interval::try_new(start, end.clone())?;

assert_eq!(interval.end(), &end);

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

let start = Coordinate::<Base>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Base>::try_new("seq0", "+", 20)?;
let interval = Interval::try_new(start, end.clone())?;

assert_eq!(interval.end(), &end);
Source

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

Consumes self and returns the end coordinate.

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

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

let start = Coordinate::<Interbase>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Interbase>::try_new("seq0", "+", 20)?;
let interval = Interval::try_new(start, end.clone())?;

assert_eq!(interval.into_end(), end);

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

let start = Coordinate::<Base>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Base>::try_new("seq0", "+", 20)?;
let interval = Interval::try_new(start, end.clone())?;

assert_eq!(interval.into_end(), end);
Source

pub fn into_coordinates(self) -> (Coordinate<S>, Coordinate<S>)

Consumes self and returns the start and end coordinates.

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

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

let start = Coordinate::<Interbase>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Interbase>::try_new("seq0", "+", 20)?;
let interval = Interval::try_new(start.clone(), end.clone())?;
let parts = interval.into_coordinates();

assert_eq!(parts.0, start);
assert_eq!(parts.1, end);

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

let start = Coordinate::<Base>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Base>::try_new("seq0", "+", 20)?;
let interval = Interval::try_new(start.clone(), end.clone())?;
let parts = interval.into_coordinates();

assert_eq!(parts.0, start);
assert_eq!(parts.1, end);
Source

pub fn contig(&self) -> &Contig

Returns a reference to the contig.

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

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

let start = Coordinate::<Interbase>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Interbase>::try_new("seq0", "+", 20)?;
let interval = Interval::try_new(start, end)?;

assert_eq!(interval.contig().as_str(), "seq0");

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

let start = Coordinate::<Base>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Base>::try_new("seq0", "+", 20)?;
let interval = Interval::try_new(start, end)?;

assert_eq!(interval.contig().as_str(), "seq0");
Source

pub fn strand(&self) -> Strand

Returns the strand.

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

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

let start = Coordinate::<Interbase>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Interbase>::try_new("seq0", "+", 20)?;
let interval = Interval::try_new(start, end)?;

assert_eq!(interval.strand(), Strand::Positive);

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

let start = Coordinate::<Base>::try_new("seq0", "-", 20)?;
let end = Coordinate::<Base>::try_new("seq0", "-", 10)?;
let interval = Interval::try_new(start, end)?;

assert_eq!(interval.strand(), Strand::Negative);
Source

pub fn contains_coordinate(&self, coordinate: &Coordinate<S>) -> bool

Returns whether or not a coordinate is contained within this interval. Notably, when checked whether coordinates are included in the interval, both the start and end positions are considered inclusive.

§Caution

**This is not the method you want to use when checking if a nucleotide or amino acid at a particular position is included in the interval. This checks the coordinates themselves and, in-so-doing, considers both the start and the end positions of the interval to be inclusive.

If you’d like to check whether a particular nucleotide, amino acid, or other entity is contained within the interval, use the contains_entity() method.

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

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

let start = Coordinate::<Interbase>::try_new("seq0", "+", 0)?;
let end = Coordinate::<Interbase>::try_new("seq0", "+", 10)?;
let interval = Interval::try_new(start, end)?;

// Coordinates on the same contig, strand, and within the interval's range
// are contained within the interval.
assert!(interval.contains_coordinate(&Coordinate::try_new("seq0", "+", 0)?));
assert!(interval.contains_coordinate(&Coordinate::try_new("seq0", "+", 5)?));
assert!(interval.contains_coordinate(&Coordinate::try_new("seq0", "+", 10)?));

// Coordinates on different contigs, strands, or outside the range are
// not contained within the interval.
assert!(!interval.contains_coordinate(&Coordinate::try_new("seq1", "+", 5)?));
assert!(!interval.contains_coordinate(&Coordinate::try_new("seq0", "-", 5)?));
assert!(!interval.contains_coordinate(&Coordinate::try_new("seq0", "+", 11)?));

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

let start = Coordinate::<Interbase>::try_new("seq0", "+", 1)?;
let end = Coordinate::<Interbase>::try_new("seq0", "+", 10)?;
let interval = Interval::try_new(start, end)?;

// Coordinates on the same contig, strand, and within the interval's range
// are contained within the interval.
assert!(interval.contains_coordinate(&Coordinate::try_new("seq0", "+", 1)?));
assert!(interval.contains_coordinate(&Coordinate::try_new("seq0", "+", 5)?));
assert!(interval.contains_coordinate(&Coordinate::try_new("seq0", "+", 10)?));

// Coordinates on different contigs, strands, or outside the range are
// not contained within the interval.
assert!(!interval.contains_coordinate(&Coordinate::try_new("seq1", "+", 5)?));
assert!(!interval.contains_coordinate(&Coordinate::try_new("seq0", "-", 5)?));
assert!(!interval.contains_coordinate(&Coordinate::try_new("seq0", "+", 11)?));
Source

pub fn contains_entity(&self, coordinate: &Coordinate<Base>) -> bool

Returns whether or not the entity at the in-base coordinate is contained within this interval.

/// # Examples

use omics_coordinate::Coordinate;
use omics_coordinate::Interval;
use omics_coordinate::Strand;
use omics_coordinate::system::Base;
use omics_coordinate::system::Interbase;

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

let start = Coordinate::<Interbase>::try_new("seq0", "+", 0)?;
let end = Coordinate::<Interbase>::try_new("seq0", "+", 10)?;
let interval = Interval::try_new(start, end)?;

// Coordinates on the same contig, strand, and within the interval's range
// are contained within the interval.
assert!(interval.contains_coordinate(&Coordinate::try_new("seq0", "+", 0)?));
assert!(interval.contains_coordinate(&Coordinate::try_new("seq0", "+", 5)?));
assert!(interval.contains_coordinate(&Coordinate::try_new("seq0", "+", 10)?));

// Coordinates on different contigs, strands, or outside the range are
// not contained within the interval.
assert!(!interval.contains_coordinate(&Coordinate::try_new("seq1", "+", 5)?));
assert!(!interval.contains_coordinate(&Coordinate::try_new("seq0", "-", 5)?));
assert!(!interval.contains_coordinate(&Coordinate::try_new("seq0", "+", 11)?));

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

let start = Coordinate::<Interbase>::try_new("seq0", "+", 1)?;
let end = Coordinate::<Interbase>::try_new("seq0", "+", 10)?;
let interval = Interval::try_new(start, end)?;

// Coordinates on the same contig, strand, and within the interval's range
// are contained within the interval.
assert!(interval.contains_coordinate(&Coordinate::try_new("seq0", "+", 1)?));
assert!(interval.contains_coordinate(&Coordinate::try_new("seq0", "+", 5)?));
assert!(interval.contains_coordinate(&Coordinate::try_new("seq0", "+", 10)?));

// Coordinates on different contigs, strands, or outside the range are
// not contained within the interval.
assert!(!interval.contains_coordinate(&Coordinate::try_new("seq1", "+", 5)?));
assert!(!interval.contains_coordinate(&Coordinate::try_new("seq0", "-", 5)?));
assert!(!interval.contains_coordinate(&Coordinate::try_new("seq0", "+", 11)?));
Source

pub fn count_entities(&self) -> Number

Counts the number of entities in the interval.

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

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

// Positive strand.

let start = Coordinate::<Interbase>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Interbase>::try_new("seq0", "+", 20)?;
let interval = Interval::try_new(start, end)?;

assert_eq!(interval.count_entities(), 10);

// Negative strand.

let start = Coordinate::<Interbase>::try_new("seq0", "-", 20)?;
let end = Coordinate::<Interbase>::try_new("seq0", "-", 10)?;
let interval = Interval::try_new(start, end)?;

assert_eq!(interval.count_entities(), 10);

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

// Positive strand.

let start = Coordinate::<Base>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Base>::try_new("seq0", "+", 20)?;
let interval = Interval::try_new(start, end)?;

assert_eq!(interval.count_entities(), 11);

// Negative strand.

let start = Coordinate::<Base>::try_new("seq0", "-", 20)?;
let end = Coordinate::<Base>::try_new("seq0", "-", 10)?;
let interval = Interval::try_new(start, end)?;

assert_eq!(interval.count_entities(), 11);
Source

pub fn clamp(self, interval: Interval<S>) -> Result<Interval<S>>

Consumes self and clamps an interval by another interval.

Clamping is an operation whereby the ends of an interval are restricted to the range of the argument passed in with a tendency to restrict towards the middle of the interval.

§Summary
  • If the interval being operated on is completely contained within the argument interval, the interval being operated on is returned.
╔═════╦═════╦═════╦═════╦═════╦═════╦═════╦═════╦═════╦═════╦═════ →
10    11    12    13    14    15    16    17    18    19    20       |
                  ●───────────────────────● [13, 17]                 | Original Interval
      ●───────────────────────────────────────────────● [11, 19]     | Argument Interval
┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
                  ●───────────────────────● [13, 17]                 | Resulting Interval


Here, no modifications were made to the original interval, as neither
the start nor the end of the interval would be restricted by the
argument interval.
  • If the argument interval is completely within the interval being operated on, the argument interval will clamp both sides of the original interval, and the argument interval will be returned.
╔═════╦═════╦═════╦═════╦═════╦═════╦═════╦═════╦═════╦═════╦═════ →
10    11    12    13    14    15    16    17    18    19    20       |
      ●───────────────────────────────────────────────● [11, 19]     | Original Interval
                  ●───────────────────────● [13, 17]                 | Argument Interval
┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
                  ●───────────────────────● [13, 17]                 | Resulting Interval


Here, both the start and the end position of the original interval were
restricted by the start and end of the argument interval respectively.
  • If the argument interval would restrict the length of one side of the subject interval on either end, that end is restricted to the argument interval’s value, whereas the non-restricted end is the original interval’s value.
╔═════╦═════╦═════╦═════╦═════╦═════╦═════╦═════╦═════╦═════╦═════ →
10    11    12    13    14    15    16    17    18    19    20       |
      ●───────────────────────────────────● [11, 17]                 | Original Interval
                  ●───────────────────────● [13, 17]                 | Argument Interval
┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
                  ●───────────────────────● [13, 17]                 | Resulting Interval


Here, the start of the original interval is clamped by the argument
interval's start position. However, the end position of the original
interval is not restricted by the argument interval's end position,
so it remains the same. This results in the latter half of the interval
being clamped.


╔═════╦═════╦═════╦═════╦═════╦═════╦═════╦═════╦═════╦═════╦═════ →
10    11    12    13    14    15    16    17    18    19    20       |
                  ●───────────────────────────────────● [13, 19]     | Original Interval
                  ●───────────────────────● [13, 17]                 | Argument Interval
┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
                  ●───────────────────────● [13, 17]                 | Resulting Interval


Here, the start position of the original interval would not be
restricted by the argument interval's start position, so it remains
the same. However, the end position is clamped by the end position
of the argument interval, so the resulting end position is that of the
argument interval's end position. This results in the first half of
interval being clamped.
§Examples
use omics_coordinate::Coordinate;
use omics_coordinate::Interval;
use omics_coordinate::system::Base;
use omics_coordinate::system::Interbase;

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

let interval = "seq0:+:10-20".parse::<Interval<Interbase>>()?;
let clamped = interval.clamp("seq0:+:5-15".parse::<Interval<Interbase>>()?)?;
assert_eq!(clamped, "seq0:+:10-15".parse::<Interval<Interbase>>()?);

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

let interval = "seq0:-:20-10".parse::<Interval<Base>>()?;
let clamped = interval.clamp("seq0:-:25-15".parse::<Interval<Base>>()?)?;
assert_eq!(clamped, "seq0:-:20-15".parse::<Interval<Base>>()?);

Ok::<(), Box<dyn std::error::Error>>(())
Source

pub fn coordinate_offset(&self, coordinate: &Coordinate<S>) -> Option<Number>

Gets the offset of a coordinate from the start of the interval.

If the coordinate is not contained within the interval, None is returned.

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

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

let start = Coordinate::<Interbase>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Interbase>::try_new("seq0", "+", 20)?;
let interval = Interval::try_new(start, end)?;

let query = Coordinate::<Interbase>::try_new("seq0", "+", 15)?;
assert_eq!(interval.coordinate_offset(&query).unwrap(), 5);

let query = Coordinate::<Interbase>::try_new("seq0", "+", 20)?;
assert_eq!(interval.coordinate_offset(&query).unwrap(), 10);

let query = Coordinate::<Interbase>::try_new("seq0", "+", 21)?;
assert!(interval.coordinate_offset(&query).is_none());

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

let start = Coordinate::<Base>::try_new("seq0", "-", 20)?;
let end = Coordinate::<Base>::try_new("seq0", "-", 10)?;
let interval = Interval::try_new(start, end)?;

let query = Coordinate::<Base>::try_new("seq0", "-", 15)?;
assert_eq!(interval.coordinate_offset(&query).unwrap(), 5);

let query = Coordinate::<Base>::try_new("seq0", "-", 10)?;
assert_eq!(interval.coordinate_offset(&query).unwrap(), 10);

let query = Coordinate::<Base>::try_new("seq0", "-", 9)?;
assert!(interval.coordinate_offset(&query).is_none());

Ok::<(), Box<dyn std::error::Error>>(())
Source

pub fn coordinate_at_offset(&self, offset: Number) -> Option<Coordinate<S>>

Returns the coordinate at the offset within the interval.

This method only returns the coordinate if the coordinate falls within the interval.

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

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

// Positive strand.

let interval = "seq0:+:0-1000".parse::<Interval<Interbase>>()?;

let expected = "seq0:+:5".parse::<Coordinate<Interbase>>()?;
assert_eq!(interval.coordinate_at_offset(5).unwrap(), expected);

let expected = "seq0:+:1000".parse::<Coordinate<Interbase>>()?;
assert_eq!(interval.coordinate_at_offset(1000).unwrap(), expected);

assert!(interval.coordinate_at_offset(1001).is_none());

// Negative strand.

let interval = "seq0:-:1000-0".parse::<Interval<Interbase>>()?;

let expected = "seq0:-:995".parse::<Coordinate<Interbase>>()?;
assert_eq!(interval.coordinate_at_offset(5).unwrap(), expected);

let expected = "seq0:-:0".parse::<Coordinate<Interbase>>()?;
assert_eq!(interval.coordinate_at_offset(1000).unwrap(), expected);

assert_eq!(interval.coordinate_at_offset(1001), None);

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

// Positive strand.

let interval = "seq0:+:1-1000".parse::<Interval<Base>>()?;

let expected = "seq0:+:6".parse::<Coordinate<Base>>()?;
assert_eq!(interval.coordinate_at_offset(5).unwrap(), expected);

let expected = "seq0:+:1000".parse::<Coordinate<Base>>()?;
assert_eq!(interval.coordinate_at_offset(999).unwrap(), expected);

assert!(interval.coordinate_at_offset(1000).is_none());

// Negative strand.

let interval = "seq0:-:1000-1".parse::<Interval<Base>>()?;

let expected = "seq0:-:995".parse::<Coordinate<Base>>()?;
assert_eq!(interval.coordinate_at_offset(5).unwrap(), expected);

let expected = "seq0:-:1".parse::<Coordinate<Base>>()?;
assert_eq!(interval.coordinate_at_offset(999).unwrap(), expected);

assert_eq!(interval.coordinate_at_offset(1000), None);

Ok::<(), Box<dyn std::error::Error>>(())
Source

pub fn reverse_complement(self) -> Interval<S>

Reverse complements the interval, meaning that:

  • the start and end positions are swapped, and
  • the strand is swapped.
§Examples
use omics_coordinate::Coordinate;
use omics_coordinate::Interval;
use omics_coordinate::system::Base;
use omics_coordinate::system::Interbase;

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

let start = Coordinate::<Interbase>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Interbase>::try_new("seq0", "+", 20)?;
let original = Interval::try_new(start, end)?;

let complemented = original.clone().reverse_complement();
assert_eq!(complemented, "seq0:-:20-10".parse::<Interval<Interbase>>()?);

let recomplemented = complemented.reverse_complement();
assert_eq!(recomplemented, original);

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

let start = Coordinate::<Base>::try_new("seq0", "+", 10)?;
let end = Coordinate::<Base>::try_new("seq0", "+", 20)?;
let original = Interval::try_new(start, end)?;

let complemented = original.clone().reverse_complement();
assert_eq!(complemented, "seq0:-:20-10".parse::<Interval<Base>>()?);

let recomplemented = complemented.reverse_complement();
assert_eq!(recomplemented, original);

Ok::<(), Box<dyn std::error::Error>>(())

Trait Implementations§

Source§

impl<S: Clone + System> Clone for Interval<S>

Source§

fn clone(&self) -> Interval<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<S: Debug + System> Debug for Interval<S>

Source§

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

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

impl<S: System> Display for Interval<S>
where Interval<S>: Interval<S>, Position<S>: Position<S>,

Source§

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

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

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

Source§

type Err = Error

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

fn from_str(s: &str) -> Result<Self>

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

impl<S: PartialEq + System> PartialEq for Interval<S>

Source§

fn eq(&self, other: &Interval<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: Eq + System> Eq for Interval<S>

Source§

impl<S: System> StructuralPartialEq for Interval<S>

Auto Trait Implementations§

§

impl<S> Freeze for Interval<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for Interval<S>
where S: RefUnwindSafe,

§

impl<S> Send for Interval<S>
where S: Send,

§

impl<S> Sync for Interval<S>
where S: Sync,

§

impl<S> Unpin for Interval<S>
where S: Unpin,

§

impl<S> UnwindSafe for Interval<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.