Skip to content

Commit

Permalink
Merge pull request #375 from ChristopherBradley/368
Browse files Browse the repository at this point in the history
deserialise_annotations handles nested annotations
  • Loading branch information
GavinHuttley committed Nov 12, 2019
2 parents 6712007 + ca67520 commit 5611777
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cogent3/util/deserialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,13 @@ def deserialise_annotation(data, parent):
annots = []
for element in data:
element.pop("version", None)
annotations = element.pop("annotations", None)
klass = _get_class(element.pop("type"))
kwargs = element.pop("annotation_construction")
kwargs["map"] = deserialise_map_spans(kwargs["map"])
instance = klass(parent, **kwargs)
if annotations:
deserialise_annotation(annotations, instance)
annots.append(instance)
parent.annotations += tuple(annots)

Expand Down
10 changes: 10 additions & 0 deletions tests/test_core/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,16 @@ def test_nested_to_rich_dict(self):
self.nested_feature.to_rich_dict(),
)

def test_nested_deserialise_annotation(self):
"""nested annotations can be deserialised"""
got = self.s.to_json()
new = deserialise_object(got)
new_exon1 = new.annotations[0]
new_nested_feature = new_exon1.annotations[0]
self.assertEqual(
new_nested_feature.to_rich_dict(), self.nested_feature.to_rich_dict()
)


if __name__ == "__main__":
main()

0 comments on commit 5611777

Please sign in to comment.