Spaces:
Running
Running
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +69 -68
src/streamlit_app.py
CHANGED
|
@@ -54,46 +54,60 @@ st.markdown(
|
|
| 54 |
|
| 55 |
st.divider()
|
| 56 |
|
| 57 |
-
def
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
key=f"{key_prefix}_mode",
|
| 63 |
-
index=0,
|
| 64 |
-
)
|
| 65 |
-
|
| 66 |
-
disabled_nums = (mode != "Enter alleles")
|
| 67 |
-
|
| 68 |
c1, c2 = st.columns(2)
|
| 69 |
with c1:
|
| 70 |
a1 = st.number_input(
|
| 71 |
-
f"{label}
|
| 72 |
-
min_value=
|
| 73 |
-
value=
|
| 74 |
-
key=f"{key_prefix}
|
| 75 |
-
disabled=
|
| 76 |
)
|
| 77 |
with c2:
|
| 78 |
a2 = st.number_input(
|
| 79 |
-
f"{label}
|
| 80 |
-
min_value=0, max_value=
|
| 81 |
value=0,
|
| 82 |
-
key=f"{key_prefix}
|
| 83 |
-
|
| 84 |
-
disabled=disabled_nums,
|
| 85 |
)
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
if
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
# Initialize sidebar (model/target/threshold defaults etc.)
|
| 99 |
sidebar()
|
|
@@ -108,24 +122,10 @@ st.session_state.targets_df = pd.DataFrame()
|
|
| 108 |
min_d = dt.date(1950, 1, 1)
|
| 109 |
max_d = dt.date(2050, 12, 31)
|
| 110 |
|
| 111 |
-
st.markdown("###### Recepient HLA Alleles")
|
| 112 |
-
r_hla_a = hla_allele_widget("R_HLA_A", "r_hla_a")
|
| 113 |
-
r_hla_b = hla_allele_widget("R_HLA_B", "r_hla_b")
|
| 114 |
-
r_hla_c = hla_allele_widget("R_HLA_C", "r_hla_c")
|
| 115 |
-
r_hla_dr = hla_allele_widget("R_HLA_DR", "r_hla_dr")
|
| 116 |
-
r_hla_dq = hla_allele_widget("R_HLA_DQ", "r_hla_dq")
|
| 117 |
-
|
| 118 |
|
| 119 |
-
st.markdown("###### Donor HLA Alleles")
|
| 120 |
-
d_hla_a = hla_allele_widget("D_HLA_A", "d_hla_a")
|
| 121 |
-
d_hla_b = hla_allele_widget("D_HLA_B", "d_hla_b")
|
| 122 |
-
d_hla_c = hla_allele_widget("D_HLA_C", "d_hla_c")
|
| 123 |
-
d_hla_dr = hla_allele_widget("D_HLA_DR", "d_hla_dr")
|
| 124 |
-
d_hla_dq = hla_allele_widget("D_HLA_DQ", "d_hla_dq")
|
| 125 |
|
| 126 |
-
with st.
|
| 127 |
st.subheader("Recepient Information", divider=True)
|
| 128 |
-
|
| 129 |
gender = st.radio("Recepient Gender", ["MALE", "FEMALE"], index=None)
|
| 130 |
|
| 131 |
dob = st.date_input(
|
|
@@ -180,10 +180,7 @@ with st.form("individual_form"):
|
|
| 180 |
key="recepient_blood_group",
|
| 181 |
)
|
| 182 |
|
| 183 |
-
|
| 184 |
-
|
| 185 |
st.subheader("Donor Information", divider=True)
|
| 186 |
-
|
| 187 |
donor_relation = st.radio(
|
| 188 |
"Donor Relation to Recepient",
|
| 189 |
["SELF", "SIBLING", "FIRST DEGREE RELATIVE", "SECOND DEGREE RELATIVE", "RELATED", "UNRELATED", "Unknown"],
|
|
@@ -208,10 +205,7 @@ with st.form("individual_form"):
|
|
| 208 |
key="donor_blood_group",
|
| 209 |
)
|
| 210 |
|
| 211 |
-
|
| 212 |
-
|
| 213 |
st.subheader("Treatment Details", divider=True)
|
| 214 |
-
|
| 215 |
lines_of_rx = st.selectbox("Number of Lines of Rx Before HSCT", [0, 1, 2, 3, 4, 5, 6, 7, "Unknown"], index=None)
|
| 216 |
|
| 217 |
conditioning = st.multiselect(
|
|
@@ -228,7 +222,6 @@ with st.form("individual_form"):
|
|
| 228 |
)
|
| 229 |
|
| 230 |
st.subheader("HSCT Details", divider=True)
|
| 231 |
-
|
| 232 |
hsct_date = st.date_input(
|
| 233 |
"HSCT Date",
|
| 234 |
value=dt.date(2000, 1, 31),
|
|
@@ -246,13 +239,23 @@ with st.form("individual_form"):
|
|
| 246 |
hla_match = st.radio("HLA Match Ratio", ["FULL", "PARTIAL", "HAPLOIDENTICAL", "Unknown"], index=None)
|
| 247 |
|
| 248 |
st.subheader("Transplant Risk Modifiers", divider=True)
|
| 249 |
-
|
| 250 |
donor_type = st.selectbox(
|
| 251 |
"Donor Type",
|
| 252 |
["MRD", "MMRD", "MUD", "MMUD", "HAPLOIDENTICAL", "CORD", "Unknown"],
|
| 253 |
index=None,
|
| 254 |
)
|
| 255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
conditioning_intensity = st.radio("Conditioning Intensity", ["MAC", "RIC", "NMA", "Unknown"], index=None)
|
| 257 |
|
| 258 |
last_followup_date = st.date_input(
|
|
@@ -278,7 +281,6 @@ with st.form("individual_form"):
|
|
| 278 |
)
|
| 279 |
|
| 280 |
st.subheader("Post-HSCT Treatment and GVHD Prophylaxis", divider=True)
|
| 281 |
-
|
| 282 |
post_hsct_regimen = st.radio("Post-HSCT Regimen", ["YES", "NO", "IVIG", "Unknown"], index=None)
|
| 283 |
|
| 284 |
gvhd_prophylaxis = st.multiselect(
|
|
@@ -290,9 +292,7 @@ with st.form("individual_form"):
|
|
| 290 |
]),
|
| 291 |
placeholder="Choose option(s)",
|
| 292 |
)
|
| 293 |
-
|
| 294 |
-
submitted = st.form_submit_button("PREDICT", type="primary")
|
| 295 |
-
|
| 296 |
|
| 297 |
if submitted:
|
| 298 |
# Collect input values in a dict
|
|
@@ -308,16 +308,17 @@ if submitted:
|
|
| 308 |
"Donor_gender": donor_gender,
|
| 309 |
"D_Blood group": donor_blood_group if donor_blood_group != "Unknown" else "X",
|
| 310 |
|
| 311 |
-
"R_HLA_A":
|
| 312 |
-
"R_HLA_B":
|
| 313 |
-
"R_HLA_C":
|
| 314 |
-
"R_HLA_DR":
|
| 315 |
-
"R_HLA_DQ":
|
| 316 |
-
|
| 317 |
-
"
|
| 318 |
-
"
|
| 319 |
-
"
|
| 320 |
-
"
|
|
|
|
| 321 |
|
| 322 |
"Number of lines of Rx before HSCT": lines_of_rx,
|
| 323 |
"PreHSCT conditioning regimen+/-ATG+/-TBI": conditioning,
|
|
|
|
| 54 |
|
| 55 |
st.divider()
|
| 56 |
|
| 57 |
+
def two_alleles_number_inputs(label: str, key_prefix: str, max_allele: int = 500, disabled: bool = False):
|
| 58 |
+
"""
|
| 59 |
+
Two numeric allele inputs. 0 = not provided.
|
| 60 |
+
Returns [] if both 0 else list of strings, e.g. ["12","24"].
|
| 61 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
c1, c2 = st.columns(2)
|
| 63 |
with c1:
|
| 64 |
a1 = st.number_input(
|
| 65 |
+
f"{label} allele 1",
|
| 66 |
+
min_value=0, max_value=max_allele, step=1,
|
| 67 |
+
value=0,
|
| 68 |
+
key=f"{key_prefix}_1",
|
| 69 |
+
disabled=disabled,
|
| 70 |
)
|
| 71 |
with c2:
|
| 72 |
a2 = st.number_input(
|
| 73 |
+
f"{label} allele 2",
|
| 74 |
+
min_value=0, max_value=max_allele, step=1,
|
| 75 |
value=0,
|
| 76 |
+
key=f"{key_prefix}_2",
|
| 77 |
+
disabled=disabled,
|
|
|
|
| 78 |
)
|
| 79 |
|
| 80 |
+
a1, a2 = int(a1), int(a2)
|
| 81 |
+
out = []
|
| 82 |
+
if a1 != 0:
|
| 83 |
+
out.append(str(a1))
|
| 84 |
+
if a2 != 0 and a2 != a1:
|
| 85 |
+
out.append(str(a2))
|
| 86 |
+
return out
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def hla_block(person: str, key_prefix: str, enabled: bool):
|
| 90 |
+
if not enabled:
|
| 91 |
+
return {
|
| 92 |
+
f"{key_prefix}_A": ["Unknown"],
|
| 93 |
+
f"{key_prefix}_B": ["Unknown"],
|
| 94 |
+
f"{key_prefix}_C": ["Unknown"],
|
| 95 |
+
f"{key_prefix}_DR": ["Unknown"],
|
| 96 |
+
f"{key_prefix}_DQ": ["Unknown"],
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
st.markdown(f"###### {person} HLA Alleles")
|
| 100 |
+
|
| 101 |
+
def _val(x):
|
| 102 |
+
return x if (x and len(x) > 0) else ["Unknown"]
|
| 103 |
+
|
| 104 |
+
return {
|
| 105 |
+
f"{key_prefix}_A": _val(two_alleles_number_inputs(f"{person} HLA-A", f"{key_prefix}_A")),
|
| 106 |
+
f"{key_prefix}_B": _val(two_alleles_number_inputs(f"{person} HLA-B", f"{key_prefix}_B")),
|
| 107 |
+
f"{key_prefix}_C": _val(two_alleles_number_inputs(f"{person} HLA-C", f"{key_prefix}_C")),
|
| 108 |
+
f"{key_prefix}_DR": _val(two_alleles_number_inputs(f"{person} HLA-DR", f"{key_prefix}_DR")),
|
| 109 |
+
f"{key_prefix}_DQ": _val(two_alleles_number_inputs(f"{person} HLA-DQ", f"{key_prefix}_DQ")),
|
| 110 |
+
}
|
| 111 |
|
| 112 |
# Initialize sidebar (model/target/threshold defaults etc.)
|
| 113 |
sidebar()
|
|
|
|
| 122 |
min_d = dt.date(1950, 1, 1)
|
| 123 |
max_d = dt.date(2050, 12, 31)
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
+
with st.container():
|
| 128 |
st.subheader("Recepient Information", divider=True)
|
|
|
|
| 129 |
gender = st.radio("Recepient Gender", ["MALE", "FEMALE"], index=None)
|
| 130 |
|
| 131 |
dob = st.date_input(
|
|
|
|
| 180 |
key="recepient_blood_group",
|
| 181 |
)
|
| 182 |
|
|
|
|
|
|
|
| 183 |
st.subheader("Donor Information", divider=True)
|
|
|
|
| 184 |
donor_relation = st.radio(
|
| 185 |
"Donor Relation to Recepient",
|
| 186 |
["SELF", "SIBLING", "FIRST DEGREE RELATIVE", "SECOND DEGREE RELATIVE", "RELATED", "UNRELATED", "Unknown"],
|
|
|
|
| 205 |
key="donor_blood_group",
|
| 206 |
)
|
| 207 |
|
|
|
|
|
|
|
| 208 |
st.subheader("Treatment Details", divider=True)
|
|
|
|
| 209 |
lines_of_rx = st.selectbox("Number of Lines of Rx Before HSCT", [0, 1, 2, 3, 4, 5, 6, 7, "Unknown"], index=None)
|
| 210 |
|
| 211 |
conditioning = st.multiselect(
|
|
|
|
| 222 |
)
|
| 223 |
|
| 224 |
st.subheader("HSCT Details", divider=True)
|
|
|
|
| 225 |
hsct_date = st.date_input(
|
| 226 |
"HSCT Date",
|
| 227 |
value=dt.date(2000, 1, 31),
|
|
|
|
| 239 |
hla_match = st.radio("HLA Match Ratio", ["FULL", "PARTIAL", "HAPLOIDENTICAL", "Unknown"], index=None)
|
| 240 |
|
| 241 |
st.subheader("Transplant Risk Modifiers", divider=True)
|
|
|
|
| 242 |
donor_type = st.selectbox(
|
| 243 |
"Donor Type",
|
| 244 |
["MRD", "MMRD", "MUD", "MMUD", "HAPLOIDENTICAL", "CORD", "Unknown"],
|
| 245 |
index=None,
|
| 246 |
)
|
| 247 |
|
| 248 |
+
r_hla = {"R_HLA_A":["Unknown"], "R_HLA_B":["Unknown"], "R_HLA_C":["Unknown"], "R_HLA_DR":["Unknown"], "R_HLA_DQ":["Unknown"]}
|
| 249 |
+
d_hla = {"D_HLA_A":["Unknown"], "D_HLA_B":["Unknown"], "D_HLA_C":["Unknown"], "D_HLA_DR":["Unknown"], "D_HLA_DQ":["Unknown"]}
|
| 250 |
+
with st.expander("Optional: HLA Allele Details", expanded=False):
|
| 251 |
+
st.caption("Enter HLA allele data if available to enhance prediction accuracy.")
|
| 252 |
+
|
| 253 |
+
enter_recipient_hla = st.toggle("Enter Recipient HLA alleles", value=False, key="enter_recipient_hla")
|
| 254 |
+
r_hla = hla_block("Recipient", "R_HLA", enabled=enter_recipient_hla)
|
| 255 |
+
|
| 256 |
+
enter_donor_hla = st.toggle("Enter Donor HLA alleles", value=False, key="enter_donor_hla")
|
| 257 |
+
d_hla = hla_block("Donor", "D_HLA", enabled=enter_donor_hla)
|
| 258 |
+
|
| 259 |
conditioning_intensity = st.radio("Conditioning Intensity", ["MAC", "RIC", "NMA", "Unknown"], index=None)
|
| 260 |
|
| 261 |
last_followup_date = st.date_input(
|
|
|
|
| 281 |
)
|
| 282 |
|
| 283 |
st.subheader("Post-HSCT Treatment and GVHD Prophylaxis", divider=True)
|
|
|
|
| 284 |
post_hsct_regimen = st.radio("Post-HSCT Regimen", ["YES", "NO", "IVIG", "Unknown"], index=None)
|
| 285 |
|
| 286 |
gvhd_prophylaxis = st.multiselect(
|
|
|
|
| 292 |
]),
|
| 293 |
placeholder="Choose option(s)",
|
| 294 |
)
|
| 295 |
+
submitted = st.button("PREDICT", type="primary", use_container_width=True)
|
|
|
|
|
|
|
| 296 |
|
| 297 |
if submitted:
|
| 298 |
# Collect input values in a dict
|
|
|
|
| 308 |
"Donor_gender": donor_gender,
|
| 309 |
"D_Blood group": donor_blood_group if donor_blood_group != "Unknown" else "X",
|
| 310 |
|
| 311 |
+
"R_HLA_A": r_hla["R_HLA_A"],
|
| 312 |
+
"R_HLA_B": r_hla["R_HLA_B"],
|
| 313 |
+
"R_HLA_C": r_hla["R_HLA_C"],
|
| 314 |
+
"R_HLA_DR": r_hla["R_HLA_DR"],
|
| 315 |
+
"R_HLA_DQ": r_hla["R_HLA_DQ"],
|
| 316 |
+
|
| 317 |
+
"D_HLA_A": d_hla["D_HLA_A"],
|
| 318 |
+
"D_HLA_B": d_hla["D_HLA_B"],
|
| 319 |
+
"D_HLA_C": d_hla["D_HLA_C"],
|
| 320 |
+
"D_HLA_DR": d_hla["D_HLA_DR"],
|
| 321 |
+
"D_HLA_DQ": d_hla["D_HLA_DQ"],
|
| 322 |
|
| 323 |
"Number of lines of Rx before HSCT": lines_of_rx,
|
| 324 |
"PreHSCT conditioning regimen+/-ATG+/-TBI": conditioning,
|