Skip to content

Commit

Permalink
Merge pull request #16 from GenomicMedLab/issue-13
Browse files Browse the repository at this point in the history
feat #13: get statistics about variation content
  • Loading branch information
andreasprlic authored Jul 12, 2022
2 parents f13324f + eb1b0cf commit fe25571
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
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
28 changes: 28 additions & 0 deletions src/anyvar/restapi/_data/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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


# ######################################################################
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

0 comments on commit fe25571

Please # to comment.