mirror of
https://github.com/p2p-ld/nwb-linkml.git
synced 2025-01-10 06:04:28 +00:00
remove hdf5_linkml - it doesn't make sense to be separate since it requires all the rest of the main package
This commit is contained in:
parent
808c63e7c2
commit
799d32ed24
8 changed files with 0 additions and 2076 deletions
|
@ -1,3 +0,0 @@
|
||||||
# hdf5_linkml
|
|
||||||
|
|
||||||
HDF5 adapter to linkml models
|
|
1952
hdf5_linkml/poetry.lock
generated
1952
hdf5_linkml/poetry.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1,20 +0,0 @@
|
||||||
[tool.poetry]
|
|
||||||
name = "hdf5-linkml"
|
|
||||||
version = "0.1.0"
|
|
||||||
description = "Adapt and load hdf5 files to linkml-pydantic models"
|
|
||||||
authors = ["sneakers-the-rat <JLSaunders987@gmail.com>"]
|
|
||||||
license = "AGPL-3.0"
|
|
||||||
readme = "README.md"
|
|
||||||
packages = [{include = "hdf5_linkml", from="src"}]
|
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
|
||||||
python = "^3.11"
|
|
||||||
h5py = "^3.9.0"
|
|
||||||
nwb_linkml = { path = '..', develop = true, optional = true }
|
|
||||||
linkml = "^1.5.7"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[build-system]
|
|
||||||
requires = ["poetry-core"]
|
|
||||||
build-backend = "poetry.core.masonry.api"
|
|
|
@ -1,31 +0,0 @@
|
||||||
"""
|
|
||||||
Base I/O class for loading and saving hdf5 files
|
|
||||||
"""
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
from linkml_runtime.linkml_model import SchemaDefinition
|
|
||||||
|
|
||||||
class H5File:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# --------------------------------------------------
|
|
||||||
# Hooks
|
|
||||||
# --------------------------------------------------
|
|
||||||
def load_embedded_schema(self, h5f) -> List[dict]:
|
|
||||||
"""
|
|
||||||
Load schema that are embedded within the hdf5 file
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
def translate_schema(self, schema: List[dict]) -> List[SchemaDefinition]:
|
|
||||||
"""
|
|
||||||
Optionally translate schema from source language into LinkML
|
|
||||||
|
|
||||||
Args:
|
|
||||||
dict:
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
|
@ -1,68 +0,0 @@
|
||||||
import pdb
|
|
||||||
from pathlib import Path
|
|
||||||
import h5py
|
|
||||||
import json
|
|
||||||
from hdf5_linkml.io import H5File
|
|
||||||
from nwb_linkml.adapters import NamespacesAdapter
|
|
||||||
from nwb_linkml.io import load_schema_file
|
|
||||||
from linkml_runtime.linkml_model import SchemaDefinition
|
|
||||||
|
|
||||||
DATASET = '/Users/jonny/Dropbox/lab/p2p_ld/data/nwb/sub-738651046_ses-760693773.nwb'
|
|
||||||
|
|
||||||
|
|
||||||
class NWBH5File(H5File):
|
|
||||||
|
|
||||||
def __init__(self, file: Path):
|
|
||||||
self.file = Path(file)
|
|
||||||
|
|
||||||
def read(self):
|
|
||||||
with h5py.File(self.file, 'r') as h5f:
|
|
||||||
embedded_schema = self.load_embedded_schema(h5f)
|
|
||||||
translated_schema = self.translate_schema(embedded_schema)
|
|
||||||
pdb.set_trace()
|
|
||||||
|
|
||||||
def load_embedded_schema(self, h5f:h5py.File) -> List[dict]:
|
|
||||||
"""
|
|
||||||
Stored in ``/specfications/{namespace}/{version}/{schema_files}``
|
|
||||||
|
|
||||||
Args:
|
|
||||||
h5f:
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
[
|
|
||||||
{
|
|
||||||
'namespace': "DECODED_JSON_OBJECT",
|
|
||||||
'nwb.base': "DECODED_JSON_OBJECT",
|
|
||||||
...
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'namespace': "DECODED_JSON_OBJECT",
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
namespaces = []
|
|
||||||
for ns_name, ns in h5f['specifications'].items():
|
|
||||||
ns_schema = {}
|
|
||||||
for version in ns.values():
|
|
||||||
for schema_name, schema in version.items():
|
|
||||||
# read the source json binary string
|
|
||||||
sch_str = schema[()]
|
|
||||||
sch_dict = json.loads(sch_str)
|
|
||||||
ns_schema[schema_name] = sch_dict
|
|
||||||
namespaces.append(ns_schema)
|
|
||||||
return namespaces
|
|
||||||
|
|
||||||
def translate_schema(self, schema:List[dict]) -> List[SchemaDefinition]:
|
|
||||||
translated = []
|
|
||||||
for ns_schema in schema:
|
|
||||||
# find namespace
|
|
||||||
namespace = ns_schema['namespace']
|
|
||||||
ns_schema_adapters = [load_schema_file(sch_name, schema_dict) for sch_name, schema_dict in ns_schema.items() if sch_name != 'namespace']
|
|
||||||
adapter = NamespacesAdapter(
|
|
||||||
namespaces=namespace,
|
|
||||||
schemas=ns_schema_adapters
|
|
||||||
)
|
|
||||||
res = adapter.build()
|
|
||||||
translated.extend(res.schema)
|
|
|
@ -1,2 +0,0 @@
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue