Skip to content

Commit

Permalink
parse the subpop ac/an/af in python
Browse files Browse the repository at this point in the history
  • Loading branch information
RoriCremer committed Aug 12, 2021
1 parent 51918a9 commit aa3be2b
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@
"'-'"
]

gvsSubpopulations = [
"afr",
"amr",
"eas",
"eur",
"mid",
"oth",
"sas"
]

def check_filtering(variant):
# skip any row (with a warning) if no gvsAnnotations exist
if variant.get("gvsAnnotations") == None: # <-- enum since we need this to be in tandem with the custom annotations header / template
Expand All @@ -113,6 +123,35 @@ def check_filtering(variant):
else:
return True

def getSubpopulationCalculations(variant):
row = {}
max_af = None
max_ac = None
max_an = None
for gvs_subpop in gvsSubpopulations: # TODO check with Lee on order
subpop_annotations = variant.get("".join([gvs_subpop, "SubpopulationAnnotations"]))
if variant.get(subpop_annotations) != None:
subpop_ac_val = subpop_annotations.get("AC") # note that these can be null if there is no value in the annotations. They will be null in the VAT
subpop_an_val = subpop_annotations.get("AN")
subpop_af_val = subpop_annotations.get("AF")
# here we set the subpopulation ac/an/af values
row["_".join(["gvs", gvs_subpop, "ac"])] = subpop_ac_val
row["_".join(["gvs", gvs_subpop, "an"])] = subpop_an_val
row["_".join(["gvs", gvs_subpop, "af"])] = subpop_af_val
if subpop_af_val != None and max_af == None: # this will set the first max_af value
max_af = subpop_af_val
if subpop_af_val != None and subpop_af_val > max_af:
max_subpop = gvs_subpop
max_ac = subpop_ac_val
max_an = subpop_an_val
max_af = subpop_af_val
# here we set the MAX subpopulation ac/an/af values
row["gvs_max_subpop"] = max_subpop
row["gvs_max_ac"] = max_ac
row["gvs_max_an"] = max_an
row["gvs_max_af"] = max_af
return row

def make_annotated_json_row(row_position, variant_line, transcript_line):
row = {}
row["position"] = row_position # this is a required field
Expand Down

0 comments on commit aa3be2b

Please sign in to comment.