Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DTS Manifest parsing #210

Merged
merged 10 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions staging_service/import_specifications/individual_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Contains parser functions for use with the file parser framework.
"""

from collections import defaultdict
import csv
import json
import math
Expand Down Expand Up @@ -60,6 +61,11 @@
"null",
]

_DTS_INSTRUCTIONS_KEY = "instructions"
_DTS_INSTRUCTIONS_DATATYPE_KEY = "data_type"
_DTS_INSTRUCTIONS_PARAMETERS_KEY = "parameters"
_DTS_INSTRUCTIONS_OBJECTS_KEY = "objects"


class _ParseException(Exception):
pass
Expand Down Expand Up @@ -351,15 +357,27 @@ def parse_dts_manifest(path: Path, validator: Draft202012Validator) -> ParseResu
results = {}
try:
with open(path, "r") as manifest:
manifest_json = json.load(manifest)
if not isinstance(manifest_json, dict):
manifest = json.load(manifest)
if not isinstance(manifest, dict):
return _error(Error(ErrorType.PARSE_FAIL, "Manifest is not a dictionary", spcsrc))
for err in validator.iter_errors(manifest_json):
for err in validator.iter_errors(manifest):
err_str = err.message
err_path = list(err.absolute_path)
if err_path:
err_str += f" at {err_path}"
errors.append(Error(ErrorType.PARSE_FAIL, err_str, spcsrc))
if not errors:
results = defaultdict(list)
instructions = manifest[_DTS_INSTRUCTIONS_KEY]
for resource_obj in instructions[_DTS_INSTRUCTIONS_OBJECTS_KEY]:
datatype = resource_obj[_DTS_INSTRUCTIONS_DATATYPE_KEY]
parameters = frozendict(resource_obj[_DTS_INSTRUCTIONS_PARAMETERS_KEY])
Copy link
Member

@MrCreosote MrCreosote Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the DTS has to know the app parameter names for each datatype it processes? IOW the DTS is coupled to the apps?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also assume the file names / locations in the staging area are in the parameters? They can't be anywhere else...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes to both. We talked about doing some references from the parameters to file paths, but if we do that'll be in a later version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that seems less than ideal, but if you've agreed that that's how it'll work so be it

results[datatype].append(parameters)
# Re-package results as a dict of {datatype: ParseResult}
results = {
datatype: ParseResult(spcsrc, tuple(paramlist))
for datatype, paramlist in results.items()
}
except json.JSONDecodeError:
return _error(Error(ErrorType.PARSE_FAIL, "File must be in JSON format", spcsrc))
except FileNotFoundError:
Expand Down
81 changes: 81 additions & 0 deletions tests/import_specifications/test_data/manifest_errors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"name": "manifest",
"resources": [
{
"id": "JDP:555518eb0d8785178e712d88",
"name": "61564.assembled",
"path": "img/submissions/61564/61564.assembled.gff",
"format": "gff",
"media_type": "text/plain",
"bytes": 455161,
"hash": "",
"credit": {
"comment": "",
"content_url": "",
"contributors": null,
"credit_metadata_source": "",
"dates": null,
"descriptions": null,
"funding": null,
"identifier": "JDP:555518eb0d8785178e712d88",
"license": {
"id": "",
"url": ""
},
"publisher": {
"organization_id": "",
"organization_name": ""
},
"related_identifiers": null,
"resource_type": "dataset",
"titles": null,
"url": "",
"version": ""
}
},
{
"id": "JDP:555518eb0d8785178e712d84",
"name": "61564.assembled",
"path": "img/submissions/61564/61564.assembled.fna",
"format": "fasta",
"media_type": "text/plain",
"bytes": 6354414,
"hash": "",
"credit": {
"comment": "",
"content_url": "",
"contributors": null,
"credit_metadata_source": "",
"dates": null,
"descriptions": null,
"funding": null,
"identifier": "JDP:555518eb0d8785178e712d84",
"license": {
"id": "",
"url": ""
},
"publisher": {
"organization_id": "",
"organization_name": ""
},
"related_identifiers": null,
"resource_type": "dataset",
"titles": null,
"url": "",
"version": ""
}
}
],
"instructions": {
"protocol": "KBase narrative import",
"objects": [
{
"data_type": "gff_metagenome",
"parameters": {
"param1": "value1",
"param2": "value2"
}
}
]
}
}
62 changes: 62 additions & 0 deletions tests/import_specifications/test_data/manifest_multiple.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "manifest",
"resources": [
{
"id": "JDP:555518eb0d8785178e712d88",
"name": "61564.assembled",
"path": "img/submissions/61564/61564.assembled.gff",
"format": "gff"
},
{
"id": "JDP:555518eb0d8785178e712d84",
"name": "61564.assembled",
"path": "img/submissions/61564/61564.assembled.fna",
"format": "fasta"
},
{
"id": "JDP:555518ec0d8785178e712d9f",
"name": "61567.assembled",
"path": "img/submissions/61567/61567.assembled.gff",
"format": "gff"
},
{
"id": "JDP:555518ec0d8785178e712d9b",
"name": "61567.assembled",
"path": "img/submissions/61567/61567.assembled.fna",
"format": "fasta"
}
],
"instructions": {
"protocol": "KBase narrative import",
"objects": [
{
"data_type": "gff_metagenome",
"parameters": {
"mg_param1": "value1",
"mg_param2": "value2"
}
},
{
"data_type": "gff_metagenome",
"parameters": {
"mg_param1": "value3",
"mg_param2": "value4"
}
},
{
"data_type": "gff_genome",
"parameters": {
"gen_param1": "value1",
"gen_param2": "value2"
}
},
{
"data_type": "gff_genome",
"parameters": {
"gen_param1": "value3",
"gen_param2": "value4"
}
}
]
}
}
41 changes: 23 additions & 18 deletions tests/import_specifications/test_data/manifest_small.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@
"titles": null,
"url": "",
"version": ""
},
"instructions": {
"data_type": "gff_metagenome",
"parameters": {
"param1": "value1",
"param2": "value2"
}
}
},
{
Expand Down Expand Up @@ -70,13 +63,6 @@
"titles": null,
"url": "",
"version": ""
},
"instructions": {
"data_type": "gff_metagenome",
"parameters": {
"param1": "value1",
"param2": "value2"
}
}
},
{
Expand Down Expand Up @@ -109,14 +95,33 @@
"titles": null,
"url": "",
"version": ""
},
"instructions": {
}
}
],
"instructions": {
"protocol": "KBase narrative import",
"objects": [
{
"data_type": "gff_metagenome",
"parameters": {
"param1": "value1",
"param2": "value2"
}
},
{
"data_type": "gff_metagenome",
"parameters": {
"param1": "value3",
"param2": "value4"
}
},
{
"data_type": "gff_metagenome",
"parameters": {
"param1": "value5",
"param2": "value6"
}
}
}
]
]
}
}
Loading
Loading