-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneticScreening.py
122 lines (104 loc) · 4.72 KB
/
geneticScreening.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import streamlit as st
import pandas as pd
import requests
from st_aggrid import AgGrid
st.set_page_config(
page_title="Genetic Screening",
page_icon="random",
layout="wide",
initial_sidebar_state="collapsed",
# menu_items={
# 'Get Help': 'url',
# 'Report a bug': "url",
# 'About': "# This is a header. This is an *extremely* cool app!"
# }
)
@st.cache
def findPopulationDxImplications(conditionCode):
url = 'https://fhir-gen-ops.herokuapp.com/population-operations/phenotype-operations/$find-population-dx-implications?conditions='+conditionCode+'&includePatientList=true'
headers = {'Accept': 'application/json'}
r = requests.get(url, headers=headers)
return r.json()
@st.cache
def findSubjectDxImplications(subject, conditionCode):
url = 'https://fhir-gen-ops.herokuapp.com/subject-operations/phenotype-operations/$find-subject-dx-implications?subject='+subject+'&conditions='+conditionCode
headers = {'Accept': 'application/json'}
r = requests.get(url, headers=headers)
return r.json()
resultList = []
patientList = []
conditionList = []
clinSigList = []
evidenceList = []
variantList = []
st.title("Genetic Screening")
st.markdown("This app illustrates [FHIR Genomics Operations](http://build.fhir.org/ig/HL7/genomics-reporting/operations.html) **find-population-dx-implications** and **find-subject-dx-implications**. Select a condition from dropdown. The population is screened for this condition, and each associated variant in each patient is returned.")
condition = st.selectbox("", (
'Hemochromatosis',
'Familial hypercholesterolemia',
'Hereditary Breast and Ovarian Cancer Syndrome',
'Hereditary Paraganglioma-Pheochromocytoma Syndrome',
'Hypertrophic cardiomyopathy',
'Lynch syndrome',
'Multiple endocrine neoplasia',
'Peutz-Jeghers syndrome'))
if condition == "Familial hypercholesterolemia":
conditionCode = "https://www.ncbi.nlm.nih.gov/medgen|C0020445"
elif condition == "Hereditary Breast and Ovarian Cancer Syndrome":
conditionCode = "https://www.ncbi.nlm.nih.gov/medgen|C0677776"
elif condition == "Hereditary Paraganglioma-Pheochromocytoma Syndrome":
conditionCode = "https://www.ncbi.nlm.nih.gov/medgen|C1708353"
elif condition == "Hypertrophic cardiomyopathy":
conditionCode = "https://www.ncbi.nlm.nih.gov/medgen|C0878544"
elif condition == "Lynch syndrome":
conditionCode = "https://www.ncbi.nlm.nih.gov/medgen|C4552100"
elif condition == "Multiple endocrine neoplasia":
conditionCode = "https://www.ncbi.nlm.nih.gov/medgen|C0027662"
elif condition == "Peutz-Jeghers syndrome":
conditionCode = "https://www.ncbi.nlm.nih.gov/medgen|C0031269"
elif condition == "Hemochromatosis":
conditionCode = "https://www.ncbi.nlm.nih.gov/medgen|C3469186"
for i in findPopulationDxImplications(conditionCode)["parameter"][0]["part"]:
if i["name"] == "subject":
resultList.append(i["valueString"])
for i in resultList:
patient = i
variants = []
dxImplications = findSubjectDxImplications(i, conditionCode)
for j in dxImplications["parameter"]:
if j["name"] == "variant":
# extract variant
for l in j["resource"]["component"]:
if l["code"]["coding"][0]["code"] == "81252-9":
variant = l["valueCodeableConcept"]["coding"][0]["display"]
if variant in variants:
variant = ""
else:
variants.append(variant)
elif j["name"] == "implication":
# extract condition, clinical significance, evidence
for l in j["resource"]["component"]:
if l["code"]["coding"][0]["code"] == "53037-8":
try:
clinSig = l["valueCodeableConcept"]["coding"][0]["display"]
except KeyError:
clinSig = l["valueCodeableConcept"]["text"]
elif l["code"]["coding"][0]["code"] == "81259-4":
condition = l["valueCodeableConcept"]["coding"][0]["display"]
elif l["code"]["coding"][0]["code"] == "93044-6":
evidence = l["valueCodeableConcept"]["text"]
if variant != "":
patientList.append(patient)
variantList.append(variant)
clinSigList.append(clinSig)
conditionList.append(condition)
evidenceList.append(evidence)
data = (pd.DataFrame({
'Patient': patientList,
'Condition': conditionList,
'Variant': variantList,
'Clinical Significance': clinSigList,
'Evidence': evidenceList}))
data_t = data.T
AgGrid(data, enable_enterprise_modules=True, update_mode="value_changed", allow_unsafe_jscode=True)
st.download_button("Download table", data_t.to_json())