linkml-phenopackets 0.1.0rc1__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.
- linkml_phenopackets/__init__.py +16 -0
- linkml_phenopackets/cli/__init__.py +24 -0
- linkml_phenopackets/cli/cli.py +266 -0
- linkml_phenopackets/datamodel/__init__.py +9 -0
- linkml_phenopackets/datamodel/phenopackets.py +4214 -0
- linkml_phenopackets/jsonschema/phenopackets.schema.json +4616 -0
- linkml_phenopackets/pydantic/__init__.py +0 -0
- linkml_phenopackets/pydantic/model.py +2469 -0
- linkml_phenopackets/schema/any.yaml +37 -0
- linkml_phenopackets/schema/base.yaml +243 -0
- linkml_phenopackets/schema/biosample.yaml +181 -0
- linkml_phenopackets/schema/constants.yaml +392 -0
- linkml_phenopackets/schema/cv_terms.yaml +144 -0
- linkml_phenopackets/schema/disease.yaml +85 -0
- linkml_phenopackets/schema/genome.yaml +25 -0
- linkml_phenopackets/schema/individual.yaml +194 -0
- linkml_phenopackets/schema/interpretation.yaml +210 -0
- linkml_phenopackets/schema/measurement.yaml +168 -0
- linkml_phenopackets/schema/medical_action.yaml +290 -0
- linkml_phenopackets/schema/meta_data.yaml +123 -0
- linkml_phenopackets/schema/pedigree.yaml +82 -0
- linkml_phenopackets/schema/phenopackets.yaml +189 -0
- linkml_phenopackets/schema/phenotypic_feature.yaml +75 -0
- linkml_phenopackets/schema/timestamp.yaml +37 -0
- linkml_phenopackets/schema/vrs.yaml +862 -0
- linkml_phenopackets/schema/vrsatile.yaml +245 -0
- linkml_phenopackets/utilities/__init__.py +0 -0
- linkml_phenopackets/utilities/ingest_constants.py +74 -0
- linkml_phenopackets/utilities/io_utilities.py +84 -0
- linkml_phenopackets/utilities/ontology_utilities.py +194 -0
- linkml_phenopackets-0.1.0rc1.dist-info/METADATA +240 -0
- linkml_phenopackets-0.1.0rc1.dist-info/RECORD +36 -0
- linkml_phenopackets-0.1.0rc1.dist-info/WHEEL +4 -0
- linkml_phenopackets-0.1.0rc1.dist-info/entry_points.txt +3 -0
- linkml_phenopackets-0.1.0rc1.dist-info/licenses/LICENSE +29 -0
- linkml_phenopackets-0.1.0rc1.dist-info/licenses/NOTICE +134 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""A LinkML rendering of the GA4GH Phenopacket Schema.
|
|
2
|
+
|
|
3
|
+
This is not the official GA4GH library. That one is the ``phenopackets`` package,
|
|
4
|
+
which has the classes that are generated from the protobuf files.
|
|
5
|
+
|
|
6
|
+
- :mod:`linkml_phenopackets.datamodel.phenopackets` has the dataclasses
|
|
7
|
+
- :mod:`linkml_phenopackets.pydantic.model` has the Pydantic models
|
|
8
|
+
- :mod:`linkml_phenopackets.datamodel` has the paths of the schema and of the JSON Schema
|
|
9
|
+
"""
|
|
10
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
11
|
+
|
|
12
|
+
try:
|
|
13
|
+
__version__ = version("linkml-phenopackets")
|
|
14
|
+
except PackageNotFoundError:
|
|
15
|
+
# the source is on the path, but the package is not installed
|
|
16
|
+
__version__ = "0.0.0"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""The ``p3`` command.
|
|
2
|
+
|
|
3
|
+
Its subcommands are in :mod:`linkml_phenopackets.cli.cli`. They use the packages of
|
|
4
|
+
the ``tools`` extra, so that module is imported only when ``p3`` runs.
|
|
5
|
+
"""
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
# The packages of the `tools` extra that are missing when it is not installed.
|
|
9
|
+
# The other ones are installed with linkml-runtime.
|
|
10
|
+
TOOLS_MODULES = {"bioregistry", "linkml", "oaklib"}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main():
|
|
14
|
+
"""Run ``p3``, or say how to install what it needs."""
|
|
15
|
+
try:
|
|
16
|
+
from linkml_phenopackets.cli.cli import main as p3
|
|
17
|
+
except ModuleNotFoundError as e:
|
|
18
|
+
if e.name is None or e.name.split(".")[0] not in TOOLS_MODULES:
|
|
19
|
+
raise
|
|
20
|
+
sys.exit(
|
|
21
|
+
f"p3 needs the module '{e.name}', which is not installed.\n"
|
|
22
|
+
"Install what p3 needs with: pip install 'linkml-phenopackets[tools]'"
|
|
23
|
+
)
|
|
24
|
+
p3()
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import subprocess
|
|
3
|
+
import sys
|
|
4
|
+
from typing import Optional, TextIO, List
|
|
5
|
+
|
|
6
|
+
import click
|
|
7
|
+
import linkml.validator as linkml_validator
|
|
8
|
+
from linkml_runtime import SchemaView
|
|
9
|
+
from linkml_runtime.dumpers import yaml_dumper
|
|
10
|
+
from linkml_runtime.linkml_model import SchemaDefinition
|
|
11
|
+
from oaklib import get_implementation_from_shorthand
|
|
12
|
+
from oaklib.datamodels.vocabulary import IS_A
|
|
13
|
+
from oaklib.interfaces.obograph_interface import OboGraphInterface
|
|
14
|
+
from oaklib.interfaces.semsim_interface import SemanticSimilarityInterface
|
|
15
|
+
from oaklib.io.streaming_yaml_writer import StreamingYamlWriter
|
|
16
|
+
from oaklib.utilities.obograph_utils import graph_to_image, default_stylemap_path
|
|
17
|
+
|
|
18
|
+
import linkml_phenopackets.utilities.io_utilities as ioutil
|
|
19
|
+
import linkml_phenopackets.utilities.ontology_utilities as ontutil
|
|
20
|
+
from linkml_phenopackets.datamodel import MAIN_SCHEMA_PATH
|
|
21
|
+
from linkml_phenopackets.datamodel.phenopackets import Phenopacket
|
|
22
|
+
|
|
23
|
+
logger = logging.getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
input_path_argument = click.argument("input_path", required=True, type=click.Path())
|
|
26
|
+
multi_input_path_argument = click.argument("input_paths", required=True, nargs=-1, type=click.Path())
|
|
27
|
+
input_format_option = click.option(
|
|
28
|
+
"-I",
|
|
29
|
+
"--input-format",
|
|
30
|
+
help=f"The string denoting the input format",
|
|
31
|
+
)
|
|
32
|
+
output_option = click.option(
|
|
33
|
+
"-o",
|
|
34
|
+
"--output",
|
|
35
|
+
help="Path of SSSOM output file.",
|
|
36
|
+
)
|
|
37
|
+
output_format_option = click.option(
|
|
38
|
+
"-O",
|
|
39
|
+
"--output-format",
|
|
40
|
+
help=f"Desired output format",
|
|
41
|
+
)
|
|
42
|
+
ontology_option = click.option(
|
|
43
|
+
"--ontology",
|
|
44
|
+
"-i",
|
|
45
|
+
help="Path to an ontology file or OAK locator.",
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def get_configuration(
|
|
50
|
+
ontology: Optional[str],
|
|
51
|
+
) -> Optional[ontutil.OntologyConfiguration]:
|
|
52
|
+
if ontology is None:
|
|
53
|
+
return None
|
|
54
|
+
oi = get_implementation_from_shorthand(ontology)
|
|
55
|
+
return ontutil.OntologyConfiguration(default_ontology=oi)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@click.group()
|
|
59
|
+
@click.option("-v", "--verbose", count=True)
|
|
60
|
+
@click.option("-q", "--quiet")
|
|
61
|
+
def main(verbose: int, quiet: bool):
|
|
62
|
+
"""Run the CLI."""
|
|
63
|
+
logger = logging.getLogger()
|
|
64
|
+
if verbose >= 2:
|
|
65
|
+
logger.setLevel(level=logging.DEBUG)
|
|
66
|
+
elif verbose == 1:
|
|
67
|
+
logger.setLevel(level=logging.INFO)
|
|
68
|
+
else:
|
|
69
|
+
logger.setLevel(level=logging.WARNING)
|
|
70
|
+
if quiet:
|
|
71
|
+
logger.setLevel(level=logging.ERROR)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@main.command()
|
|
75
|
+
@input_format_option
|
|
76
|
+
@input_path_argument
|
|
77
|
+
@output_format_option
|
|
78
|
+
@output_option
|
|
79
|
+
@ontology_option
|
|
80
|
+
def migrate_obsoletes(
|
|
81
|
+
input_path: TextIO,
|
|
82
|
+
input_format: Optional[str],
|
|
83
|
+
output_format: Optional[str],
|
|
84
|
+
output: Optional[str],
|
|
85
|
+
ontology: Optional[str],
|
|
86
|
+
):
|
|
87
|
+
"""Rewire all OntologyClass objects that have an obsoletion with replacement."""
|
|
88
|
+
pkt = ioutil.load_phenopacket(input_path, input_format)
|
|
89
|
+
conf = get_configuration(ontology)
|
|
90
|
+
results = list(ontutil.migrate_obsoletes(pkt, configuration=conf))
|
|
91
|
+
print(f"## Num results: {len(results)}")
|
|
92
|
+
for result in results:
|
|
93
|
+
print(f"## RESULT: {result}")
|
|
94
|
+
ioutil.dump_phenopacket(pkt, output, output_format)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@main.command()
|
|
98
|
+
@input_format_option
|
|
99
|
+
@input_path_argument
|
|
100
|
+
@output_format_option
|
|
101
|
+
@output_option
|
|
102
|
+
@ontology_option
|
|
103
|
+
def update_labels(
|
|
104
|
+
input_path: TextIO,
|
|
105
|
+
input_format: Optional[str],
|
|
106
|
+
output_format: Optional[str],
|
|
107
|
+
output: Optional[str],
|
|
108
|
+
ontology: Optional[str],
|
|
109
|
+
):
|
|
110
|
+
"""Rewire all OntologyClass objects to update labels."""
|
|
111
|
+
pkt = ioutil.load_phenopacket(input_path, input_format)
|
|
112
|
+
conf = get_configuration(ontology)
|
|
113
|
+
results = list(ontutil.update_labels(pkt, configuration=conf))
|
|
114
|
+
print(f"## Num results: {len(results)}")
|
|
115
|
+
for result in results:
|
|
116
|
+
print(f"## RESULT: {result}")
|
|
117
|
+
ioutil.dump_phenopacket(pkt, output, output_format)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
@main.command()
|
|
121
|
+
@input_format_option
|
|
122
|
+
@input_path_argument
|
|
123
|
+
@output_format_option
|
|
124
|
+
@output_option
|
|
125
|
+
@ontology_option
|
|
126
|
+
def normalize_curies(
|
|
127
|
+
input_path: TextIO,
|
|
128
|
+
input_format: Optional[str],
|
|
129
|
+
output_format: Optional[str],
|
|
130
|
+
output: Optional[str],
|
|
131
|
+
ontology: Optional[str],
|
|
132
|
+
):
|
|
133
|
+
"""Rewire all OntologyClass objects to update labels."""
|
|
134
|
+
pkt = ioutil.load_phenopacket(input_path, input_format)
|
|
135
|
+
conf = get_configuration(ontology)
|
|
136
|
+
results = list(ontutil.normalize_curies(pkt, configuration=conf))
|
|
137
|
+
print(f"## Num results: {len(results)}")
|
|
138
|
+
for result in results:
|
|
139
|
+
print(f"## RESULT: {result}")
|
|
140
|
+
ioutil.dump_phenopacket(pkt, output, output_format)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
@main.command()
|
|
144
|
+
@input_format_option
|
|
145
|
+
@input_path_argument
|
|
146
|
+
@output_format_option
|
|
147
|
+
@output_option
|
|
148
|
+
def list_terms(
|
|
149
|
+
input_path: TextIO,
|
|
150
|
+
input_format: Optional[str],
|
|
151
|
+
output_format: Optional[str],
|
|
152
|
+
output: Optional[str],
|
|
153
|
+
):
|
|
154
|
+
"""Rewire all OntologyClass objects to update labels."""
|
|
155
|
+
pkt = ioutil.load_phenopacket(input_path, input_format)
|
|
156
|
+
results = list(ontutil.collect_ontology_classes(pkt))
|
|
157
|
+
ioutil.dump_phenopacket(results, output, output_format)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
@main.command()
|
|
161
|
+
@input_format_option
|
|
162
|
+
@multi_input_path_argument
|
|
163
|
+
@output_format_option
|
|
164
|
+
@output_option
|
|
165
|
+
@ontology_option
|
|
166
|
+
def validate(
|
|
167
|
+
input_paths: List[TextIO],
|
|
168
|
+
input_format: Optional[str],
|
|
169
|
+
output_format: Optional[str],
|
|
170
|
+
output: Optional[str],
|
|
171
|
+
ontology: Optional[str],
|
|
172
|
+
):
|
|
173
|
+
"""Validate a collection of phenopackets."""
|
|
174
|
+
conf = get_configuration(ontology)
|
|
175
|
+
schema_location = str(MAIN_SCHEMA_PATH)
|
|
176
|
+
sv = SchemaView(schema_location)
|
|
177
|
+
schema = sv.schema
|
|
178
|
+
errs = []
|
|
179
|
+
for input_path in input_paths:
|
|
180
|
+
click.echo(f"## Validating {input_path}")
|
|
181
|
+
pkt = ioutil.load_phenopacket(input_path, input_format)
|
|
182
|
+
report = linkml_validator.validate(pkt, schema)
|
|
183
|
+
for result in report.results:
|
|
184
|
+
click.echo(f"## LinkML Validation Messages:")
|
|
185
|
+
click.echo(f"[{result.severity.value}] [{result.instance_index}]")
|
|
186
|
+
errs.append((input_path, result.message))
|
|
187
|
+
for r in ontutil.validate_ontology_classes(pkt, configuration=conf):
|
|
188
|
+
click.echo(f"## Ontology Validation Messages: {r}")
|
|
189
|
+
errs.append((input_path, r))
|
|
190
|
+
click.echo(f"Errors: {len(errs)}")
|
|
191
|
+
if errs:
|
|
192
|
+
sys.exit(1)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
@main.command()
|
|
197
|
+
@input_format_option
|
|
198
|
+
@input_path_argument
|
|
199
|
+
@output_format_option
|
|
200
|
+
@output_option
|
|
201
|
+
@ontology_option
|
|
202
|
+
def viz(
|
|
203
|
+
input_path: TextIO,
|
|
204
|
+
input_format: Optional[str],
|
|
205
|
+
output_format: Optional[str],
|
|
206
|
+
output: Optional[str],
|
|
207
|
+
ontology: Optional[str],
|
|
208
|
+
):
|
|
209
|
+
"""Rewire all OntologyClass objects to update labels."""
|
|
210
|
+
conf = get_configuration(ontology)
|
|
211
|
+
stylemap = default_stylemap_path()
|
|
212
|
+
ont = conf.default_ontology
|
|
213
|
+
if not isinstance(ont, SemanticSimilarityInterface):
|
|
214
|
+
raise ValueError("Ontology does not support semantic similarity")
|
|
215
|
+
pkt = ioutil.load_phenopacket(input_path, input_format)
|
|
216
|
+
seeds = [c.id for c in ontutil.collect_ontology_classes(pkt)]
|
|
217
|
+
if not isinstance(ont, OboGraphInterface):
|
|
218
|
+
raise ValueError("Ontology does not support OBO Graphs")
|
|
219
|
+
graph = ont.ancestor_graph(seeds, predicates=[IS_A])
|
|
220
|
+
imgfile = graph_to_image(
|
|
221
|
+
graph, seeds=seeds, imgfile=output, stylemap=stylemap
|
|
222
|
+
)
|
|
223
|
+
if True:
|
|
224
|
+
subprocess.run(["open", imgfile])
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
@main.command()
|
|
228
|
+
@input_format_option
|
|
229
|
+
@multi_input_path_argument
|
|
230
|
+
@output_format_option
|
|
231
|
+
@output_option
|
|
232
|
+
@ontology_option
|
|
233
|
+
def compare(
|
|
234
|
+
input_paths: List[TextIO],
|
|
235
|
+
input_format: Optional[str],
|
|
236
|
+
output_format: Optional[str],
|
|
237
|
+
output: Optional[str],
|
|
238
|
+
ontology: Optional[str],
|
|
239
|
+
):
|
|
240
|
+
"""Rewire all OntologyClass objects to update labels."""
|
|
241
|
+
conf = get_configuration(ontology)
|
|
242
|
+
ont = conf.default_ontology
|
|
243
|
+
if not isinstance(ont, SemanticSimilarityInterface):
|
|
244
|
+
raise ValueError("Ontology does not support semantic similarity")
|
|
245
|
+
pkts = [ioutil.load_phenopacket(input_path, input_format) for input_path in input_paths]
|
|
246
|
+
def terms(pkt: Phenopacket) -> List[str]:
|
|
247
|
+
return [c.id for c in ontutil.collect_ontology_classes(pkt1) if c.id.startswith("HP:")]
|
|
248
|
+
w = StreamingYamlWriter()
|
|
249
|
+
for i in range(len(pkts)):
|
|
250
|
+
pkt1 = pkts[i]
|
|
251
|
+
terms1 = terms(pkt1)
|
|
252
|
+
if not terms1:
|
|
253
|
+
continue
|
|
254
|
+
for j in range(i + 1, len(pkts)):
|
|
255
|
+
pkt2 = pkts[j]
|
|
256
|
+
terms2 = terms(pkt2)
|
|
257
|
+
if not terms2:
|
|
258
|
+
continue
|
|
259
|
+
print(f"COMPARISON: {terms1} vs {terms2}")
|
|
260
|
+
sim = ont.termset_pairwise_similarity(terms1, terms2, predicates=[IS_A])
|
|
261
|
+
w.emit(sim)
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
if __name__ == "__main__":
|
|
266
|
+
main()
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
THIS_PATH = Path(__file__).parent
|
|
4
|
+
|
|
5
|
+
SCHEMA_DIRECTORY = THIS_PATH.parent / "schema"
|
|
6
|
+
MAIN_SCHEMA_PATH = SCHEMA_DIRECTORY / "phenopackets.yaml"
|
|
7
|
+
|
|
8
|
+
# the JSON Schema that is generated from the schema, see `make jsonschema`
|
|
9
|
+
JSON_SCHEMA_PATH = THIS_PATH.parent / "jsonschema" / "phenopackets.schema.json"
|