pub struct OboDoc { /* private fields */ }
Expand description
A complete OBO document in format version 1.4.
Implementations§
source§impl OboDoc
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()))));
sourcepub fn with_header(header: HeaderFrame) -> Self
pub fn with_header(header: HeaderFrame) -> Self
Create a new OBO document with the provided frame.
sourcepub fn and_header(self, header: HeaderFrame) -> Self
pub fn and_header(self, header: HeaderFrame) -> Self
Use the provided frame as the header of the OBO document.
sourcepub fn with_entities(entities: Vec<EntityFrame>) -> Self
pub fn with_entities(entities: Vec<EntityFrame>) -> Self
Create a new OBO document with the provided entity frames.
sourcepub fn and_entities(self, entities: Vec<EntityFrame>) -> Self
pub fn and_entities(self, entities: Vec<EntityFrame>) -> Self
Use the provided entity frames as the content of the OBO document.
source§impl OboDoc
impl OboDoc
Shared and mutable getters.
sourcepub fn header(&self) -> &HeaderFrame
pub fn header(&self) -> &HeaderFrame
Get a reference to the header of the OBO document.
sourcepub fn header_mut(&mut self) -> &mut HeaderFrame
pub fn header_mut(&mut self) -> &mut HeaderFrame
Get a mutable reference to the header of the OBO document.
sourcepub fn entities(&self) -> &Vec<EntityFrame>
pub fn entities(&self) -> &Vec<EntityFrame>
Get a reference to the entities of the OBO document.
sourcepub fn entities_mut(&mut self) -> &mut Vec<EntityFrame>
pub fn entities_mut(&mut self) -> &mut Vec<EntityFrame>
Get a reference to the entities of the OBO document.
source§impl OboDoc
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.
sourcepub fn assign_namespaces(&mut self) -> Result<(), CardinalityError>
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
");
sourcepub fn treat_xrefs(&mut self)
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
- Header Macro Translation section of the syntax and semantics guide.
sourcepub fn is_fully_labeled(&self) -> bool
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
impl AsMut<Vec<EntityFrame, Global>> for OboDoc
source§fn as_mut(&mut self) -> &mut Vec<EntityFrame>
fn as_mut(&mut self) -> &mut Vec<EntityFrame>
source§impl AsRef<[EntityFrame]> for OboDoc
impl AsRef<[EntityFrame]> for OboDoc
source§fn as_ref(&self) -> &[EntityFrame]
fn as_ref(&self) -> &[EntityFrame]
source§impl AsRef<Vec<EntityFrame, Global>> for OboDoc
impl AsRef<Vec<EntityFrame, Global>> for OboDoc
source§fn as_ref(&self) -> &Vec<EntityFrame>
fn as_ref(&self) -> &Vec<EntityFrame>
source§impl<E> FromIterator<E> for OboDocwhere
E: Into<EntityFrame>,
impl<E> FromIterator<E> for OboDocwhere E: Into<EntityFrame>,
source§fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = E>,
fn from_iter<T>(iter: T) -> Selfwhere T: IntoIterator<Item = E>,
source§impl<'i> FromPair<'i> for OboDoc
impl<'i> FromPair<'i> for OboDoc
source§unsafe fn from_pair_unchecked(
pair: Pair<'i, Rule>,
cache: &Cache
) -> Result<Self, SyntaxError>
unsafe fn from_pair_unchecked( pair: Pair<'i, Rule>, cache: &Cache ) -> Result<Self, SyntaxError>
Pair
without checking the rule. Read more