#obo #ontology #syntax #ast #parser

fastobo

Faultless AST for Open Biomedical Ontologies

15 releases (6 breaking)

✓ Uses Rust 2018 edition

0.7.1 Aug 8, 2019
0.6.1 Jul 24, 2019

#33 in Parser implementations

Download history 109/week @ 2019-05-09 16/week @ 2019-05-16 93/week @ 2019-05-23 73/week @ 2019-05-30 102/week @ 2019-06-06 156/week @ 2019-06-13 87/week @ 2019-06-20 86/week @ 2019-06-27 150/week @ 2019-07-04 110/week @ 2019-07-11 209/week @ 2019-07-18 28/week @ 2019-07-25 206/week @ 2019-08-01

473 downloads per month
Used in 2 crates

MIT license

299KB
7.5K SLoC

fastobo Star me

Faultless AST for Open Biomedical Ontologies.

TravisCI Codecov License Source Crate Documentation Changelog GitHub issues

Overview

This library provides a mostly-complete implementation of the OBO flat file format 1.4.

  • Data structures - fastobo provides a complete owned AST for the OBO language, with constructors and covenience traits where applicable. There is a plan to provide borrowed data structures as well, to be able to build a view of an OBO document from borrowed data.
  • Parsing - The parser is implemented using pest, and is reexported from the fastobo-syntax crate. Most structures implement the FromPair trait which allows to build a data structure from a stream of pest tokens.
  • Errors - All functions in that crate that return a Result will always use the Error struct defined in the error module. Errors reported by pest are very meaningful, and can give the exact location of a syntax error encountered by the parser.
  • Semantics - This library exports specific methods that can be used to edit an OBO syntax tree with the semantics expected in the format guide: mapping identifiers to URLs, adding default namespaces, or expanding entity frames using treat-xrefs macros.

Warning: this project adheres to Semantic Versioning, but the API is likely to change a lot before the release of a stable 1.0.

Features

All the following features are enabled by default, but can be disabled and cherry-picked using the default-features = false option in the Cargo.toml manifest of your project:

  • memchr - Use the memchr library to improve parser speed when searching for a particular character in a buffer.

Usage

Add fastobo to the [dependencies] sections of your Cargo.toml manifest:

[dependencies]
fastobo = "0.7.0"

The top-level fastobo module provides several functions to parse an OboDoc. Use fastobo::from_reader to load an OBO document from a BufRead implementor (use std::io::BufReader if needed):

extern crate fastobo;
extern crate ureq;

fn main() {
    let response = ureq::get("http://purl.obolibrary.org/obo/ms.obo").call();
    let mut reader = std::io::BufReader::new(response.into_reader());

    match fastobo::from_reader(&mut reader) {
        Ok(doc) => println!("Number of MS entities: {}", doc.entities().len()),
        Err(e) => panic!("Could not parse the Mass-Spec Ontology: {}", e),
    }
}

See also

  • fastobo-syntax: Standalone pest parser for the OBO format version 1.4.
  • fastobo-graphs: Data model and serde implementation of the OBO graphs specification, with conversion traits from and to OBO.
  • fastobo-py: Idiomatic Python bindings to this crate.
  • fastobo-validator: Standalone CLI to validate OBO files against the specification.

Feedback

Found a bug ? Have an enhancement request ? Head over to the GitHub issue tracker of the project if you need to report or ask something. If you are filling in on a bug, please include as much information as you can about the issue, and try to recreate the same bug in a simple, easily reproducible situation.

About

This project is currently being developed by Martin Larralde as part of a Master's Degree internship in the BBOP team of the Lawrence Berkeley National Laboratory, under the supervision of Chris Mungall.

Dependencies

~5MB
~95K SLoC