Struct hpo::annotations::Gene

source ·
pub struct Gene { /* private fields */ }
Expand description

A single gene

A gene has a unique GeneId and a name (symbol) and is connected to a set of HPO terms

Implementations§

source§

impl Gene

source

pub fn new(id: GeneId, name: &str) -> Gene

Initializes a new Gene

This method should rarely, if ever, be used directly. The preferred way to create new genes is through Ontology::add_gene to ensure that each gene exists only once.

source

pub fn from_parts(id: &str, name: &str) -> HpoResult<Gene>

Initializes a new Gene from str values

This method should rarely, if ever, be used directly. The preferred way to create new genes is through Ontology::add_gene to ensure that each gene exists only once.

§Errors

If the id is not a correct GeneId, returns HpoError::ParseIntError

source

pub fn id(&self) -> &GeneId

The unique GeneId of the gene, most likely the NCBI Gene ID

source

pub fn name(&self) -> &str

The name of the gene (gene symbol)

source

pub fn symbol(&self) -> &str

The gene symbol (identical to Gene::id)

source

pub fn add_term<I: Into<HpoTermId>>(&mut self, term_id: I) -> bool

Connect another HPO term to the gene

source

pub fn hpo_terms(&self) -> &HpoGroup

The set of connected HPO terms

source

pub fn as_bytes(&self) -> Vec<u8>

Returns a binary representation of the Gene

The binary layout is defined as:

Byte offsetNumber of bytesDescription
04The total length of the binary data blob as big-endian u32
44The Gene ID as big-endian u32
81The length of the Gene Name / Symbol (converted to a u8 vector) as a u8
9nThe Gene name/symbol as u8 vector. If the name has more than 255 bytes, it is trimmed to 255
9 + n4The number of associated HPO terms as big-endian u32
13 + nx * 4The HPO Term IDs of the associated terms, each encoded as big-endian u32
§Examples
use hpo::annotations::Gene;

let mut gene = Gene::from_parts("123", "FooBar").unwrap();
let bytes = gene.as_bytes();

assert_eq!(bytes.len(), 4 + 4 + 1 + 6 + 4);
assert_eq!(bytes[4..8], [0u8, 0u8, 0u8, 123u8]);
assert_eq!(bytes[8], 6u8);
source

pub fn to_hpo_set<'a>(&self, ontology: &'a Ontology) -> HpoSet<'a>

Returns an HpoSet from the Gene

Trait Implementations§

source§

impl Clone for Gene

source§

fn clone(&self) -> Gene

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

source§

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

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

impl Default for Gene

source§

fn default() -> Gene

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

impl Hash for Gene

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 PartialEq for Gene

source§

fn eq(&self, other: &Gene) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFrom<&[u8]> for Gene

source§

fn try_from(bytes: &[u8]) -> Result<Self, Self::Error>

Returns a Gene from a bytes vector

The byte layout for this method is defined in Gene::as_bytes

§Examples
use hpo::annotations::{Gene, GeneId};

let bytes = vec![
    0u8, 0u8, 0u8, 19u8, // Total size of Blop
    0u8, 0u8, 0u8, 123u8, // ID of the gene => 123
    6u8, // Length of gene symbol
    b'F', b'o', b'o', b'b', b'a', b'r', // Foobar
    0u8, 0u8, 0u8, 0u8  // Number of associated HPO Terms => 0
];
let gene = Gene::try_from(&bytes[..]).unwrap();

assert_eq!(gene.name(), "Foobar");
assert_eq!(gene.id(), &GeneId::from(123u32));
§

type Error = HpoError

The type returned in the event of a conversion error.
source§

impl Eq for Gene

Auto Trait Implementations§

§

impl Freeze for Gene

§

impl RefUnwindSafe for Gene

§

impl Send for Gene

§

impl Sync for Gene

§

impl Unpin for Gene

§

impl UnwindSafe for Gene

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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, 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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,