Skip to content

Commit

Permalink
feat: made abstract metadata option; added module to convert GINsim d…
Browse files Browse the repository at this point in the history
…iagrams to Vega
  • Loading branch information
jonrkarr committed Jul 28, 2021
1 parent 242f1b5 commit 61c9af5
Show file tree
Hide file tree
Showing 29 changed files with 3,755 additions and 93 deletions.
123 changes: 97 additions & 26 deletions biosimulators_utils/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def _default(self):


class ConvertEscherController(cement.Controller):
""" Controller for converting Escher maps to Vega visualizations """
""" Controller for converting Escher maps to Vega data visualizations """

class Meta:
label = 'escher-to-vega'
Expand All @@ -334,7 +334,7 @@ class Meta:
description = "Convert an Escher map of a metabolic network to the Vega data visualization format"
arguments = [
(
['--flux-sedml-report'],
['--data-sedml'],
dict(
type=str,
help=(
Expand All @@ -346,7 +346,7 @@ class Meta:
),
),
(
['--flux-file'],
['--data-file'],
dict(
type=str,
help=(
Expand All @@ -358,7 +358,7 @@ class Meta:
),
),
(
['--flux-url'],
['--data-url'],
dict(
type=str,
help=(
Expand All @@ -382,43 +382,113 @@ class Meta:
dict(
metavar='vega-file',
type=str,
help='Path to save the Escher map in Vega format',
help='Path to save the diagram in Vega format',
),
),
]

@cement.ex(hide=True)
def _default(self):
from biosimulators_utils.viz.vega.escher.core import escher_to_vega
_convert_diagram(self.app.pargs, 'escher_file', escher_to_vega)

args = self.app.pargs

n_flux_args = (
(args.flux_sedml_report is not None) +
(args.flux_file is not None) +
(args.flux_url is not None)
)
class ConvertGinmlController(cement.Controller):
""" Controller for converting GINML activity flow diagrams to Vega data visualizations """

if n_flux_args == 0:
raise SystemExit('One of --flux-sedml-report, --flux-file, or --flux-url must be used')
elif n_flux_args > 1:
raise SystemExit('Only one of --flux-sedml-report, --flux-file, or --flux-url can be used')
class Meta:
label = 'ginml-to-vega'
stacked_on = 'convert'
stacked_type = 'nested'
help = "Convert a GINML activity flow diagram to Vega"
description = "Convert a GINML activity flow diagram to the Vega data visualization format"
arguments = [
(
['--data-sedml'],
dict(
action='store_true',
help=(
'Set to indicate that the predicted value of each node should be read from the reports of '
'the SED-ML files in a COMBINE archive'
),
),
),
(
['--data-file'],
dict(
type=str,
help=(
'Path to a JSON file which represents a list of dictionaries, each which have two keys '
'`label` and `values` whose values are the ids of nodes and arrays of their predicted values'
),
default=None,
),
),
(
['--data-url'],
dict(
type=str,
help=(
'URL for a JSON file which represents a list of dictionaries, each which have two keys '
'`label` and `values` whose values are the ids of nodes and arrays of their predicted values'
),
default=None,
),
),
(
['ginml_file'],
dict(
metavar='ginml-file',
type=str,
help='Path to the GINML file',
),
),
(
['vega_file'],
dict(
metavar='vega-file',
type=str,
help='Path to save the diagram in Vega format',
),
),
]

@cement.ex(hide=True)
def _default(self):
from biosimulators_utils.viz.vega.ginml.core import ginml_to_vega
_convert_diagram(self.app.pargs, 'ginml_file', ginml_to_vega)

if args.flux_sedml_report:
sedDocumentlocation, _, reportId = args.flux_sedml_report.rpartition('/')
reaction_fluxes_data_set = {'sedmlUri': [sedDocumentlocation, reportId]}

elif args.flux_file:
with open(args.flux_file, 'rb') as file:
reaction_fluxes_data_set = {'values': json.load(file)}
def _convert_diagram(args, diagram_file_attr, converter):
n_data_args = (
(args.data_sedml not in [None, False]) +
(args.data_file is not None) +
(args.data_url is not None)
)

if n_data_args == 0:
raise SystemExit('One of --data-sedml, --data-file, or --data-url must be used')
elif n_data_args > 1:
raise SystemExit('Only one of --data-sedml, --data-file, or --data-url can be used')

if args.data_sedml:
if isinstance(args.data_sedml, bool):
data_set = {'sedmlUri': []}
else:
reaction_fluxes_data_set = {'url': args.flux_url}
sedDocumentlocation, _, reportId = args.data_sedml.rpartition('/')
data_set = {'sedmlUri': [sedDocumentlocation, reportId]}

try:
escher_to_vega(reaction_fluxes_data_set, args.escher_file, args.vega_file)
except Exception as exception:
raise SystemExit(str(exception))
elif args.data_file:
with open(args.data_file, 'rb') as file:
data_set = {'values': json.load(file)}

else:
data_set = {'url': args.data_url}

try:
converter(data_set, getattr(args, diagram_file_attr), args.vega_file)
except Exception as exception:
raise SystemExit(str(exception))


class App(cement.App):
Expand All @@ -433,6 +503,7 @@ class Meta:
ExecuteModelingProjectController,
ConvertController,
ConvertEscherController,
ConvertGinmlController,
]


Expand Down
56 changes: 28 additions & 28 deletions biosimulators_utils/omex_meta/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,31 @@ class OmexMetaSchema(str, enum.Enum):
BIOSIMULATIONS_ROOT_URI_PATTERN = r'^http://omex-libary\.org/.*?\.omex$'

BIOSIMULATIONS_PREDICATE_TYPES = {
'https://dublincore.org/specifications/dublin-core/dcmi-terms/title': {
'http://dublincore.org/specifications/dublin-core/dcmi-terms/title': {
'namespace': {
'prefix': 'dc',
'uri': 'https://dublincore.org/specifications/dublin-core/dcmi-terms/',
'uri': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/',
},
'uri': 'https://dublincore.org/specifications/dublin-core/dcmi-terms/title',
'uri': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/title',
'attribute': 'title',
'label': 'title',
'multiple_allowed': False,
'has_uri': False,
'has_label': True,
'required': True,
},
'https://dublincore.org/specifications/dublin-core/dcmi-terms/abstract': {
'http://dublincore.org/specifications/dublin-core/dcmi-terms/abstract': {
'namespace': {
'prefix': 'dc',
'uri': 'https://dublincore.org/specifications/dublin-core/dcmi-terms/',
'uri': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/',
},
'uri': 'https://dublincore.org/specifications/dublin-core/dcmi-terms/abstract',
'uri': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/abstract',
'attribute': 'abstract',
'label': 'Abstract',
'multiple_allowed': False,
'has_uri': False,
'has_label': True,
'required': True,
'required': False,
},
'http://prismstandard.org/namespaces/basic/2.0/keyword': {
'namespace': {
Expand All @@ -115,12 +115,12 @@ class OmexMetaSchema(str, enum.Enum):
'has_label': True,
'required': False,
},
'https://dublincore.org/specifications/dublin-core/dcmi-terms/description': {
'http://dublincore.org/specifications/dublin-core/dcmi-terms/description': {
'namespace': {
'prefix': 'dc',
'uri': 'https://dublincore.org/specifications/dublin-core/dcmi-terms/',
'uri': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/',
},
'uri': 'https://dublincore.org/specifications/dublin-core/dcmi-terms/description',
'uri': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/description',
'attribute': 'description',
'label': 'Description',
'multiple_allowed': False,
Expand Down Expand Up @@ -167,12 +167,12 @@ class OmexMetaSchema(str, enum.Enum):
'has_label': False,
'required': False,
},
'https://dublincore.org/specifications/dublin-core/dcmi-terms/source': {
'http://dublincore.org/specifications/dublin-core/dcmi-terms/source': {
'namespace': {
'prefix': 'dc',
'uri': 'https://dublincore.org/specifications/dublin-core/dcmi-terms/',
'uri': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/',
},
'uri': 'https://dublincore.org/specifications/dublin-core/dcmi-terms/source',
'uri': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/source',
'attribute': 'sources',
'label': 'Sources',
'multiple_allowed': True,
Expand Down Expand Up @@ -219,25 +219,25 @@ class OmexMetaSchema(str, enum.Enum):
'has_label': True,
'required': False,
},
'https://dublincore.org/specifications/dublin-core/dcmi-terms/creator': {
'http://dublincore.org/specifications/dublin-core/dcmi-terms/creator': {
'namespace': {
'prefix': 'dc',
'uri': 'https://dublincore.org/specifications/dublin-core/dcmi-terms/',
'uri': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/',
},
'uri': 'https://dublincore.org/specifications/dublin-core/dcmi-terms/creator',
'uri': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/creator',
'attribute': 'creators',
'label': 'Creators',
'multiple_allowed': True,
'has_uri': True,
'has_label': True,
'required': True,
},
'https://dublincore.org/specifications/dublin-core/dcmi-terms/contributor': {
'http://dublincore.org/specifications/dublin-core/dcmi-terms/contributor': {
'namespace': {
'prefix': 'dc',
'uri': 'https://dublincore.org/specifications/dublin-core/dcmi-terms/',
'uri': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/',
},
'uri': 'https://dublincore.org/specifications/dublin-core/dcmi-terms/contributor',
'uri': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/contributor',
'attribute': 'contributors',
'label': 'Contributors',
'multiple_allowed': True,
Expand Down Expand Up @@ -271,12 +271,12 @@ class OmexMetaSchema(str, enum.Enum):
'has_label': True,
'required': False,
},
'https://dublincore.org/specifications/dublin-core/dcmi-terms/license': {
'http://dublincore.org/specifications/dublin-core/dcmi-terms/license': {
'namespace': {
'prefix': 'dc',
'uri': 'https://dublincore.org/specifications/dublin-core/dcmi-terms/',
'uri': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/',
},
'uri': 'https://dublincore.org/specifications/dublin-core/dcmi-terms/license',
'uri': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/license',
'attribute': 'license',
'label': 'License',
'multiple_allowed': False,
Expand All @@ -297,25 +297,25 @@ class OmexMetaSchema(str, enum.Enum):
'has_label': True,
'required': False,
},
'https://dublincore.org/specifications/dublin-core/dcmi-terms/created': {
'http://dublincore.org/specifications/dublin-core/dcmi-terms/created': {
'namespace': {
'prefix': 'dc',
'uri': 'https://dublincore.org/specifications/dublin-core/dcmi-terms/',
'uri': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/',
},
'uri': 'https://dublincore.org/specifications/dublin-core/dcmi-terms/created',
'uri': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/created',
'attribute': 'created',
'label': 'Created',
'multiple_allowed': False,
'has_uri': False,
'has_label': True,
'required': False,
},
'https://dublincore.org/specifications/dublin-core/dcmi-terms/modified': {
'http://dublincore.org/specifications/dublin-core/dcmi-terms/modified': {
'namespace': {
'prefix': 'dc',
'uri': 'https://dublincore.org/specifications/dublin-core/dcmi-terms/',
'uri': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/',
},
'uri': 'https://dublincore.org/specifications/dublin-core/dcmi-terms/modified',
'uri': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/modified',
'attribute': 'modified',
'label': 'Modified',
'multiple_allowed': True,
Expand Down
12 changes: 6 additions & 6 deletions biosimulators_utils/omex_meta/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def parse_triples_to_schema(cls, triples, root_uri):
}
for sub_el in el['value'].get('other', []):
if (
sub_el['predicate'] == 'https://dublincore.org/specifications/dublin-core/dcmi-terms/identifier'
sub_el['predicate'] == 'http://dublincore.org/specifications/dublin-core/dcmi-terms/identifier'
and 'uri' in sub_el['value']
):
value['uri'] = sub_el['value']['uri']
Expand Down Expand Up @@ -558,13 +558,13 @@ def parse_triples_to_schema(cls, triples, root_uri):
}
for el in other_md['value'].get('description', []):
if (
el['predicate'] == 'https://dublincore.org/specifications/dublin-core/dcmi-terms/description'
el['predicate'] == 'http://dublincore.org/specifications/dublin-core/dcmi-terms/description'
and 'label' in el['value']
):
value['attribute']['label'] = el['value']['label']
for el in other_md['value'].get('other', []):
if (
el['predicate'] == 'https://dublincore.org/specifications/dublin-core/dcmi-terms/identifier'
el['predicate'] == 'http://dublincore.org/specifications/dublin-core/dcmi-terms/identifier'
and 'uri' in el['value']
):
value['value']['uri'] = el['value']['uri']
Expand Down Expand Up @@ -621,7 +621,7 @@ def run(self, el_metadatas, filename, format=OmexMetaOutputFormat.rdfxml_abbrev)
local_id = 0

namespaces = {
'dc': rdflib.Namespace('https://dublincore.org/specifications/dublin-core/dcmi-terms/'),
'dc': rdflib.Namespace('http://dublincore.org/specifications/dublin-core/dcmi-terms/'),
'dcterms': rdflib.Namespace('http://purl.org/dc/terms/'),
'foaf': rdflib.Namespace('http://xmlns.com/foaf/0.1/'),
'rdfs': rdflib.Namespace('http://www.w3.org/2000/01/rdf-schema#'),
Expand Down Expand Up @@ -664,8 +664,8 @@ def run(self, el_metadatas, filename, format=OmexMetaOutputFormat.rdfxml_abbrev)
))

if predicate_type['uri'] in [
'https://dublincore.org/specifications/dublin-core/dcmi-terms/creator',
'https://dublincore.org/specifications/dublin-core/dcmi-terms/contributor',
'http://dublincore.org/specifications/dublin-core/dcmi-terms/creator',
'http://dublincore.org/specifications/dublin-core/dcmi-terms/contributor',
]:
if value.get('uri', None) is not None:
triples.append(Triple(
Expand Down
2 changes: 1 addition & 1 deletion biosimulators_utils/viz/vega/escher/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def escher_to_vega(reaction_fluxes_data_set, escher_filename, vega_filename,
should be a dictionary with two keys
* ``label``: value should be the BiGG identifier of the corresponding reaction
* ``values``: array of with a single value equal to the predicted flux
* ``values``: array with a single value equal to the predicted flux
* Contain a key ``url`` whose value is a URL where the predicted flux values can be retrieved in JSON
format. The data should be in the same format outlined above.
Expand Down
1 change: 1 addition & 0 deletions biosimulators_utils/viz/vega/ginml/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .core import ginml_to_vega # noqa: F401
Loading

0 comments on commit 61c9af5

Please sign in to comment.