-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Adds two new sources for GO and Monarch JSON LD contexts 2. Adds documentation for each source
- Loading branch information
Showing
4 changed files
with
123 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,111 @@ | ||
//! Contains functions for getting pre-defined contexts | ||
|
||
use crate::{error::CuriesError, Converter}; | ||
|
||
/// Get the latest OBO Foundry context. | ||
/// Get the latest [OBO Foundry context](http://purl.obolibrary.org/meta/obo_context.jsonld). | ||
/// | ||
/// The OBO Foundry context is a simple prefix map stored in a JSON-LD file. | ||
/// It contains OBO Foundry preferred prefixes and OBO PURL expansions, | ||
/// but no synonyms. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```rust | ||
/// use curies::sources::{get_obo_converter}; | ||
/// use tokio::{runtime}; | ||
/// | ||
/// let rt = runtime::Runtime::new().expect("Failed to create Tokio runtime"); | ||
/// let converter = rt.block_on(async { | ||
/// get_obo_converter().await | ||
/// }).expect("Failed to create the OBO converter"); | ||
/// | ||
/// let uri = converter.expand("DOID:1234").unwrap(); | ||
/// assert_eq!(uri, "http://purl.obolibrary.org/obo/DOID_1234"); | ||
/// | ||
/// let unregistered_uri = converter.expand("missing.prefix:0000001"); | ||
/// assert!(unregistered_uri.is_err()); | ||
/// | ||
/// let curie = converter.compress("http://purl.obolibrary.org/obo/DOID_1234").unwrap(); | ||
/// assert_eq!(curie, "DOID:1234"); | ||
/// | ||
/// let unregistered_curie = converter.compress("http://example.org/missing.prefix:0000001"); | ||
/// assert!(unregistered_curie.is_err()); | ||
/// ``` | ||
pub async fn get_obo_converter() -> Result<Converter, CuriesError> { | ||
Converter::from_jsonld("http://purl.obolibrary.org/meta/obo_context.jsonld").await | ||
} | ||
|
||
/// Get the Prefix Commons-maintained [Monarch Initiative | ||
/// context](https://github.com/prefixcommons/prefixcommons-py/blob/master/prefixcommons/registry/monarch_context.jsonld) | ||
/// | ||
/// The Monarch Initiative context is a simple prefix map stored in a JSON-LD file. | ||
/// It contains a project-specific mix of prefixes from GO, OBO, and Identifiers.org. | ||
/// | ||
/// Note, this is not a carefully constructed context, as there are overlapping entries | ||
/// such as: | ||
/// | ||
/// - TrEMBL and `http://purl.uniprot.org/uniprot/` | ||
/// - SwissProt and `http://identifiers.org/SwissProt:` | ||
/// - UniProtKB" and `http://identifiers.org/uniprot/` | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```rust | ||
/// use curies::sources::{get_monarch_converter}; | ||
/// use tokio::{runtime}; | ||
/// | ||
/// let rt = runtime::Runtime::new().expect("Failed to create Tokio runtime"); | ||
/// let converter = rt.block_on(async { | ||
/// get_monarch_converter().await | ||
/// }).expect("Failed to create the GO converter"); | ||
/// | ||
/// let uri = converter.expand("CHEBI:24867").unwrap(); | ||
/// assert_eq!(uri, "http://purl.obolibrary.org/obo/CHEBI_24867"); | ||
/// | ||
/// let unregistered_uri = converter.expand("addgene:50943"); | ||
/// assert!(unregistered_uri.is_err(), "AddGene is not registered in the Monarch context"); | ||
/// | ||
/// let curie = converter.compress("http://purl.obolibrary.org/obo/CHEBI_24867").unwrap(); | ||
/// assert_eq!(curie, "CHEBI:24867"); | ||
/// | ||
/// let unregistered_curie = converter.compress("http://addgene.org/50943"); | ||
/// assert!(unregistered_curie.is_err(), "AddGene is not registered in the Monarch context"); | ||
/// ``` | ||
pub async fn get_monarch_converter() -> Result<Converter, CuriesError> { | ||
Converter::from_jsonld("https://raw.githubusercontent.com/prefixcommons/prefixcommons-py/master/prefixcommons/registry/monarch_context.jsonld").await | ||
} | ||
|
||
/// Get the Prefix Commons-maintained [Gene Ontology (GO) | ||
/// context](https://github.com/prefixcommons/prefixcommons-py/blob/master/prefixcommons/registry/go_context.jsonld) | ||
/// | ||
/// The Gene Ontology context is a simple prefix map stored in a JSON-LD file. | ||
/// It contains prefixes corresponding to semantic spaces that are useful for | ||
/// modeling the molecular functions, cellular components, and biological processes | ||
/// that genes take part in. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```rust | ||
/// use curies::sources::{get_go_converter}; | ||
/// use tokio::{runtime}; | ||
/// | ||
/// let rt = runtime::Runtime::new().expect("Failed to create Tokio runtime"); | ||
/// let converter = rt.block_on(async { | ||
/// get_go_converter().await | ||
/// }).expect("Failed to create the GO converter"); | ||
/// | ||
/// let uri = converter.expand("NCBIGene:100010").unwrap(); | ||
/// assert_eq!(uri, "http://identifiers.org/ncbigene/100010"); | ||
/// | ||
/// let unregistered_uri = converter.expand("DOID:1234"); | ||
/// assert!(unregistered_uri.is_err(), "DOID is not registered in the GO context"); | ||
/// | ||
/// let curie = converter.compress("http://identifiers.org/ncbigene/100010").unwrap(); | ||
/// assert_eq!(curie, "NCBIGene:100010"); | ||
/// | ||
/// let unregistered_curie = converter.compress("http://purl.obolibrary.org/obo/DOID_1234"); | ||
/// assert!(unregistered_curie.is_err(), "DOID is not registered in the GO context"); | ||
/// ``` | ||
pub async fn get_go_converter() -> Result<Converter, CuriesError> { | ||
Converter::from_jsonld("https://raw.githubusercontent.com/prefixcommons/prefixcommons-py/master/prefixcommons/registry/go_context.jsonld").await | ||
} |