From b1de943d00931ef6e1371e55c7a6c43bd505a6b1 Mon Sep 17 00:00:00 2001 From: Jeremy Arbesfeld Date: Tue, 12 Jul 2022 17:48:35 -0400 Subject: [PATCH 1/2] feat #13:get statistics about variation content --- .gitignore | 1 + src/anyvar/restapi/_data/openapi.yaml | 27 +++++++++++++++++++ .../restapi/routes/summary_statistics.py | 13 +++++++++ src/anyvar/storage/postgres.py | 15 ++++++++++- 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/anyvar/restapi/routes/summary_statistics.py diff --git a/.gitignore b/.gitignore index e46a0a0..7ff73c3 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ build/ develop-eggs/ dist/ downloads/ +*.DS_Store eggs/ .eggs/ .idea/ diff --git a/src/anyvar/restapi/_data/openapi.yaml b/src/anyvar/restapi/_data/openapi.yaml index 59437a9..02127a5 100644 --- a/src/anyvar/restapi/_data/openapi.yaml +++ b/src/anyvar/restapi/_data/openapi.yaml @@ -433,6 +433,33 @@ paths: type: object # This seems to be working: $ref: "file:vr.json#/definitions/Location" + ####################################################################### + # Summary Statistics + + /summary_statistics/{vartype}: + get: + tags: ["Statistics"] + summary: Summary Statistics for Variations in anyvar + description: Output summary statistics + parameters: + - name: vartype + in: path + description: variation type + required: true + schema: + type: string + enum: + - substitution + - deletion + - insertion + - all + responses: + 200: + description: OK + content: + application/json: + schema: + type: integer # ###################################################################### diff --git a/src/anyvar/restapi/routes/summary_statistics.py b/src/anyvar/restapi/routes/summary_statistics.py new file mode 100644 index 0000000..40fdd57 --- /dev/null +++ b/src/anyvar/restapi/routes/summary_statistics.py @@ -0,0 +1,13 @@ +from ..globals import get_anyvar + +def get(vartype): + av = get_anyvar() + if vartype == "substitution": + out = av.object_store.substitution_count() + elif vartype == "deletion": + out = av.object_store.deletion_count() + elif vartype == "insertion": + out = av.object_store.insertion_count() + elif vartype == "all": + out = len(av.object_store) + return out, 200 diff --git a/src/anyvar/storage/postgres.py b/src/anyvar/storage/postgres.py index bfe367d..9fa17a8 100644 --- a/src/anyvar/storage/postgres.py +++ b/src/anyvar/storage/postgres.py @@ -54,7 +54,20 @@ def __del__(self): self._db.close() def __len__(self): - return self._db.__len__() + data = self.conn._fetchone(f"select count(*) as c from vrs_objects where vrs_object ->> 'type' = 'Allele'") + return data[0] + + def deletion_count(self): + data = self.conn._fetchone(f"select count(*) as c from vrs_objects where length(vrs_object -> 'state' ->> 'sequence') = 0") + return data[0] + + def substitution_count(self): + data = self.conn._fetchone(f"select count(*) as c from vrs_objects where length(vrs_object -> 'state' ->> 'sequence') = 1") + return data[0] + + def insertion_count(self): + data = self.conn._fetchone(f"select count(*) as c from vrs_objects where length(vrs_object -> 'state' ->> 'sequence') > 1") + return data[0] def __iter__(self): return self._db.__iter__() From eb1b0cf520f5f67c5791643c55339e5f0c5c2684 Mon Sep 17 00:00:00 2001 From: Jeremy Arbesfeld Date: Tue, 12 Jul 2022 18:06:44 -0400 Subject: [PATCH 2/2] set enum default to all --- src/anyvar/restapi/_data/openapi.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/anyvar/restapi/_data/openapi.yaml b/src/anyvar/restapi/_data/openapi.yaml index 02127a5..5eefa52 100644 --- a/src/anyvar/restapi/_data/openapi.yaml +++ b/src/anyvar/restapi/_data/openapi.yaml @@ -448,6 +448,7 @@ paths: required: true schema: type: string + default: all enum: - substitution - deletion