nmdc-runtime 1.6.0__py3-none-any.whl → 1.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of nmdc-runtime might be problematic. Click here for more details.
- nmdc_runtime/site/export/ncbi_xml.py +433 -0
- nmdc_runtime/site/export/ncbi_xml_utils.py +206 -0
- nmdc_runtime/site/export/study_metadata.py +24 -4
- nmdc_runtime/site/graphs.py +24 -12
- nmdc_runtime/site/ops.py +120 -44
- nmdc_runtime/site/repository.py +56 -6
- nmdc_runtime/site/resources.py +30 -40
- nmdc_runtime/site/translation/submission_portal_translator.py +16 -9
- nmdc_runtime/util.py +1 -1
- {nmdc_runtime-1.6.0.dist-info → nmdc_runtime-1.7.0.dist-info}/METADATA +4 -7
- {nmdc_runtime-1.6.0.dist-info → nmdc_runtime-1.7.0.dist-info}/RECORD +15 -17
- {nmdc_runtime-1.6.0.dist-info → nmdc_runtime-1.7.0.dist-info}/WHEEL +1 -1
- {nmdc_runtime-1.6.0.dist-info → nmdc_runtime-1.7.0.dist-info}/entry_points.txt +0 -1
- nmdc_runtime/site/terminusdb/__init__.py +0 -0
- nmdc_runtime/site/terminusdb/generate.py +0 -198
- nmdc_runtime/site/terminusdb/ingest.py +0 -44
- nmdc_runtime/site/terminusdb/schema.py +0 -1671
- {nmdc_runtime-1.6.0.dist-info → nmdc_runtime-1.7.0.dist-info}/LICENSE +0 -0
- {nmdc_runtime-1.6.0.dist-info → nmdc_runtime-1.7.0.dist-info}/top_level.txt +0 -0
|
@@ -2,4 +2,3 @@
|
|
|
2
2
|
nmdcdb-mongodump = nmdc_runtime.site.backup.nmdcdb_mongodump:main
|
|
3
3
|
nmdcdb-mongoexport = nmdc_runtime.site.backup.nmdcdb_mongoexport:main
|
|
4
4
|
nmdcdb-mongoimport = nmdc_runtime.site.backup.nmdcdb_mongoimport:main
|
|
5
|
-
schemagen-terminusdb = nmdc_runtime.site.terminusdb.generate:cli
|
|
File without changes
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Example usage:
|
|
3
|
-
$ schemagen-terminusdb ../nmdc-schema/src/schema/nmdc.yaml \
|
|
4
|
-
> nmdc_runtime/site/terminusdb/nmdc.schema.terminusdb.json
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import json
|
|
8
|
-
import os
|
|
9
|
-
from typing import Union, TextIO, List
|
|
10
|
-
|
|
11
|
-
import click
|
|
12
|
-
from linkml.utils.generator import Generator, shared_arguments
|
|
13
|
-
from linkml_runtime.linkml_model.meta import (
|
|
14
|
-
SchemaDefinition,
|
|
15
|
-
ClassDefinition,
|
|
16
|
-
SlotDefinition,
|
|
17
|
-
)
|
|
18
|
-
from linkml_runtime.utils.formatutils import camelcase, be, underscore
|
|
19
|
-
|
|
20
|
-
# http://books.xmlschemata.org/relaxng/relax-CHP-19.html
|
|
21
|
-
XSD_Ok = {
|
|
22
|
-
"xsd:anyURI",
|
|
23
|
-
"xsd:base64Binary",
|
|
24
|
-
"xsd:boolean",
|
|
25
|
-
"xsd:byte",
|
|
26
|
-
"xsd:date",
|
|
27
|
-
"xsd:dateTime",
|
|
28
|
-
"xsd:decimal",
|
|
29
|
-
"xsd:double",
|
|
30
|
-
"xsd:duration",
|
|
31
|
-
"xsd:ENTITIES",
|
|
32
|
-
"xsd:ENTITY",
|
|
33
|
-
"xsd:float",
|
|
34
|
-
"xsd:gDay",
|
|
35
|
-
"xsd:gMonth",
|
|
36
|
-
"xsd:gMonthDay",
|
|
37
|
-
"xsd:gYear",
|
|
38
|
-
"xsd:gYearMonth",
|
|
39
|
-
"xsd:hexBinary",
|
|
40
|
-
"xsd:ID",
|
|
41
|
-
"xsd:IDREF",
|
|
42
|
-
"xsd:IDREFS",
|
|
43
|
-
"xsd:int",
|
|
44
|
-
"xsd:integer",
|
|
45
|
-
"xsd:language",
|
|
46
|
-
"xsd:long",
|
|
47
|
-
"xsd:Name",
|
|
48
|
-
"xsd:NCName",
|
|
49
|
-
"xsd:negativeInteger",
|
|
50
|
-
"xsd:NMTOKEN",
|
|
51
|
-
"xsd:NMTOKENS",
|
|
52
|
-
"xsd:nonNegativeInteger",
|
|
53
|
-
"xsd:nonPositiveInteger",
|
|
54
|
-
"xsd:normalizedString",
|
|
55
|
-
"xsd:NOTATION",
|
|
56
|
-
"xsd:positiveInteger",
|
|
57
|
-
"xsd:short",
|
|
58
|
-
"xsd:string",
|
|
59
|
-
"xsd:time",
|
|
60
|
-
"xsd:token",
|
|
61
|
-
"xsd:unsignedByte",
|
|
62
|
-
"xsd:unsignedInt",
|
|
63
|
-
"xsd:unsignedLong",
|
|
64
|
-
"xsd:unsignedShort",
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def as_list(thing) -> list:
|
|
69
|
-
return thing if isinstance(thing, list) else [thing]
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
def has_field(graph: List[dict], cls: dict, field: str) -> bool:
|
|
73
|
-
if field in cls:
|
|
74
|
-
return True
|
|
75
|
-
for parent_id in as_list(cls.get("@inherits", [])):
|
|
76
|
-
parent_cls = next(
|
|
77
|
-
graph_cls for graph_cls in graph if graph_cls.get("@id") == parent_id
|
|
78
|
-
)
|
|
79
|
-
if parent_cls and has_field(graph, parent_cls, field):
|
|
80
|
-
return True
|
|
81
|
-
return False
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
class TerminusdbGenerator(Generator):
|
|
85
|
-
"""Generates JSON file to pass to WOQLClient.insert_document(..., graph_type="schema")`."""
|
|
86
|
-
|
|
87
|
-
generatorname = os.path.basename(__file__)
|
|
88
|
-
generatorversion = "0.1.0"
|
|
89
|
-
valid_formats = ["json"]
|
|
90
|
-
visit_all_class_slots = True
|
|
91
|
-
|
|
92
|
-
def __init__(self, schema: Union[str, TextIO, SchemaDefinition], **kwargs) -> None:
|
|
93
|
-
super().__init__(schema, **kwargs)
|
|
94
|
-
self.graph = []
|
|
95
|
-
self.cls_json = {}
|
|
96
|
-
|
|
97
|
-
def visit_schema(self, inline: bool = False, **kwargs) -> None:
|
|
98
|
-
self.graph.append(
|
|
99
|
-
{
|
|
100
|
-
"@type": "@context",
|
|
101
|
-
"@base": "https://api.microbiomedata.org/nmdcschema/ids/",
|
|
102
|
-
"@schema": "https://w3id.org/nmdc/",
|
|
103
|
-
}
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
def end_schema(self, **_) -> None:
|
|
107
|
-
for cls in self.graph:
|
|
108
|
-
if has_field(self.graph, cls, "id"):
|
|
109
|
-
cls["@key"] = {"@type": "Lexical", "@fields": ["id"]}
|
|
110
|
-
print(json.dumps(self.graph, indent=2))
|
|
111
|
-
|
|
112
|
-
def visit_class(self, cls: ClassDefinition) -> bool:
|
|
113
|
-
self.cls_json = {
|
|
114
|
-
"@type": "Class",
|
|
115
|
-
"@id": camelcase(cls.name),
|
|
116
|
-
"@documentation": {
|
|
117
|
-
"@comment": be(cls.description),
|
|
118
|
-
"@properties": {},
|
|
119
|
-
},
|
|
120
|
-
}
|
|
121
|
-
if cls.is_a:
|
|
122
|
-
self.cls_json["@inherits"] = camelcase(cls.is_a)
|
|
123
|
-
if cls.abstract:
|
|
124
|
-
self.cls_json["@abstract"] = []
|
|
125
|
-
return True
|
|
126
|
-
|
|
127
|
-
def end_class(self, cls: ClassDefinition) -> None:
|
|
128
|
-
self.cls_json["@id"] = cls.definition_uri.split(":")[-1].rpartition("/")[-1]
|
|
129
|
-
self.graph.append(self.cls_json)
|
|
130
|
-
|
|
131
|
-
# sounding board as solist
|
|
132
|
-
# safe space to ask questions. more of a whatsapp group.
|
|
133
|
-
# both re: business, how to structure proposals, etc.
|
|
134
|
-
# And also technical content suggestions. R data pipeline / copy/paste in Figma
|
|
135
|
-
# - how far do you go in automation in delivery
|
|
136
|
-
|
|
137
|
-
def visit_class_slot(
|
|
138
|
-
self, cls: ClassDefinition, aliased_slot_name: str, slot: SlotDefinition
|
|
139
|
-
) -> None:
|
|
140
|
-
if slot not in self.own_slots(cls):
|
|
141
|
-
return
|
|
142
|
-
if slot.is_usage_slot:
|
|
143
|
-
# TerminusDB does not support calling different things the same name.
|
|
144
|
-
# So, ignore usage overrides.
|
|
145
|
-
slot = self.schema.slots[aliased_slot_name]
|
|
146
|
-
|
|
147
|
-
if slot.range in self.schema.classes:
|
|
148
|
-
rng = camelcase(slot.range)
|
|
149
|
-
elif slot.range in self.schema.types:
|
|
150
|
-
# XXX Why does `linkml.utils.metamodelcore.Identifier` subclass `str`??
|
|
151
|
-
rng = str(self.schema.types[slot.range].uri)
|
|
152
|
-
else:
|
|
153
|
-
rng = "xsd:string"
|
|
154
|
-
|
|
155
|
-
# name = (
|
|
156
|
-
# f"{cls.name} {aliased_slot_name}"
|
|
157
|
-
# if slot.is_usage_slot
|
|
158
|
-
# else aliased_slot_name
|
|
159
|
-
# )
|
|
160
|
-
name = slot.name
|
|
161
|
-
# TODO fork nmdc schema and make any slots NOT required in parent class
|
|
162
|
-
# also NOT required in child classes. Can have opt-in entity validation logic in code.
|
|
163
|
-
|
|
164
|
-
# XXX MAG bin -> bin name goes to "mAGBin__bin_name", etc. Weird.
|
|
165
|
-
|
|
166
|
-
# # translate to terminusdb xsd builtins:
|
|
167
|
-
# if rng == "xsd:int":
|
|
168
|
-
# rng = "xsd:integer"
|
|
169
|
-
# elif rng == "xsd:float":
|
|
170
|
-
# rng = "xsd:double"
|
|
171
|
-
# elif rng == "xsd:language":
|
|
172
|
-
# rng = "xsd:string"
|
|
173
|
-
|
|
174
|
-
if rng not in XSD_Ok and slot.range not in self.schema.classes:
|
|
175
|
-
raise Exception(
|
|
176
|
-
f"slot range for {name} must be schema class or supported xsd type. "
|
|
177
|
-
f"Range {rng} is of type {type(rng)}."
|
|
178
|
-
)
|
|
179
|
-
|
|
180
|
-
self.cls_json[underscore(name)] = rng
|
|
181
|
-
self.cls_json["@documentation"]["@properties"][
|
|
182
|
-
underscore(name)
|
|
183
|
-
] = slot.description
|
|
184
|
-
if not slot.required:
|
|
185
|
-
self.cls_json[underscore(name)] = {"@type": "Optional", "@class": rng}
|
|
186
|
-
if slot.multivalued: # XXX what about an required multivalued field?
|
|
187
|
-
self.cls_json[underscore(name)] = {"@type": "Set", "@class": rng}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
@shared_arguments(TerminusdbGenerator)
|
|
191
|
-
@click.command()
|
|
192
|
-
def cli(yamlfile, **args):
|
|
193
|
-
"""Generate graphql representation of a biolink model"""
|
|
194
|
-
print(TerminusdbGenerator(yamlfile, **args).serialize(**args))
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if __name__ == "__main__":
|
|
198
|
-
cli()
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
from pathlib import Path
|
|
3
|
-
|
|
4
|
-
from terminusdb_client import WOQLClient
|
|
5
|
-
|
|
6
|
-
team = "admin"
|
|
7
|
-
client = WOQLClient(f"http://localhost:6364/")
|
|
8
|
-
# make sure you have put the token in environment variable
|
|
9
|
-
# https://docs.terminusdb.com/v10.0/#/terminusx/get-your-api-key
|
|
10
|
-
client.connect(user=team, team=team, key="root")
|
|
11
|
-
|
|
12
|
-
dbid = "nmdc"
|
|
13
|
-
label = "NMDC"
|
|
14
|
-
description = "."
|
|
15
|
-
prefixes = {
|
|
16
|
-
"@base": "terminusdb:///data/",
|
|
17
|
-
"@schema": "terminusdb:///schema#",
|
|
18
|
-
"gold": "https://gold.jgi.doe.gov/biosample?id=",
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def import_schema(client):
|
|
23
|
-
# sd = get_nmdc_schema_definition()
|
|
24
|
-
# sd.source_file = f"{REPO_ROOT_DIR.parent}/nmdc-schema/src/schema/nmdc.yaml"
|
|
25
|
-
# print(sd.source_file)
|
|
26
|
-
with open(Path(__file__).parent.joinpath("nmdc.schema.terminusdb.json")) as f:
|
|
27
|
-
schema_objects = json.load(f)
|
|
28
|
-
|
|
29
|
-
client.message = "Adding NMDC Schema"
|
|
30
|
-
results = client.insert_document(schema_objects, graph_type="schema")
|
|
31
|
-
print(f"Added schema: {results}")
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if __name__ == "__main__":
|
|
35
|
-
exists = client.get_database(dbid)
|
|
36
|
-
|
|
37
|
-
if exists:
|
|
38
|
-
client.delete_database(dbid, team=team, force=True)
|
|
39
|
-
|
|
40
|
-
client.create_database(
|
|
41
|
-
dbid, team, label=label, description=description, prefixes=prefixes
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
import_schema(client)
|