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
impl Gene
sourcepub fn new(id: GeneId, name: &str) -> Gene
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.
sourcepub fn from_parts(id: &str, name: &str) -> HpoResult<Gene>
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
sourcepub fn add_term<I: Into<HpoTermId>>(&mut self, term_id: I) -> bool
pub fn add_term<I: Into<HpoTermId>>(&mut self, term_id: I) -> bool
Connect another HPO term to the gene
sourcepub fn as_bytes(&self) -> Vec<u8> ⓘ
pub fn as_bytes(&self) -> Vec<u8> ⓘ
Returns a binary representation of the Gene
The binary layout is defined as:
Byte offset | Number of bytes | Description |
---|---|---|
0 | 4 | The total length of the binary data blob as big-endian u32 |
4 | 4 | The Gene ID as big-endian u32 |
8 | 1 | The length of the Gene Name / Symbol (converted to a u8 vector) as a u8 |
9 | n | The Gene name/symbol as u8 vector. If the name has more than 255 bytes, it is trimmed to 255 |
9 + n | 4 | The number of associated HPO terms as big-endian u32 |
13 + n | x * 4 | The 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);
sourcepub fn to_hpo_set<'a>(&self, ontology: &'a Ontology) -> HpoSet<'a>
pub fn to_hpo_set<'a>(&self, ontology: &'a Ontology) -> HpoSet<'a>
Returns an HpoSet
from the Gene
Trait Implementations§
source§impl PartialEq for Gene
impl PartialEq for Gene
source§impl TryFrom<&[u8]> for Gene
impl TryFrom<&[u8]> for Gene
source§fn try_from(bytes: &[u8]) -> Result<Self, Self::Error>
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));
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.