Struct bio_types::annot::contig::Contig

source ·
pub struct Contig<R, S> { /* private fields */ }
Expand description

Contiguous sequence region on a particular, named sequence (e.g. a chromosome)

Parameterized over the type of the reference sequence identifier and over the strandedness of the position.

The display format for a Contig is chr:start-end(+/-/.). The boundaries are given as a half-open 0-based interval, like the Rust Range and BED format.

use bio_types::annot::contig::Contig;
use bio_types::strand::ReqStrand;
let tma19 = Contig::new("chrXI".to_owned(), 334412, (334916 - 334412), ReqStrand::Reverse);
let tma19_str = tma19.to_string();
assert_eq!(tma19_str, "chrXI:334412-334916(-)");
let tma19_str_loc = tma19_str.parse()?;
assert_eq!(tma19, tma19_str_loc);

Implementations§

source§

impl<R, S> Contig<R, S>

source

pub fn new(refid: R, start: isize, length: usize, strand: S) -> Self

Construct a new sequence contig location

use std::rc::Rc;
use bio_types::annot::contig::Contig;
use bio_types::strand::ReqStrand;
let chr = Rc::new("chrX".to_owned());
let tma22 = Contig::new(chr, 461829, 462426 - 461829, ReqStrand::Forward);
source

pub fn with_first_length( pos: &Pos<R, S>, length: usize, ) -> Result<Self, AnnotError>
where R: Clone, S: Into<Option<ReqStrand>> + Copy,

Construct a new sequence contig location from a starting position and length.

In general, the starting position must have a “strandedness”, and reverse-strand starting positions will extend towards lower coordinates from the starting position.

use bio_types::annot::contig::Contig;
use bio_types::annot::pos::Pos;
use bio_types::strand::ReqStrand;

let tma22_first = Pos::new("chrX".to_string(), 461829, ReqStrand::Forward);
let tma22 = Contig::with_first_length(&tma22_first, 462426 - 461829)?;
assert_eq!(tma22.to_string(), "chrX:461829-462426(+)");

let tma19_first = Pos::new("chrXI".to_string(), 335015, ReqStrand::Reverse);
let tma19 = Contig::with_first_length(&tma19_first, 335016 - 334412)?;
assert_eq!(tma19.to_string(), "chrXI:334412-335016(-)");
source

pub fn into_stranded(self, strand: ReqStrand) -> Contig<R, ReqStrand>

Convert into a stranded sequence location on the specified strand

source§

impl<R> Contig<R, ReqStrand>

source

pub fn extend_upstream(&mut self, dist: usize)

Extend the annotation by dist in the upstream direction on the annotated strand.

§Arguments
  • dist specifies the offset for sliding the position. The left, 5’-most end of the contig will expand for forward-strand annotations and the right, 3’-most end will expand for reverse-strand annotations.
use bio_types::annot::contig::Contig;
use bio_types::strand::ReqStrand;
let mut tma22 = Contig::new("chrX".to_owned(), 461829, 462426 - 461829, ReqStrand::Forward);
tma22.extend_upstream(100);
assert_eq!(tma22.to_string(), "chrX:461729-462426(+)");
let mut tma19 = Contig::new("chrXI".to_owned(), 334412, 334916 - 334412, ReqStrand::Reverse);
tma19.extend_upstream(100);
assert_eq!(tma19.to_string(), "chrXI:334412-335016(-)");
source

pub fn extend_downstream(&mut self, dist: usize)

Extend the annotation by dist in the downstream direction on the annotated strand.

§Arguments
  • dist specifies the offset for sliding the position. The right, 3’-most end of the contig will expand for forward-strand annotations and the left, 5’-most end will expand for reverse-strand annotations.
use bio_types::annot::contig::Contig;
use bio_types::strand::ReqStrand;
let mut tma22 = Contig::new("chrX".to_owned(), 461829, 462426 - 461829, ReqStrand::Forward);
tma22.extend_downstream(100);
assert_eq!(tma22.to_string(), "chrX:461829-462526(+)");
let mut tma19 = Contig::new("chrXI".to_owned(), 334412, 334916 - 334412, ReqStrand::Reverse);
tma19.extend_downstream(100);
assert_eq!(tma19.to_string(), "chrXI:334312-334916(-)");

Trait Implementations§

source§

impl<R: Clone, S: Clone> Clone for Contig<R, S>

source§

fn clone(&self) -> Contig<R, S>

Returns a copy 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<R: Debug, S: Debug> Debug for Contig<R, S>

source§

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

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

impl<R, S> Display for Contig<R, S>
where R: Display, S: Display + Clone + Into<Strand>,

source§

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

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

impl<R> From<Contig<R, NoStrand>> for Contig<R, Strand>

source§

fn from(x: Contig<R, NoStrand>) -> Self

Converts to this type from the input type.
source§

impl<R> From<Contig<R, ReqStrand>> for Contig<R, NoStrand>

source§

fn from(x: Contig<R, ReqStrand>) -> Self

Converts to this type from the input type.
source§

impl<R> From<Contig<R, ReqStrand>> for Contig<R, Strand>

source§

fn from(x: Contig<R, ReqStrand>) -> Self

Converts to this type from the input type.
source§

impl<R> From<Contig<R, Strand>> for Contig<R, NoStrand>

source§

fn from(x: Contig<R, Strand>) -> Self

Converts to this type from the input type.
source§

impl<R, S> FromStr for Contig<R, S>
where R: From<String>, S: FromStr<Err = StrandError>,

§

type Err = ParseAnnotError

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

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

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

impl<R: Hash, S: Hash> Hash for Contig<R, S>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<R, S> Loc for Contig<R, S>

§

type RefID = R

§

type Strand = S

source§

fn refid(&self) -> &R

Name of the reference sequence (chromosome name, etc.)
source§

fn start(&self) -> isize

Starting (lowest, left-most, 5’-most) position on the reference sequence (0-based).
source§

fn length(&self) -> usize

Length of the region
source§

fn strand(&self) -> S
where S: Copy,

Strand of the position
source§

fn pos_into<T>(&self, pos: &Pos<Self::RefID, T>) -> Option<Pos<(), T>>
where Self::RefID: Eq, Self::Strand: Into<ReqStrand> + Copy, T: Neg<Output = T> + Copy,

Map a sequence position on a reference sequence into a relative position within an annotated location on the reference sequence. Read more
source§

fn pos_outof<Q, T>(&self, pos: &Pos<Q, T>) -> Option<Pos<Self::RefID, T>>
where Self::RefID: Clone, Self::Strand: Into<ReqStrand> + Copy, T: Neg<Output = T> + Copy,

Map a relative position within an annotated location out of that location onto the enclosing reference sequence. Read more
source§

fn contig_intersection<T>( &self, contig: &Contig<Self::RefID, T>, ) -> Option<Self>
where Self::RefID: PartialEq + Clone, Self::Strand: Copy,

source§

impl<R: PartialEq, S: PartialEq> PartialEq for Contig<R, S>

source§

fn eq(&self, other: &Contig<R, 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<R: Eq, S: Eq> Eq for Contig<R, S>

source§

impl<R, S> StructuralPartialEq for Contig<R, S>

Auto Trait Implementations§

§

impl<R, S> Freeze for Contig<R, S>
where R: Freeze, S: Freeze,

§

impl<R, S> RefUnwindSafe for Contig<R, S>

§

impl<R, S> Send for Contig<R, S>
where R: Send, S: Send,

§

impl<R, S> Sync for Contig<R, S>
where R: Sync, S: Sync,

§

impl<R, S> Unpin for Contig<R, S>
where R: Unpin, S: Unpin,

§

impl<R, S> UnwindSafe for Contig<R, S>
where R: UnwindSafe, 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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

§

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§

default 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>,

§

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>,

§

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.