Skip to content

Commit

Permalink
fixing bugs for individuals and cohorts
Browse files Browse the repository at this point in the history
  • Loading branch information
costero-e committed Jan 16, 2025
1 parent 676e471 commit b9feaca
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1,016 deletions.
39 changes: 33 additions & 6 deletions cohorts_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def generate(dict_properties, list_of_headers):
new_item = key + "|" + ki + "|" + k + "|" + k1 + "|" + k2 + "|" + k3
for propk, propv in dict_of_properties.items():
if propk == new_item:
#print(propk)
subitem_dict[k][k1]={}
subitem_dict[k][k1][k2]={}
subitem_dict[k][k1][k2][k3]=propv
Expand All @@ -81,13 +82,15 @@ def generate(dict_properties, list_of_headers):
new_item = key + "|" + ki + "|" + k + "|" + k1 + "|" + k2
for propk, propv in dict_of_properties.items():
if propk == new_item:
#print(propk)
subitem_dict[k][k1]={}
subitem_dict[k][k1][k2]=propv
else:
new_item = ""
new_item = key + "|" + ki + "|" + k + "|" + k1
for propk, propv in dict_of_properties.items():
if propk == new_item:
#print(propk)
if subitem_dict == {}:
subitem_dict[k]={}
subitem_dict[k][k1]=propv
Expand Down Expand Up @@ -115,6 +118,7 @@ def generate(dict_properties, list_of_headers):
new_item = key + "|" + ki + "|" + ki1
for propk, propv in dict_of_properties.items():
if propk == new_item:
#print(propk)
propv = re.sub(r'\s', '', propv)
respropv = json.loads(propv)
item_dict[ki][ki1]=respropv
Expand All @@ -124,6 +128,7 @@ def generate(dict_properties, list_of_headers):
new_item = key + "|" + ki + "|" + ki1 + "|" + ki2
for propk, propv in dict_of_properties.items():
if propk == new_item:
#print(propk)
vi_dict[ki1][ki2]=propv
if vi_dict != {}:
item_dict[ki]=vi_dict
Expand All @@ -132,6 +137,7 @@ def generate(dict_properties, list_of_headers):
new_item = key + "|" + ki + "|" + ki1
for propk, propv in dict_of_properties.items():
if propk == new_item:
#print(propk)
if propk.endswith('availability'):
vi_dict[ki1]=bool(propv)
item_dict[ki]=vi_dict
Expand Down Expand Up @@ -249,6 +255,7 @@ def generate(dict_properties, list_of_headers):
new_item = key + "|" + kd + "|" + kd1 + "|" + kd2
for propk, propv in dict_of_properties.items():
if propk == new_item:
#print(propk)
try:
value_dict[kd][0][kd1][kd2]=propv
except Exception:
Expand All @@ -269,6 +276,7 @@ def generate(dict_properties, list_of_headers):
new_item = key + "|" + kd + "|" + kd1
for propk, propv in dict_of_properties.items():
if propk == new_item:
#print(propk)
if '|' in propv:
if propv_splitted_id != [] and propv_splitted_label != []:
propv_splitted_version = propv.split(',')
Expand Down Expand Up @@ -315,6 +323,7 @@ def generate(dict_properties, list_of_headers):
new_item = key + "|" + kd + "|" + kd1
for propk, propv in dict_of_properties.items():
if propk == new_item:
#print(propk)
if '|' in propv:
if propv_splitted_id != []:
propv_splitted_label = propv.split('|')
Expand Down Expand Up @@ -348,14 +357,17 @@ def generate(dict_properties, list_of_headers):
value_dict[kd]=[]
try:
if dicty not in value_dict[kd]:
value_dict[kd].append(dicty)
if dicty != {}:
value_dict[kd].append(dicty)
except Exception:
if key == 'inclusionCriteria' or key == 'exclusionCriteria':
try:
value_dict[kd].append(dicty)
if dicty != {}:
value_dict[kd].append(dicty)
except Exception:
value_dict[kd]=[]
value_dict[kd].append(dicty)
if dicty != {}:
value_dict[kd]=[]
value_dict[kd].append(dicty)
else:
value_dict[kd]=dicty

Expand All @@ -364,7 +376,14 @@ def generate(dict_properties, list_of_headers):
if value_dict not in vd_list:
vd_list.append(value_dict)
if vd_list != []:
definitivedict[key]=vd_list[0]
definitive_vd_dict={}
for kdv,vdv in vd_list[0].items():
if vdv == {}:
pass
else:
definitive_vd_dict[kdv]=vdv
if definitive_vd_dict!={}:
definitivedict[key]=definitive_vd_dict


elif isinstance(vd, dict):
Expand All @@ -376,6 +395,7 @@ def generate(dict_properties, list_of_headers):
new_item = key + "|" + kd + "|" + kd1 + "|" + kd2
for propk, propv in dict_of_properties.items():
if propk == new_item:
#print(propk)
if value_dict == {}:
value_dict[kd]={}
value_dict[kd][kd1]={}
Expand All @@ -386,20 +406,23 @@ def generate(dict_properties, list_of_headers):
new_item = key + "|" + kd + "|" + kd1
for propk, propv in dict_of_properties.items():
if propk == new_item:
#print(propk)
value_dict[kd][kd1]=propv
definitivedict[key]=value_dict
else:
new_item = ""
new_item = key + "|" + kd
for propk, propv in dict_of_properties.items():
if propk == new_item:
#print(propk)
value_dict[kd]=propv
definitivedict[key]=value_dict
else:
new_item = ""
new_item = key + "|" + kd
for propk, propv in dict_of_properties.items():
if propk == new_item:
#print(propk)
value_dict[kd]=propv
if key == 'cohortDataTypes':
definitivedict[key]=[value_dict]
Expand All @@ -414,6 +437,8 @@ def generate(dict_properties, list_of_headers):
propvalue={}
propvalue_splitted = propv.split(':')
propvalue[propvalue_splitted[0]]=propvalue_splitted[1]
print(key)
print(value)
definitivedict[key]=propvalue
else:
new_item = ""
Expand All @@ -424,8 +449,10 @@ def generate(dict_properties, list_of_headers):
propv = int(propv)
except Exception:
propv = propv
#print(key)
#print(propv)
definitivedict[key]=propv

#print(definitivedict)
Cohorts(**definitivedict)
definitivedict["datasetId"]=conf.datasetId
total_dict.append(definitivedict)
Expand Down
2 changes: 1 addition & 1 deletion conf/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#### Input and Output files config parameters ####
csv_folder = './csv/examples/Mireia/'
csv_folder = './csv/examples/'
output_docs_folder='./output_docs/'

#### VCF Conversion config parameters ####
Expand Down
Loading

0 comments on commit b9feaca

Please sign in to comment.