Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat #13: get statistics about variation content #16

Merged
merged 2 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ build/
develop-eggs/
dist/
downloads/
*.DS_Store
eggs/
.eggs/
.idea/
Expand Down
27 changes: 27 additions & 0 deletions src/anyvar/restapi/_data/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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


# ######################################################################
Expand Down
13 changes: 13 additions & 0 deletions src/anyvar/restapi/routes/summary_statistics.py
Original file line number Diff line number Diff line change
@@ -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
15 changes: 14 additions & 1 deletion src/anyvar/storage/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand Down