Update appbackup.py
Browse files- appbackup.py +91 -27
appbackup.py
CHANGED
@@ -91,7 +91,90 @@ def display_results(predictions, site):
|
|
91 |
xaxis=dict(tickmode='array', tickvals=predictions['Year Index'], ticktext=predictions['Year'])
|
92 |
)))
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
# Streamlit UI
|
|
|
95 |
def main():
|
96 |
st.title("BMD and T-score Prediction Tool")
|
97 |
|
@@ -119,33 +202,8 @@ def main():
|
|
119 |
format="%.3f"
|
120 |
)
|
121 |
|
122 |
-
# Medication Selection
|
123 |
-
|
124 |
-
|
125 |
-
# Add "Show All" Option
|
126 |
-
show_all = st.checkbox("Show All Medications")
|
127 |
-
|
128 |
-
# Define medications by rows
|
129 |
-
medication_rows = [
|
130 |
-
["Alendronate", "Risedronate", "Ibandronate oral"],
|
131 |
-
["Zoledronate", "Ibandronate IV (3mg)"],
|
132 |
-
["Denosumab", "Denosumab + Teriparatide"],
|
133 |
-
["Teriparatide", "Teriparatide + Denosumab"],
|
134 |
-
["Romosozumab", "Romosozumab + Denosumab", "Romosozumab + Alendronate"],
|
135 |
-
["Romosozumab + Ibandronate", "Romosozumab + Zoledronate"]
|
136 |
-
]
|
137 |
-
|
138 |
-
# Create checkboxes for each row
|
139 |
-
selected_medications = []
|
140 |
-
if not show_all:
|
141 |
-
for row in medication_rows:
|
142 |
-
cols = st.columns(len(row))
|
143 |
-
for col, med in zip(cols, row):
|
144 |
-
if col.checkbox(med):
|
145 |
-
selected_medications.append(med)
|
146 |
-
else:
|
147 |
-
# If "Show All" is checked, include all medications
|
148 |
-
selected_medications = [med for row in medication_rows for med in row]
|
149 |
|
150 |
# Load constants and medication data
|
151 |
medication_data = load_medication_data()
|
@@ -159,7 +217,13 @@ def main():
|
|
159 |
if not filtered_predictions:
|
160 |
st.warning("No medications selected. Please select at least one medication or use the 'Show All' option.")
|
161 |
else:
|
|
|
|
|
|
|
|
|
|
|
162 |
display_results(filtered_predictions, selected_site)
|
163 |
|
|
|
164 |
if __name__ == "__main__":
|
165 |
main()
|
|
|
91 |
xaxis=dict(tickmode='array', tickvals=predictions['Year Index'], ticktext=predictions['Year'])
|
92 |
)))
|
93 |
|
94 |
+
# Generate summary of medications reaching the target T-score
|
95 |
+
def generate_goal_summary(predictions, target_tscore=-2.4):
|
96 |
+
def year_to_int(year):
|
97 |
+
# Convert "1st", "2nd", "3rd", etc., to numeric values
|
98 |
+
try:
|
99 |
+
return int(year.rstrip("stndrdth")) # Remove suffixes like "st", "nd", "rd", "th"
|
100 |
+
except ValueError:
|
101 |
+
return 0 # Default to 0 if year cannot be converted
|
102 |
+
|
103 |
+
goal_reached = []
|
104 |
+
|
105 |
+
for result in predictions:
|
106 |
+
drug = result['Drug']
|
107 |
+
predictions_data = result['Predictions']
|
108 |
+
|
109 |
+
for year, tscore in zip(predictions_data['Year'], predictions_data['Predicted T-score']):
|
110 |
+
if tscore >= target_tscore:
|
111 |
+
# Convert year to an integer using helper function
|
112 |
+
numeric_year = year_to_int(year)
|
113 |
+
goal_reached.append({'Medication': drug, 'Year': numeric_year})
|
114 |
+
break # Stop checking further years for this drug
|
115 |
+
|
116 |
+
# Sort by year to prioritize earlier achievement
|
117 |
+
goal_reached_sorted = sorted(goal_reached, key=lambda x: x['Year'])
|
118 |
+
return goal_reached_sorted
|
119 |
+
|
120 |
+
# Display summary of goal-reaching medications
|
121 |
+
def display_goal_summary(goal_summary):
|
122 |
+
st.subheader("Goal Treatment Summary (T-score ≥ -2.4)")
|
123 |
+
|
124 |
+
if not goal_summary:
|
125 |
+
st.info("No medications reach the target T-score.")
|
126 |
+
else:
|
127 |
+
summary_table = pd.DataFrame(goal_summary)
|
128 |
+
st.table(summary_table)
|
129 |
+
|
130 |
+
# Medication Selection with Collapsible Categories
|
131 |
+
def select_medications():
|
132 |
+
st.subheader("Select Medications to Display")
|
133 |
+
show_all = st.checkbox("Show All Medications", key="show_all")
|
134 |
+
|
135 |
+
selected_medications = []
|
136 |
+
if not show_all:
|
137 |
+
# Define categories and medications
|
138 |
+
categories = {
|
139 |
+
"Bisphosphonates": [
|
140 |
+
"Alendronate", "Risedronate", "Ibandronate oral",
|
141 |
+
"Zoledronate", "Ibandronate IV (3mg)"
|
142 |
+
],
|
143 |
+
"RANK Ligand Inhibitors": [
|
144 |
+
"Denosumab", "Denosumab + Teriparatide"
|
145 |
+
],
|
146 |
+
"Anabolic Agents": [
|
147 |
+
"Teriparatide", "Teriparatide + Denosumab"
|
148 |
+
],
|
149 |
+
"Sclerostin Inhibitors": [
|
150 |
+
"Romosozumab", "Romosozumab + Denosumab",
|
151 |
+
"Romosozumab + Alendronate", "Romosozumab + Ibandronate",
|
152 |
+
"Romosozumab + Zoledronate"
|
153 |
+
]
|
154 |
+
}
|
155 |
+
|
156 |
+
# Create collapsible sections
|
157 |
+
for category, medications in categories.items():
|
158 |
+
with st.expander(category):
|
159 |
+
for med in medications:
|
160 |
+
# Use a unique key for each checkbox
|
161 |
+
if st.checkbox(med, key=f"{category}_{med}"):
|
162 |
+
selected_medications.append(med)
|
163 |
+
else:
|
164 |
+
# Include all medications if "Show All" is selected
|
165 |
+
selected_medications = [
|
166 |
+
"Alendronate", "Risedronate", "Ibandronate oral",
|
167 |
+
"Zoledronate", "Ibandronate IV (3mg)", "Denosumab",
|
168 |
+
"Denosumab + Teriparatide", "Teriparatide",
|
169 |
+
"Teriparatide + Denosumab", "Romosozumab",
|
170 |
+
"Romosozumab + Denosumab", "Romosozumab + Alendronate",
|
171 |
+
"Romosozumab + Ibandronate", "Romosozumab + Zoledronate"
|
172 |
+
]
|
173 |
+
|
174 |
+
return selected_medications
|
175 |
+
|
176 |
# Streamlit UI
|
177 |
+
# Main function
|
178 |
def main():
|
179 |
st.title("BMD and T-score Prediction Tool")
|
180 |
|
|
|
202 |
format="%.3f"
|
203 |
)
|
204 |
|
205 |
+
# Medication Selection
|
206 |
+
selected_medications = select_medications() # Ensure this is only called once
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
|
208 |
# Load constants and medication data
|
209 |
medication_data = load_medication_data()
|
|
|
217 |
if not filtered_predictions:
|
218 |
st.warning("No medications selected. Please select at least one medication or use the 'Show All' option.")
|
219 |
else:
|
220 |
+
# Generate and display goal treatment summary
|
221 |
+
goal_summary = generate_goal_summary(filtered_predictions, target_tscore=-2.4)
|
222 |
+
display_goal_summary(goal_summary)
|
223 |
+
|
224 |
+
# Display individual medication results
|
225 |
display_results(filtered_predictions, selected_site)
|
226 |
|
227 |
+
|
228 |
if __name__ == "__main__":
|
229 |
main()
|