Struct fastobo::ast::OboDoc[][src]

pub struct OboDoc { /* fields omitted */ }

A complete OBO document in format version 1.4.

Implementations

impl OboDoc[src]

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()))));

pub fn new() -> Self[src]

Create a new empty OBO document.

pub fn with_header(header: HeaderFrame) -> Self[src]

Create a new OBO document with the provided frame.

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

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

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

Create a new OBO document with the provided entity frames.

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

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

impl OboDoc[src]

Shared and mutable getters.

pub fn header(&self) -> &HeaderFrame[src]

Get a reference to the header of the OBO document.

pub fn header_mut(&mut self) -> &mut HeaderFrame[src]

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

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

Notable traits for Vec<u8, Global>

impl Write for Vec<u8, Global>
[src]

Get a reference to the entities of the OBO document.

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

Notable traits for Vec<u8, Global>

impl Write for Vec<u8, Global>
[src]

Get a reference to the entities of the OBO document.

pub fn is_empty(&self) -> bool[src]

Check whether or not the document is empty.

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

impl OboDoc[src]

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.

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

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

  • CardinalityError::MissingClause: if the header frame does not contain any default namespace definition.
  • CardinalityError::DuplicateClauses if the header frame does contain more than one default namespace definition.

Example

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

[Term]
id: TST:01

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

doc.assign_namespaces().unwrap();

assert_eq!(doc.to_string(),
"default-namespace: TST

[Term]
id: TST:01
namespace: TST

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

pub fn treat_xrefs(&mut self)[src]

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

pub fn is_fully_labeled(&self) -> bool[src]

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

impl AsMut<Vec<EntityFrame, Global>> for OboDoc[src]

impl AsRef<[EntityFrame]> for OboDoc[src]

impl AsRef<Vec<EntityFrame, Global>> for OboDoc[src]

impl Clone for OboDoc[src]

impl Debug for OboDoc[src]

impl Default for OboDoc[src]

impl Display for OboDoc[src]

impl Eq for OboDoc[src]

impl<E> FromIterator<E> for OboDoc where
    E: Into<EntityFrame>, 
[src]

impl<'i> FromPair<'i> for OboDoc[src]

impl FromStr for OboDoc[src]

type Err = SyntaxError

The associated error which can be returned from parsing.

impl Hash for OboDoc[src]

impl Orderable for OboDoc[src]

fn sort(&mut self)[src]

Sort the document in the right serialization order.

fn is_sorted(&self) -> bool[src]

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

impl PartialEq<OboDoc> for OboDoc[src]

impl StructuralEq for OboDoc[src]

impl StructuralPartialEq for OboDoc[src]

impl<B: BufRead> TryFrom<&'_ mut SequentialParser<B>> for OboDoc[src]

type Error = Error

The type returned in the event of a conversion error.

impl<B: BufRead> TryFrom<&'_ mut ThreadedParser<B>> for OboDoc[src]

type Error = Error

The type returned in the event of a conversion error.

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

type Error = Error

The type returned in the event of a conversion error.

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

type Error = Error

The type returned in the event of a conversion error.

impl<B: BufRead> TryFrom<SequentialParser<B>> for OboDoc[src]

type Error = Error

The type returned in the event of a conversion error.

impl<B: BufRead> TryFrom<ThreadedParser<B>> for OboDoc[src]

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.