From a96c47d9fc5b2098fd6ebabb861e680ee67d401f Mon Sep 17 00:00:00 2001 From: Jared Lumpe Date: Sun, 14 Jul 2024 15:23:34 -0700 Subject: [PATCH] Simplifications to "archive" results format --- src/gambit/results/archive.py | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/src/gambit/results/archive.py b/src/gambit/results/archive.py index 4d29836..172703c 100644 --- a/src/gambit/results/archive.py +++ b/src/gambit/results/archive.py @@ -4,21 +4,17 @@ from typing import Union, IO, Any from functools import singledispatchmethod -from attr import attrs, attrib, asdict, has as has_attrs +from attr import attrs, has as has_attrs from sqlalchemy.orm import Session from gambit.query import QueryResultItem, QueryResults -from gambit.classify import ClassifierResult, GenomeMatch +from gambit.classify import GenomeMatch from gambit.db import ReferenceGenomeSet, Taxon, AnnotatedGenome, Genome import gambit.util.json as gjson from gambit.util.io import FilePath, maybe_open from gambit.util.misc import type_singledispatchmethod from gambit.util.typing import is_optional, unwrap_optional -from .base import asdict_default, BaseJSONResultsExporter - - -def _todict(obj, attrs): - return {a: getattr(obj, a) for a in attrs} +from .base import BaseJSONResultsExporter, _todict @attrs() @@ -29,29 +25,12 @@ class ResultsArchiveWriter(BaseJSONResultsExporter): The exported data can be read and converted back into an identical :class:`QueryResults` object using :class:`.ResultsArchiveReader`. - Attributes - ---------- - install_info - Add results of :func:`gambit.util.dev.install_info` to the ``QueryResults.extra`` dict. + Only the ID attributes of database models are saved, when loading the saved results the models + are recreated by database queries. """ - install_info: bool = attrib(default=False) to_json = singledispatchmethod(BaseJSONResultsExporter.to_json) - to_json.register(ClassifierResult, asdict_default) - to_json.register(GenomeMatch, asdict_default) - to_json.register(QueryResultItem, asdict_default) - - @to_json.register(QueryResults) - def _queryresults_to_json(self, results): - data = asdict(results) - - if self.install_info: - from gambit.util.dev import install_info - data['extra']['install_info'] = install_info() - - return data - @to_json.register(ReferenceGenomeSet) def _genomeset_to_json(self, gset: ReferenceGenomeSet): return _todict(gset, ['key', 'version'])