Skip to content

Commit

Permalink
fixed bug in flatten code refactor, expanded tests to catch
Browse files Browse the repository at this point in the history
  • Loading branch information
AmandaBirmingham committed May 25, 2024
1 parent 277fffc commit 460893f
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 2 deletions.
6 changes: 4 additions & 2 deletions qiimp/src/metadata_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ def flatten_nested_stds_dict(
curr_host_type_stds_nested_dict)

# recurse into the next level--depth first search.
# is ok if this comes back as an empty dict; we are adding to it below.
wip_host_types_dict = flatten_nested_stds_dict(
# if this comes back empty, we ignore it.
curr_host_type_sub_host_dict = flatten_nested_stds_dict(
curr_host_type_stds_nested_dict, curr_host_type_wip_flat_dict)
if curr_host_type_sub_host_dict:
wip_host_types_dict.update(curr_host_type_sub_host_dict)

# assign the flattened wip dict for the current host type to the result
# (which now contains flat records for the hosts lower down than
Expand Down
135 changes: 135 additions & 0 deletions qiimp/tests/test_metadata_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@ class TestMetadataExtender(TestCase):
}
}
}
},
"control": {
"metadata_fields": {
# overrides stds parent host
"description": {
"allowed": ["control"],
"default": "control",
"type": "string"
},
# overrides stds parent host
"host_type": {
"allowed": ["control"],
"default": "control",
"type": "string"
}
}
}
}
}
Expand Down Expand Up @@ -412,6 +428,22 @@ class TestMetadataExtender(TestCase):
}
}
}
},
"control": {
"metadata_fields": {
# overrides stds parent host
"description": {
"allowed": ["control"],
"default": "control",
"type": "string"
},
# overrides stds parent host
"host_type": {
"allowed": ["control"],
"default": "control",
"type": "string"
}
}
}
}
}
Expand Down Expand Up @@ -522,6 +554,109 @@ class TestMetadataExtender(TestCase):
}
}
},
"control": {
"default": "not provided",
"metadata_fields": {
# from stds same level host
"country": {
"allowed": ["USA"],
"default": "USA",
"empty": False,
"is_phi": False,
"required": True,
"type": "string"
},
# from stds same level host
"description": {
"allowed": ["control"],
"default": "control",
"empty": False,
"is_phi": False,
"required": True,
"type": "string"
},
# from stds same level host
"dna_extracted": {
"allowed": ["true", "false"],
"default": "true",
"empty": False,
"is_phi": False,
"required": True,
"type": "string"
},
# from stds same level host
"elevation": {
"anyof": [
{
"allowed": [
"not collected",
"not provided",
"restricted access"],
"type": "string"
},
{
"min": -413.0,
"type": "number"
}],
"empty": False,
"is_phi": False,
"required": True
},
# from stds same level host
"geo_loc_name": {
"allowed": ["USA:CA:San Diego"],
"default": "USA:CA:San Diego",
"empty": False,
"is_phi": False,
"required": True,
"type": "string"
},
# overridden in stds lower host
"host_type": {
"allowed": ["control"],
"default": "control",
"empty": False,
"is_phi": False,
"required": True,
"type": "string"
}
},
"sample_type_specific_metadata": {
"fe": {
"alias": "stool"
},
"stool": {
"metadata_fields": {
# from stds same level host + sample type
"description": {
"allowed": ["host associated stool"],
"default": "host associated stool",
"type": "string"
},
# from stds same level host + sample type
# (NB: comes from study)
"physical_specimen_location": {
"allowed": ["UCSDST"],
"default": "UCSDST",
"empty": False,
"is_phi": False,
"required": True,
"type": "string"
},
# from stds same level host + sample type
# (NB: comes from study)
"physical_specimen_remaining": {
"allowed": ["true", "false"],
"default": "true",
"empty": False,
"is_phi": False,
"required": True,
"type": "string"
}
}
}
}
},
"human": {
"default": "not collected",
"metadata_fields": {
Expand Down

0 comments on commit 460893f

Please sign in to comment.