Struct Transcripts

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

A convinience wrapper to handle large amounts of Transcripts

It allows fast lookup operation by gene or transcript name.

§Examples

use atglib::models::{TranscriptBuilder, Transcripts};

let mut transcripts = Transcripts::new();
assert_eq!(transcripts.len(), 0);

transcripts.push(TranscriptBuilder::new()
    .name("NM_001203247.2")
    .chrom("chr7")
    .gene("EZH2")
    .strand(atglib::models::Strand::Minus)
    .build()
    .unwrap()
);
assert_eq!(transcripts.len(), 1);

assert_eq!(transcripts.by_name("NM_001203247.2").len(), 1);
assert_eq!(transcripts.by_gene("EZH2").len(), 1);

assert!(transcripts.by_name("Foo").is_empty());
assert!(transcripts.by_gene("Bar").is_empty());

Implementations§

Source§

impl Transcripts

Source

pub fn new() -> Self

Source

pub fn with_capacity(capacity: usize) -> Self

Source

pub fn by_name(&self, name: &str) -> Vec<&Transcript>

Retrieve all Transcripts by their name / transcript-id

Most transcripts exist only once, but some transcripts (e.g. NM_001370371.1) are on both X- and Y-chromosome.

§Examples
assert_eq!(transcripts.by_name("NM_001203247.2").len(), 1);
assert!(transcripts.by_name("invalid_name").is_empty());
Source

pub fn by_gene(&self, gene: &str) -> Vec<&Transcript>

Retrieve all Transcripts of a gene

§Examples
assert_eq!(transcripts.by_gene("EZH2").len(), 1);
assert!(transcripts.by_gene("Invalid-name").is_empty());
Source

pub fn push(&mut self, record: Transcript)

Add another Transcript

§Examples
use atglib::models::{TranscriptBuilder, Transcripts};

let mut transcripts = Transcripts::new();

transcripts.push(TranscriptBuilder::new()
    .name("NM_001203247.2")
    .chrom("chr7")
    .gene("EZH2")
    .strand(atglib::models::Strand::Minus)
    .build()
    .unwrap()
);

transcripts.push(TranscriptBuilder::new()
    .name("NM_001203247.3")
    .chrom("chr7")
    .gene("EZH2")
    .strand(atglib::models::Strand::Minus)
    .build()
    .unwrap()
);
assert_eq!(transcripts.len(), 2);

assert_eq!(transcripts.by_name("NM_001203247.2").len(), 1);
assert_eq!(transcripts.by_name("NM_001203247.3").len(), 1);
assert_eq!(transcripts.by_gene("EZH2").len(), 2);
Source

pub fn len(&self) -> usize

Returns the number of Transcripts in the object

Source

pub fn is_empty(&self) -> bool

Returns true if the object contains no transcripts.

Source

pub fn as_vec(&self) -> &Vec<Transcript>

Returns a vector of Transcripts

Source

pub fn to_vec(self) -> Vec<Transcript>

Consumes and returns a vector of Transcripts

Source

pub fn genes(&self) -> Vec<&str>

Returns a vector with the gene symbols of all transcripts

Trait Implementations§

Source§

impl Default for Transcripts

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Transcripts

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl IntoIterator for Transcripts

Source§

type Item = Transcript

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<Transcripts as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Serialize for Transcripts

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,