about summary refs log tree commit diff
path: root/scripts/phenotypes/delete_phenotypes.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/phenotypes/delete_phenotypes.py')
-rw-r--r--scripts/phenotypes/delete_phenotypes.py30
1 files changed, 26 insertions, 4 deletions
diff --git a/scripts/phenotypes/delete_phenotypes.py b/scripts/phenotypes/delete_phenotypes.py
index 028f061..461f3ec 100644
--- a/scripts/phenotypes/delete_phenotypes.py
+++ b/scripts/phenotypes/delete_phenotypes.py
@@ -24,12 +24,15 @@ def read_xref_ids_file(filepath: Optional[Path]) -> tuple[int, ...]:
     if filepath is None:
         return tuple()
 
+    logger.debug("Using file '%s' to retrieve XREF IDs for deletion.",
+                 filepath.name)
     _ids: tuple[int, ...] = tuple()
     with filepath.open(mode="r") as infile:
-        try:
-            _ids += (int(infile.readline().strip()),)
-        except TypeError:
-            pass
+        for line in infile.readlines():
+            try:
+                _ids += (int(line.strip()),)
+            except TypeError:
+                pass
 
     return _ids
 
@@ -125,16 +128,27 @@ if __name__ == "__main__":
                 assert not (len(xref_ids) > 0 and args.delete_all)
                 xref_ids = (fetch_all_xref_ids(cursor, args.population_id)
                             if args.delete_all else xref_ids)
+                logger.debug("Will delete %s phenotypes and related data",
+                             len(xref_ids))
                 if len(xref_ids) == 0:
                     print("No cross-reference IDs were provided. Aborting.")
                     return 0
 
+                print("Updating authorisations: ", end="")
                 update_auth((args.auth_server_uri, args.auth_token),
                             args.species_id,
                             args.population_id,
                             args.dataset_id,
                             xref_ids)
+                print("OK.")
+                print("Deleting the data: ", end="")
                 delete_phenotypes(cursor, args.population_id, xref_ids=xref_ids)
+                print("OK.")
+                if args.xref_ids_file is not None:
+                    print("Deleting temporary file: ", end="")
+                    args.xref_ids_file.unlink()
+                    print("OK.")
+
                 return 0
             except AssertionError:
                 logger.error(
@@ -143,6 +157,14 @@ if __name__ == "__main__":
                     "and also specify to 'DELETE-ALL' phenotypes in the "
                     "population, we have no way of knowing what it is you want.")
                 return 1
+            except requests.exceptions.HTTPError as _exc:
+                resp = _exc.response
+                resp_data = resp.json()
+                logger.debug("%s: %s",
+                             resp_data["error"],
+                             resp_data["error_description"],
+                             exc_info=True)
+                return 1
             except Exception as _exc:# pylint: disable=[broad-exception-caught]
                 logger.debug("Failed while attempting to delete phenotypes.",
                              exc_info=True)