Skip to main content

MSVocabulary

Struct MSVocabulary 

Source
pub struct MSVocabulary();
Expand description

A global facade for interacting with the PSI-MS controlled vocabulary.

This requires the cv feature which uses the mzcv library to work with OBO files, runtime caching and embed static compile-time embedding of controlled vocabulary data.

This type is a singleton guarded by a OnceLock wrapping a mzcv::CVIndex that lets the caller fetch MSTerm entries by accession CURIE or name. It also lets the caller traverse the controlled vocabulary tree.

let term = MSVocabulary::get(curie!(MS:1000044)).unwrap();
assert_eq!(term.name.as_ref(), "dissociation method");
assert!(!MSVocabulary::children_of(term.accession()).expect("this term is defined!").is_empty());

§Data Source

Alternatively, you can take a reference to the global instance with MSVocabulary::init, which first checks the on-disk cache and then uses the statically embedded copy of the controlled vocabulary if it isn’t available. Using MSVocabulary::init_static directly uses the fixed, pre-compiled version if it is the first call. Finally, you can choose to update the cached on-disk version using MSVocabulary::update_from_obo, see the method documentation for more details.

Implementations§

Source§

impl MSVocabulary

Source

pub fn version() -> &'static CVVersion

Get the version metadata of the vocabulary

Source

pub fn update_from_obo<P>(obo_path: P) -> Result<(), Box<dyn Error>>
where P: AsRef<Path>,

Update the PSI-MS vocabulary to the version at the provided path. This will update the parsed cache on disk and attempt to set the global in-memory representation to use this version.

§Warning

If the controlled vocabulary is already loaded, this will fail to update the current version in memory, but should still update the version on disk so that it will be read from when the a new process starts.

This does not update the compile time static version embedded in the binary used by Self::init_static. That can only be upgraded at build time.

Source

pub fn init() -> &'static CVIndex<MSVocabulary>

Get or create the global instance of the mzcv::CVIndex for MSVocabulary

Source

pub fn init_static() -> &'static CVIndex<MSVocabulary>

Get or create the global instance of the mzcv::CVIndex for MSVocabulary using only the statically embedded data.

Source

pub fn get(curie: CURIE) -> Option<Arc<MSTerm>>

Get a term by its CURIE

Source

pub fn get_by_name(name: &str) -> Option<Arc<MSTerm>>

Get a term by its human-readable name in a case-insensitive manner.

Source

pub fn get_by_name_or_synonym(name: &str) -> Option<(bool, Arc<MSTerm>)>

Load a term by name or if that fails by synonym, names are matched in a case insensitive manner. Returns a boolean indicating if it matches a name true or a synonym false

Source

pub fn parents_of(curie: CURIE) -> Option<HashSet<Compat<CURIE>>>

Get the immediate parents of this term

This follows the is_a OBO relationship.

Source

pub fn parents_of_recursive(curie: CURIE) -> HashSet<Compat<CURIE>>

Get all parents of this term, recursively querying the graph

This follows the is_a OBO relationship.

Source

pub fn children_of(curie: CURIE) -> Option<&'static [Compat<CURIE>]>

Get the immediate children of this term

This follows the is_a OBO relationship.

Source

pub fn is_child_of(child: CURIE, parent: CURIE) -> bool

Test if child is derived from parent along a transitive is_a relationship

Source

pub fn children_of_recursive(curie: CURIE) -> HashSet<Compat<CURIE>>

Get all children of this term, recursively querying the graph

This follows the is_a OBO relationship.

Trait Implementations§

Source§

impl CVSource for MSVocabulary

Source§

type Data = MSTerm

The data item that is stored in the CV
Source§

type Structure = VocabularyData<MSTerm>

The type of the main data structure to keep all data items (used to build any kind of hierarchy necessary)
Source§

fn cv_name() -> &'static str

The name of the CV, used to create the paths to store intermediate files and caches so has to be valid in that context
Source§

fn files() -> &'static [CVFile]

The source files for the CV
Source§

fn static_data() -> Option<(CVVersion, <MSVocabulary as CVSource>::Structure)>

The static data of this CV
Source§

fn parse( reader: impl Iterator<Item = HashBufReader<Box<dyn Read>, impl Digest>>, ) -> Result<(CVVersion, <MSVocabulary as CVSource>::Structure, Vec<BoxedError<'static, CVError>>), Vec<BoxedError<'static, CVError>>>

Parse the textual representation of this CV. Return the version, the data, and possibly a list of warnings or noncritical errors encountered while parsing. Read more
Source§

const AUTOMATICALLY_WRITE_UNCOMPRESSED: bool = false

Set this constant to true to enable automatic writing of the CV when the cache is updated
Source§

fn cv_label() -> &'static str

The label of the CV, the identifier that is used at the start of CURIEs. Defaults to the name.
Source§

fn default_stem() -> PathBuf

The default file stem (no extension). Read more
Source§

fn write_uncompressed<W>( _writer: W, _version: &CVVersion, _data: impl Iterator<Item = Arc<Self::Data>>, ) -> Result<(), BoxedError<'static, CVError>>
where W: Write,

Write out the data to the standard file, only need to implement this if AUTOMATICALLY_WRITE_UNCOMPRESSED is set to true. This is used to write out data when the main way of interacting with this structure is via the crate::CVIndex::update method. So for custom modification CVs for example. Read more
Source§

impl CVTraversal<MSVocabulary> for CVIndex<MSVocabulary>

Source§

fn child_map( &self, ) -> &HashMap<Compat<<MSTerm as CVData>::Index>, Vec<Compat<<MSTerm as CVData>::Index>>>

Source§

fn children_of( &self, curie: CURIE, ) -> Option<&[Compat<<<MSVocabulary as CVSource>::Data as CVData>::Index>]>

Get the immediate children of this term Read more
Source§

fn parents_of( &self, curie: CURIE, ) -> Option<HashSet<Compat<<<MSVocabulary as CVSource>::Data as CVData>::Index>>>

Get the immediate parents of this term Read more
Source§

fn get_by_index( &self, key: <<MSVocabulary as CVSource>::Data as CVData>::Index, ) -> Option<Arc<<MSVocabulary as CVSource>::Data>>

Helper method to mirror mzcv::CVIndex::get_by_index
Source§

fn parents_of_recursive( &self, curie: <<T as CVSource>::Data as CVData>::Index, ) -> HashSet<Compat<<<T as CVSource>::Data as CVData>::Index>>

Get all parents of this term, recursively querying the graph Read more
Source§

fn children_of_recursive( &self, curie: <<T as CVSource>::Data as CVData>::Index, ) -> HashSet<Compat<<<T as CVSource>::Data as CVData>::Index>>

Get all children of this term, recursively querying the graph Read more
Source§

fn is_child_of( &self, child: <<T as CVSource>::Data as CVData>::Index, parent: <<T as CVSource>::Data as CVData>::Index, ) -> bool

Test if child is derived from parent along a transitive is_a relationship
Source§

impl Debug for MSVocabulary

Source§

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

Formats the value using the given formatter. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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