Skip to content

Commit

Permalink
scratch work
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Mar 11, 2024
1 parent 0d4ea08 commit 3603897
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/hdmf/backends/hdf5/h5tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,7 @@ def write_dataset(self, **kwargs): # noqa: C901
if isinstance(data, TermSetWrapper):
# This is for when the wrapped item is a dataset
# (refer to objectmapper.py for wrapped attributes)
breakpoint()
data = data.value
attributes = builder.attributes
options['dtype'] = builder.dtype
Expand Down
3 changes: 2 additions & 1 deletion src/hdmf/backends/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ def write(self, **kwargs):

# add_ref_container to search for and resolve the TermSetWrapper
herd.add_ref_container(root_container=container,
unwrap=True) # container would be the NWBFile
unwrap=False) # container would be the NWBFile
# write HERD
herd.to_zip(path=self.herd_path)

"""Write a container to the IO source."""
f_builder = self.__manager.build(container, source=self.__source, root=True)
breakpoint()
self.write_builder(f_builder, **kwargs)

@docval({'name': 'src_io', 'type': 'hdmf.backends.io.HDMFIO',
Expand Down
1 change: 1 addition & 0 deletions src/hdmf/build/objectmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ def get_attr_value(self, **kwargs):
% (container.__class__.__name__, container.name, attr_name, spec))
raise ContainerConfigurationError(msg)
if isinstance(attr_val, TermSetWrapper):
breakpoint()
attr_val = attr_val.value
if attr_val is not None:
attr_val = self.__convert_string(attr_val, spec)
Expand Down
37 changes: 20 additions & 17 deletions tests/unit/common/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,26 +352,29 @@ def test_add_ref_container_attr(self):

@unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed")
def test_add_ref_termset(self):
terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml')
er = HERD()
em = HERDManagerContainer()

col1 = VectorData(name='Species_Data',
description='species from NCBI and Ensemble',
data=['Homo sapiens'])

species = DynamicTable(name='species', description='My species', columns=[col1],)

er.add_ref_termset(file=em,
container=species,
attribute='Species_Data',
key='Homo sapiens',
termset=terms
)
self.assertEqual(er.keys.data, [('Homo sapiens',)])
self.assertEqual(er.entities.data, [('NCBI_TAXON:9606',
'https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=9606')])
self.assertEqual(er.objects.data, [(0, col1.object_id, 'VectorData', '', '')])
# terms = TermSet(term_schema_path='tests/unit/example_test_term_set.yaml')
# er = HERD()
# em = HERDManagerContainer()
#
# col1 = VectorData(name='Species_Data',
# description='species from NCBI and Ensemble',
# data=['Homo sapiens'])
#
# species = DynamicTable(name='species', description='My species', columns=[col1],)
#
# er.add_ref_termset(file=em,
# container=species,
# attribute='Species_Data',
# key='Homo sapiens',
# termset=terms
# )
# self.assertEqual(er.keys.data, [('Homo sapiens',)])
# self.assertEqual(er.entities.data, [('NCBI_TAXON:9606',
# 'https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=9606')])
# self.assertEqual(er.objects.data, [(0, col1.object_id, 'VectorData', '', '')])

@unittest.skipIf(not LINKML_INSTALLED, "optional LinkML module is not installed")
def test_add_ref_termset_data_object_error(self):
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,18 @@ def __str__(self):
def my_data(self):
return self.__data

@my_data.setter
def my_data(self, value):
self.__data = value

@property
def attr1(self):
return self.__attr1

@attr1.setter
def attr1(self, value):
self.__attr1 = value

@property
def attr2(self):
return self.__attr2
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_io_hdf5_h5tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ def test_roundtrip_TermSetWrapper_dataset(self):
foo = Foo(name="species", attr1='attr1', attr2=0,
my_data=TermSetWrapper(value=['Homo sapiens', 'Mus musculus'],
termset=terms))

foobucket = FooBucket('bucket1', [foo])
foofile = FooFile(buckets=[foobucket])

Expand All @@ -839,7 +839,7 @@ def test_roundtrip_TermSetWrapper_dataset(self):

with HDF5IO(self.path, manager=get_foo_buildmanager("text"), mode='r') as io:
read_foofile = io.read()
self.assertListEqual(foofile.buckets['bucket1'].foos['species'].my_data.value,
self.assertListEqual(foofile.buckets['bucket1'].foos['species'].my_data,
read_foofile.buckets['bucket1'].foos['species'].my_data[:].tolist())
remove_test_file('./HERD.zip')

Expand All @@ -856,7 +856,7 @@ def test_roundtrip_TermSetWrapper_attribute(self):

with HDF5IO(self.path, manager=self.manager, mode='r') as io:
read_foofile = io.read()
self.assertEqual(foofile.buckets['bucket1'].foos['species'].attr1.value,
self.assertEqual(foofile.buckets['bucket1'].foos['species'].attr1,
read_foofile.buckets['bucket1'].foos['species'].attr1)
remove_test_file('./HERD.zip')

Expand Down

0 comments on commit 3603897

Please sign in to comment.