Struct fastobo::ast::OboDoc

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

A complete OBO document in format version 1.4.

Implementations§

source§

impl OboDoc

Constructors and builder methods.

Parser

Use from_file to parse a file on the local filesystem, or from_stream to parse a BufRead implementor (BufRead is needed instead of Read as the parser is line-based):

let doc1 = fastobo::from_file("tests/data/ms.obo").unwrap();

// This is equivalent to (but with the file path set in eventual errors):
let mut r = BufReader::new(File::open("tests/data/ms.obo").unwrap());
let doc2 = fastobo::from_reader(&mut r).unwrap();

// FIXME: threaded parser may not maintain ordering YET
// assert_eq!(doc1, doc2);

Builder Pattern

The builder pattern makes it easy to create an OboDoc from an interator of EntityFrame, in order to add an HeaderFrame after all the entities where collected:

use std::iter::FromIterator;

let entities = vec![TermFrame::new(ClassIdent::from(PrefixedIdent::new("TEST", "001")))];
let doc = OboDoc::from_iter(entities.into_iter())
    .and_header(HeaderFrame::from(HeaderClause::FormatVersion(Box::new("1.4".into()))));
source

pub fn new() -> Self

Create a new empty OBO document.

source

pub fn with_header(header: HeaderFrame) -> Self

Create a new OBO document with the provided frame.

source

pub fn and_header(self, header: HeaderFrame) -> Self

Use the provided frame as the header of the OBO document.

source

pub fn with_entities(entities: Vec<EntityFrame>) -> Self

Create a new OBO document with the provided entity frames.

source

pub fn and_entities(self, entities: Vec<EntityFrame>) -> Self

Use the provided entity frames as the content of the OBO document.

source§

impl OboDoc

Shared and mutable getters.

source

pub fn header(&self) -> &HeaderFrame

Get a reference to the header of the OBO document.

source

pub fn header_mut(&mut self) -> &mut HeaderFrame

Get a mutable reference to the header of the OBO document.

source

pub fn entities(&self) -> &Vec<EntityFrame>

Get a reference to the entities of the OBO document.

source

pub fn entities_mut(&mut self) -> &mut Vec<EntityFrame>

Get a reference to the entities of the OBO document.

source

pub fn is_empty(&self) -> bool

Check whether or not the document is empty.

An empty document has no header clauses and no entity frames.

source§

impl OboDoc

Additional methods for OboDoc that can be used to edit the syntax tree.

The OBO 1.4 semantics are used to process header macros or to add the default OBO namespace to all the frames of the document.

source

pub fn assign_namespaces(&mut self) -> Result<(), CardinalityError>

Assign the ontology default namespace to all frames without one.

This function will not check the cardinality of namespace clauses in entity frames: it will only add a single namespace clause to all frames that have none.

Errors

If all frames already have a namespace clause, this function will not check the contents of the header, return Ok(()). However, if a frame requires the assignment of the default namespace, then a CardinalityError may be raised depending on the header contents.

Example
let mut doc = OboDoc::from_str(
"default-namespace: test

[Term]
id: TST:01

[Term]
id: PATO:0000001
namespace: quality
").unwrap();

doc.assign_namespaces().unwrap();
assert_eq!(doc.to_string(),
"default-namespace: test

[Term]
id: TST:01
namespace: test

[Term]
id: PATO:0000001
namespace: quality
");
source

pub fn treat_xrefs(&mut self)

Process macros in the header frame, adding clauses to relevant entities.

Header macros are used to expand an ontology by overloading the actual semantics of xref clauses contained in several entity frames. In case the translated clauses are already present in the document, they won’t be added a second time.

The following implicit macros will be processed even if they are not part of the document:

  • treat-xrefs-as-equivalent: RO
  • treat-xrefs-as-equivalent: BFO
Note

After processing the document, neither the original frame xrefs nor the treat-xrefs header clauses will be removed from the AST.

See also
source

pub fn is_fully_labeled(&self) -> bool

Check if the OBO document is fully labeled.

An OBO ontology is fully labeled if every frame has exactly one name clause. This is equivalent to the definition in the OBO specification if we suppose an invalid OBO document is never fully labeled.

Trait Implementations§

source§

impl AsMut<Vec<EntityFrame, Global>> for OboDoc

source§

fn as_mut(&mut self) -> &mut Vec<EntityFrame>

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<[EntityFrame]> for OboDoc

source§

fn as_ref(&self) -> &[EntityFrame]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<Vec<EntityFrame, Global>> for OboDoc

source§

fn as_ref(&self) -> &Vec<EntityFrame>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for OboDoc

source§

fn clone(&self) -> OboDoc

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 OboDoc

source§

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

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

impl Default for OboDoc

source§

fn default() -> OboDoc

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

impl Display for OboDoc

source§

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

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

impl<E> FromIterator<E> for OboDocwhere E: Into<EntityFrame>,

source§

fn from_iter<T>(iter: T) -> Selfwhere T: IntoIterator<Item = E>,

Creates a value from an iterator. Read more
source§

impl<'i> FromPair<'i> for OboDoc

source§

const RULE: Rule = Rule::OboDoc

The production rule the pair is expected to be obtained from.
source§

unsafe fn from_pair_unchecked( pair: Pair<'i, Rule>, cache: &Cache ) -> Result<Self, SyntaxError>

Create a new instance from a Pair without checking the rule. Read more
source§

fn from_pair(pair: Pair<'i, Rule>, cache: &Cache) -> Result<Self, SyntaxError>

Create a new instance from a Pair.
source§

impl FromStr for OboDoc

§

type Err = SyntaxError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for OboDoc

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 Orderable for OboDoc

source§

fn sort(&mut self)

Sort the document in the right serialization order.

source§

fn is_sorted(&self) -> bool

Check if the document is sorted in the right serialization order.

source§

impl PartialEq<OboDoc> for OboDoc

source§

fn eq(&self, other: &OboDoc) -> 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<B: BufRead> TryFrom<&mut SequentialParser<B>> for OboDoc

§

type Error = Error

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

fn try_from(parser: &mut SequentialParser<B>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<B: BufRead> TryFrom<&mut ThreadedParser<B>> for OboDoc

§

type Error = Error

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

fn try_from(reader: &mut ThreadedParser<B>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<B: BufRead> TryFrom<Box<SequentialParser<B>, Global>> for OboDoc

§

type Error = Error

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

fn try_from(reader: Box<SequentialParser<B>>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<B: BufRead> TryFrom<Box<ThreadedParser<B>, Global>> for OboDoc

§

type Error = Error

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

fn try_from(reader: Box<ThreadedParser<B>>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<B: BufRead> TryFrom<SequentialParser<B>> for OboDoc

§

type Error = Error

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

fn try_from(parser: SequentialParser<B>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<B: BufRead> TryFrom<ThreadedParser<B>> for OboDoc

§

type Error = Error

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

fn try_from(reader: ThreadedParser<B>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for OboDoc

source§

impl StructuralEq for OboDoc

source§

impl StructuralPartialEq for OboDoc

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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<'i, T> FromSlice<'i> for Twhere T: FromStr,

§

type Err = <T as FromStr>::Err

The associated error which can be returned from parsing.
source§

fn from_slice(s: &'i str) -> Result<T, <T as FromSlice<'i>>::Err>

Parses a string slice s to return a value of this type.
source§

impl<T, U> Into<U> for Twhere 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 Twhere 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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.