From 78884d71ea90956dda614f5514a6e14fe91de75a Mon Sep 17 00:00:00 2001 From: caufieldjh Date: Tue, 17 Sep 2024 12:21:47 -0400 Subject: [PATCH] Remove interstitial products --- src/kg_bioportal/transformer.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/kg_bioportal/transformer.py b/src/kg_bioportal/transformer.py index e96b59d..21377d9 100644 --- a/src/kg_bioportal/transformer.py +++ b/src/kg_bioportal/transformer.py @@ -10,8 +10,7 @@ from kgx.transformer import Transformer as KGXTransformer from kg_bioportal.downloader import ONTOLOGY_LIST_NAME -from kg_bioportal.robot_utils import (initialize_robot, robot_convert, - robot_relax) +from kg_bioportal.robot_utils import initialize_robot, robot_convert, robot_relax # TODO: Don't repeat steps if the products already exist # TODO: Fix KGX hijacking logging @@ -248,10 +247,21 @@ def transform(self, ontology_path: str, compress: bool) -> Tuple[bool, int, int] with tarfile.open(f"{outfilename}.tar.gz", "w:gz") as tar: tar.add(nodefilename, arcname=f"{ontology_name}_nodes.tsv") tar.add(edgefilename, arcname=f"{ontology_name}_edges.tsv") - + os.remove(nodefilename) os.remove(edgefilename) + # Remove the owl files + # They may not exist if the transform failed + try: + os.remove(owl_output_path) + except OSError: + pass + try: + os.remove(relaxed_outpath) + except OSError: + pass + except Exception as e: logging.error( f"Error transforming {ontology_name} to KGX nodes and edges: {e}"