Contig

Struct Contig 

Source
pub struct Contig { /* private fields */ }
Expand description

The contig data, such as identifiers and its length.

Implementations§

Source§

impl Contig

Source

pub fn name(&self) -> &str

Get the main name of the contig (e.g. 10, X, MT).

Source

pub fn builder() -> ContigBuilder<Uninit>

Get a builder to build the Contig.

§Example

Build a contig from the minimal required attributes.

use dabuild::Contig;

let contig = Contig::builder().name("Y").length(57_227_415u32).build();

assert_eq!(contig.name(), "Y");
assert_eq!(contig.length(), 57_227_415)

Build a contig with optional attributes, including GenBank, RefSeq, and UCSC accession identifiers.

use dabuild::Contig;

let contig = Contig::builder()
                .length(57_227_415u32)
                .name("Y")
                .genbank_name("CM000686.2")
                .refseq_name("NC_000024.10")
                .ucsc_name("chrY")
                .build();

 assert_eq!(contig.name(), "Y");
 assert_eq!(contig.length(), 57_227_415);
 assert_eq!(contig.genbank_name().unwrap(), "CM000686.2");
 assert_eq!(contig.refseq_name().unwrap(), "NC_000024.10");
 assert_eq!(contig.ucsc_name().unwrap(), "chrY");
Source

pub fn alt_names(&self) -> impl Iterator<Item = &str>

Get the alternative contig identifiers.

For instance, CM000686.2, NC_000024.10, and chrY for chromosome Y.

§Example
use dabuild::Contig;

let contig = Contig::builder()
                .length(57_227_415u32)
                .name("Y")
                .genbank_name("CM000686.2")
                .refseq_name("NC_000024.10")
                .ucsc_name("chrY")
                .build();

let alt_names: Vec<_> = contig.alt_names().collect();
assert_eq!(&alt_names, &["CM000686.2", "NC_000024.10", "chrY"]);
Source

pub fn genbank_name(&self) -> Option<&str>

Get the GenBank contig identifier, if available.

For instance, CM000686.2 for chromosome Y of the GRCh38.p13 assembly.

§Example
use dabuild::Contig;

let contig = Contig::builder()
                .name("Y")
                .length(57_227_415u32)
                .genbank_name("CM000686.2")
                .build();

assert_eq!(contig.genbank_name(), Some("CM000686.2"));
Source

pub fn refseq_name(&self) -> Option<&str>

Get the RefSeq contig identifier, if available.

For instance, NC_000024.10 for chromosome Y of the GRCh38.p13 assembly.

§Example
use dabuild::Contig;

let contig = Contig::builder()
                .name("Y")
                .length(57_227_415u32)
                .refseq_name("NC_000024.10")
                .build();

assert_eq!(contig.refseq_name(), Some("NC_000024.10"));
Source

pub fn ucsc_name(&self) -> Option<&str>

Get the UCSC contig identifier, if available.

For instance, chrY for chromosome Y of the GRCh38.p13 assembly.

§Example
use dabuild::Contig;

let contig = Contig::builder()
                .name("Y")
                .length(57_227_415u32)
                .ucsc_name("chrY")
                .build();

assert_eq!(contig.ucsc_name(), Some("chrY"));
Source

pub fn length(&self) -> u32

Get the number of bases of the contig, a.k.a. its length.

Source

pub fn transpose_coordinate(&self, other: u32) -> Option<u32>

Transpose coordinate on a double-stranded sequence to the opposite strand.

Returns None if the operation would lead to an overflow.

Source

pub fn new( name: impl ToString, alt_names: &[impl ToString], length: u32, ) -> Option<Self>

👎Deprecated since 0.3.1: use Contig::builder() instead

Create a Contig from name, the alternative names, and its length.

§Example

Create a Contig with fields from the GRC assembly report:

use dabuild::Contig;

let contig = Contig::new("Y", &["CM000686.2", "NC_000024.10", "chrY"], 57_227_415);

assert!(contig.is_some());
let contig = contig.unwrap();
assert_eq!(contig.name(), "Y");
assert_eq!(contig.genbank_name(), Some("CM000686.2"));

Create a Contig with sequence name and UCSC accession:

use dabuild::Contig;

let contig = Contig::new("Y", &["na", "", "chrY"], 57_227_415);

assert!(contig.is_some());

let contig = contig.unwrap();
assert_eq!(contig.name(), "Y");
assert!(contig.genbank_name().is_none());
assert!(contig.refseq_name().is_none());
assert_eq!(contig.ucsc_name(), Some("chrY"));

The new expects alt_names with three items that correspond to:

  • GenBank accession
  • RefSeq accession
  • UCSC accession

An accession equaling to an empty string or "na" is filtered out.

Trait Implementations§

Source§

impl Clone for Contig

Source§

fn clone(&self) -> Contig

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 Debug for Contig

Source§

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

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

impl Hash for Contig

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 Ord for Contig

Source§

fn cmp(&self, other: &Contig) -> 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 PartialEq for Contig

Source§

fn eq(&self, other: &Contig) -> 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 PartialOrd for Contig

Source§

fn partial_cmp(&self, other: &Contig) -> 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 Eq for Contig

Source§

impl StructuralPartialEq for Contig

Auto Trait Implementations§

§

impl Freeze for Contig

§

impl RefUnwindSafe for Contig

§

impl Send for Contig

§

impl Sync for Contig

§

impl Unpin for Contig

§

impl UnwindSafe for Contig

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