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..5eefa52 100644 --- a/src/anyvar/restapi/_data/openapi.yaml +++ b/src/anyvar/restapi/_data/openapi.yaml @@ -433,6 +433,34 @@ 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 + default: all + 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__()