pyneuroml.annotations module#
Methods related to annotations
File: pyneuroml/annotations.py
Copyright 2024 NeuroML contributors
- class pyneuroml.annotations.Annotation#
Bases:
object
For handling NeuroML annotations
- P_MAP_EXTRA = {'encodes': 'bqbiol', 'funder': 'scoro', 'hasInstance': 'bqmodel', 'hasPart': 'bqbiol', 'hasProperty': 'bqbiol', 'hasTaxon': 'bqbiol', 'hasVersion': 'bqbiol', 'is': 'bqmodel', 'isDerivedFrom': 'bqmodel', 'isDescribedBy': 'bqmodel', 'isInstanceOf': 'bqmodel', 'isPartOf': 'bqbiol', 'isPropertyOf': 'bqbiol', 'isVersionOf': 'bqbiol', 'successor': 'scoro'}#
- create_annotation(subject: str, title: str | None = None, abstract: str | None = None, annotation_style: Literal['miriam', 'biosimulations'] = 'biosimulations', serialization_format: str = 'pretty-xml', write_to_file: str | None = None, xml_header: bool = True, indent: int = 12, description: str | None = None, is_: List[str] | None = None, keywords: List[str] | None = None, thumbnails: List[str] | None = None, organisms: Dict[str, str] | None = None, encodes_other_biology: Dict[str, str] | None = None, has_version: Dict[str, str] | None = None, is_version_of: Dict[str, str] | None = None, has_part: Dict[str, str] | None = None, is_part_of: Dict[str, str] | None = None, has_property: Dict[str, str] | None = None, is_property_of: Dict[str, str] | None = None, sources: Dict[str, str] | None = None, is_instance_of: Dict[str, str] | None = None, has_instance: Dict[str, str] | None = None, predecessors: Dict[str, str] | None = None, successors: Dict[str, str] | None = None, see_also: Dict[str, str] | None = None, references: Dict[str, str] | None = None, other_ids: Dict[str, str] | None = None, citations: Dict[str, str] | None = None, authors: Dict[str, Dict[str, str]] | Set | None = None, contributors: Dict[str, Dict[str, str]] | Set | None = None, license: Dict[str, str] | None = None, funders: Dict[str, str] | None = None, creation_date: str | None = None, modified_dates: List[str] | None = None)#
Create an RDF annotation from the provided fields
Added in version 1.2.10.
This can be used to create an RDF annotation for a subject—a model or a file like an OMEX archive file. It supports most qualifiers and will be continuously updated to support more as they are added.
It merely uses rdflib to make life easier for users to create annotations by coding in the various predicates for each subject.
For information on the specifications, see:
COMBINE specifications: combine-org/combine-specifications
Biosimulations guidelines: https://docs.biosimulations.org/concepts/conventions/simulation-project-metadata/
MIRIAM guidelines: https://drive.google.com/file/d/1JqjcH0T0UTWMuBj-scIMwsyt2z38A0vp/view
Note that:
not all qualifiers have been included yet
the qualifiers and their representations may change in the future
For any arguments here that take a dictionary of strings, the key is the resource reference URI, and the value is the string label. For example:
encodes_other_biology={ "http://identifiers.org/GO:0009653": "anatomical structure morphogenesis", "http://identifiers.org/kegg:ko04111": "Cell cycle - yeast", }
- Parameters:
subject (str) – subject/target of the annotation could be a file, a mode component
title (str) – title of annotation This is required for publishing models on biosimulations.org
abstract (str) – an abstract
annotation_style (str) –
type of annotation: either “miriam” or “biosimulations” (default).
There’s a difference in the annotation “style” suggested by MIRIAM and Biosimulations. MIRIAM suggests the use of RDF containers (bags) wherewas Biosimulations does not. This argument allows the user to select what style they want to use for the annotation.
serialization_format (str) –
format to serialize in using rdflib.serialize
See: https://rdflib.readthedocs.io/en/stable/plugin_serializers.html
xml_header (bool) – toggle inclusion of xml header if serializing in xml format
indent (int) – number of spaces to use to indent the annotation block
description (str) – a longer description
is (dict(str, str)) – biological entity represented by the model
keywords (list(str)) – keywords
thumbnails (list(str)) – thumbnails
organisms (dict(str, str)) – of organisms
encodes_other_biology (dict(str, str)) – other biological entities
has_version (dict(str, str)) – other versions
is_version_of (dict(str, str)) – is a version of
has_part (dict(str, str)) – includes another as a part
is_part_of (dict(str, str)) – is a part of another entity
has_property (dict(str, str)) – has a property
is_property_of (dict(str, str)) – is a property of another entity
sources (dict(str, str)) – links to sources (on GitHub and so on)
is_instance_of (dict(str, str)) – is an instance of
has_instance (dict(str, str)) – has instance of another entity
predecessors (dict(str, str)) – predecessors of this entity
successors (dict(str, str)) – successors of this entity
see_also (dict(str, str)) – more information
references (dict(str, str)) – references
other_ids (dict(str, str)) – other IDs
citations (dict(str, str)) – related citations
authors (dict(str, dict(str, str) or set) –
authors
This can either be:
a set:
{"Author A", "Author B"}
a dictionary where the keys are author names and values are dictionaries of more metadata:
{"Author A": {"https://../": "accountname", "..": ".."}}
The inner dictionary should have the reference or literal as key, and can take a “label”, which can be any of the FOAF attributes:
contributors (dict(str, dict(str, str) or set) – other contributors, follows the same format as authors
license (dict(str, str)) – license
funders (dict(str, str)) – funders
creation_date (str) – date in YYYY-MM-DD format when this was created (eg: 2024-04-19)
modified_dates (list(str)) – dates in YYYY-MM-DD format when modifications were made
write_to_file (str) – path to file to write to
- Returns:
the annotation string in the requested format.
- extract_annotations(nml2_file: str) Dict[str, Dict[Any, Any]] #
Extract and print annotations from a NeuroML 2 file.
- Parameters:
nml2_file (str) – name of NeuroML2 file to parse
- Returns:
dictionaries with annotations information
- Return type:
dict
- extract_annotations_from_string(xml_string: str) Dict[str, Dict[Any, Any]] #
Extract and print annotations from a NeuroML 2 string.
- Parameters:
xml_string (str) – XML string to parse
- Returns:
list of dictionaries with annotations information
- Return type:
list of dict
- parse_rdf(annotation_element: Element) Dict[str, Any] #
Parse RDF from an
<annotation>
element.Note that this is not a general purpose RDF parser. It is a specific parser for the RDF annotations that are used in NeuroML (which the
pyneuroml.annotations.Annotation.create_annotation()
method can write).- Parameters:
annotation_element (etree.Element) – an <annotation> element
- Returns:
annotation dictionary
- pyneuroml.annotations.create_annotation(*args, **kwargs)#
Wrapper around the Annotations.create_annotation method.
Added in version 1.2.13.
Please see
pyneuroml.annotations.Annotation.create_annotation()
for detailed documentation. The doc string is pasted below for convenience:This can be used to create an RDF annotation for a subject—a model or a file like an OMEX archive file. It supports most qualifiers and will be continuously updated to support more as they are added.
It merely uses rdflib to make life easier for users to create annotations by coding in the various predicates for each subject.
For information on the specifications, see:
COMBINE specifications: combine-org/combine-specifications
Biosimulations guidelines: https://docs.biosimulations.org/concepts/conventions/simulation-project-metadata/
MIRIAM guidelines: https://drive.google.com/file/d/1JqjcH0T0UTWMuBj-scIMwsyt2z38A0vp/view
Note that:
not all qualifiers have been included yet
the qualifiers and their representations may change in the future
For any arguments here that take a dictionary of strings, the key is the resource reference URI, and the value is the string label. For example:
encodes_other_biology={ "http://identifiers.org/GO:0009653": "anatomical structure morphogenesis", "http://identifiers.org/kegg:ko04111": "Cell cycle - yeast", }
- Parameters:
subject (str) – subject/target of the annotation could be a file, a mode component
title (str) – title of annotation This is required for publishing models on biosimulations.org
abstract (str) – an abstract
annotation_style (str) –
type of annotation: either “miriam” or “biosimulations” (default).
There’s a difference in the annotation “style” suggested by MIRIAM and Biosimulations. MIRIAM suggests the use of RDF containers (bags) wherewas Biosimulations does not. This argument allows the user to select what style they want to use for the annotation.
serialization_format (str) –
format to serialize in using rdflib.serialize
See: https://rdflib.readthedocs.io/en/stable/plugin_serializers.html
xml_header (bool) – toggle inclusion of xml header if serializing in xml format
indent (int) – number of spaces to use to indent the annotation block
description (str) – a longer description
is (dict(str, str)) – biological entity represented by the model
keywords (list(str)) – keywords
thumbnails (list(str)) – thumbnails
organisms (dict(str, str)) – of organisms
encodes_other_biology (dict(str, str)) – other biological entities
has_version (dict(str, str)) – other versions
is_version_of (dict(str, str)) – is a version of
has_part (dict(str, str)) – includes another as a part
is_part_of (dict(str, str)) – is a part of another entity
has_property (dict(str, str)) – has a property
is_property_of (dict(str, str)) – is a property of another entity
sources (dict(str, str)) – links to sources (on GitHub and so on)
is_instance_of (dict(str, str)) – is an instance of
has_instance (dict(str, str)) – has instance of another entity
predecessors (dict(str, str)) – predecessors of this entity
successors (dict(str, str)) – successors of this entity
see_also (dict(str, str)) – more information
references (dict(str, str)) – references
other_ids (dict(str, str)) – other IDs
citations (dict(str, str)) – related citations
authors (dict(str, dict(str, str) or set) –
authors
This can either be:
a set:
{"Author A", "Author B"}
a dictionary where the keys are author names and values are dictionaries of more metadata:
{"Author A": {"https://../": "accountname", "..": ".."}}
The inner dictionary should have the reference or literal as key, and can take a “label”, which can be any of the FOAF attributes:
contributors (dict(str, dict(str, str) or set) – other contributors, follows the same format as authors
license (dict(str, str)) – license
funders (dict(str, str)) – funders
creation_date (str) – date in YYYY-MM-DD format when this was created (eg: 2024-04-19)
modified_dates (list(str)) – dates in YYYY-MM-DD format when modifications were made
write_to_file (str) – path to file to write to
- Returns:
the annotation string in the requested format.
- pyneuroml.annotations.extract_annotations(nml2_file: str)#
Wrapper around the Annotations.extract_annotations method.
Please see
pyneuroml.annotations.Annotation.extract_annotations()
for detailed documentation.Added in version 1.2.13.
- Parameters:
nml2_file (str) – name of NeuroML2 file to parse
- Returns:
dictionaries with annotations information
- Return type:
dict