Vamsi Thiriveedhi commited on
Commit
3ec0ae0
·
1 Parent(s): 0d7be01

feat: provide an option to sort and download resulting dataset

Browse files
Files changed (1) hide show
  1. filter_data_app.py +27 -13
filter_data_app.py CHANGED
@@ -6,6 +6,7 @@ from upsetplot import UpSet
6
  import matplotlib.pyplot as plt
7
  import polars as pl
8
  from polars import col, lit
 
9
 
10
  # Set page configuration
11
  st.set_page_config(layout="wide")
@@ -88,7 +89,6 @@ def calculate_std_dev(df,radiomics_feature):
88
  # Main function to run the Streamlit app
89
  def main():
90
  st.title("Qualitative Checks of TotalSegmentator Segmentations on NLST")
91
- st.write("Filter the data based on qualitative checks, bodyPart, and laterality.")
92
 
93
  # Sidebar widgets for navigation and filtering
94
  page = st.sidebar.selectbox("Choose a page", ["Summary", "UpSet Plots"])
@@ -97,6 +97,7 @@ def main():
97
  #df = load_data()
98
 
99
  if page == "UpSet Plots":
 
100
  with st.sidebar:
101
  st.title("Filters")
102
 
@@ -122,7 +123,7 @@ def main():
122
  'series_with_vertabra_on_every_slice': None,
123
  'connected_volumes': None,
124
  'laterality': None,
125
- 'radiomics_feature': 'Volume from Voxel Summation'
126
  })
127
  st.session_state.filters = filters
128
 
@@ -170,8 +171,9 @@ def main():
170
  key='radiomics_feature',
171
  on_change=lambda: apply_filter('radiomics_feature', st.session_state.radiomics_feature)
172
  )
173
- df = load_data(radiomics_feature=radiomics_feature)
174
  filters['radiomics_feature'] = radiomics_feature
 
 
175
 
176
  # Body part filter
177
  body_part_options = sorted(df['bodyPart'].unique().to_list())
@@ -237,6 +239,11 @@ def main():
237
  else:
238
  body_part_df = df.filter(col('bodyPart') == lit(body_part))
239
 
 
 
 
 
 
240
 
241
  st.header("UpSet Plots of Qualitative Checks")
242
 
@@ -268,12 +275,11 @@ def main():
268
  paginated_df,
269
  column_config={
270
  "Viewer Url":st.column_config.LinkColumn("StudyInstanceUID",
271
- display_text="https:\/\/viewer\.imaging\.datacommons\.cancer\.gov\/viewer\/(.*)"
272
-
273
  ),
274
 
275
  },
276
- column_order=("PatientID", "Viewer Url", "seriesNumber","bodyPart","laterality", "segmentation_completeness","laterality_check", "series_with_vertabra_on_every_slice","connected_volumes"),
277
  hide_index=True,
278
  use_container_width=True
279
  )
@@ -296,9 +302,6 @@ def main():
296
  if not filtered_df.is_empty():
297
  create_upset_plot_passes(filtered_df)
298
 
299
- import seaborn as sns
300
- import pandas as pd
301
-
302
  # Assuming calculate_std_dev returns a Series
303
  std_dev_before_filtering = calculate_std_dev(body_part_df, radiomics_feature)
304
  std_dev_after_filtering = calculate_std_dev(filtered_df, radiomics_feature)
@@ -317,13 +320,24 @@ def main():
317
  combined_df = combined_df.reset_index(drop=True)
318
 
319
  # Display violin plots for the distribution of standard deviation of volumes
320
- st.header("Violin Plots for Standard Deviation of Volumes")
321
- st.write("This plot shows the distribution of standard deviation of volumes within a patient.")
322
  fig2, ax = plt.subplots()
323
  sns.violinplot(x='Filtering', y=radiomics_feature, data=combined_df, ax=ax)
324
- ax.set_ylabel("Standard Deviation of Volumes")
325
  st.pyplot(fig2)
326
-
 
 
 
 
 
 
 
 
 
 
 
327
 
328
  # Define the pages
329
  if page == "Summary":
 
6
  import matplotlib.pyplot as plt
7
  import polars as pl
8
  from polars import col, lit
9
+ import seaborn as sns
10
 
11
  # Set page configuration
12
  st.set_page_config(layout="wide")
 
89
  # Main function to run the Streamlit app
90
  def main():
91
  st.title("Qualitative Checks of TotalSegmentator Segmentations on NLST")
 
92
 
93
  # Sidebar widgets for navigation and filtering
94
  page = st.sidebar.selectbox("Choose a page", ["Summary", "UpSet Plots"])
 
97
  #df = load_data()
98
 
99
  if page == "UpSet Plots":
100
+ st.write("Filter the data based on radiomics feature, qualitative checks, bodyPart, and laterality.")
101
  with st.sidebar:
102
  st.title("Filters")
103
 
 
123
  'series_with_vertabra_on_every_slice': None,
124
  'connected_volumes': None,
125
  'laterality': None,
126
+ #'radiomics_feature': 'Volume from Voxel Summation'
127
  })
128
  st.session_state.filters = filters
129
 
 
171
  key='radiomics_feature',
172
  on_change=lambda: apply_filter('radiomics_feature', st.session_state.radiomics_feature)
173
  )
 
174
  filters['radiomics_feature'] = radiomics_feature
175
+ df = load_data(radiomics_feature=radiomics_feature)
176
+
177
 
178
  # Body part filter
179
  body_part_options = sorted(df['bodyPart'].unique().to_list())
 
239
  else:
240
  body_part_df = df.filter(col('bodyPart') == lit(body_part))
241
 
242
+ sort_column = st.selectbox("Select column to sort by", options=filtered_df.columns)
243
+ sort_order = st.checkbox("Sort in descending order", value=False)
244
+
245
+ # Sort the DataFrame based on user selection
246
+ filtered_df = filtered_df.sort(by=sort_column, descending=sort_order)
247
 
248
  st.header("UpSet Plots of Qualitative Checks")
249
 
 
275
  paginated_df,
276
  column_config={
277
  "Viewer Url":st.column_config.LinkColumn("StudyInstanceUID",
278
+ display_text="https:\/\/viewer\.imaging\.datacommons\.cancer\.gov\/viewer\/(.*)"
 
279
  ),
280
 
281
  },
282
+ column_order=("PatientID", "Viewer Url", "seriesNumber","bodyPart","laterality", "segmentation_completeness","laterality_check", "series_with_vertabra_on_every_slice","connected_volumes", radiomics_feature),
283
  hide_index=True,
284
  use_container_width=True
285
  )
 
302
  if not filtered_df.is_empty():
303
  create_upset_plot_passes(filtered_df)
304
 
 
 
 
305
  # Assuming calculate_std_dev returns a Series
306
  std_dev_before_filtering = calculate_std_dev(body_part_df, radiomics_feature)
307
  std_dev_after_filtering = calculate_std_dev(filtered_df, radiomics_feature)
 
320
  combined_df = combined_df.reset_index(drop=True)
321
 
322
  # Display violin plots for the distribution of standard deviation of volumes
323
+ st.header(f"Violin Plots for Standard Deviation of {radiomics_feature}")
324
+ st.write(f"This plot shows the distribution of standard deviation of {radiomics_feature} within a patient.")
325
  fig2, ax = plt.subplots()
326
  sns.violinplot(x='Filtering', y=radiomics_feature, data=combined_df, ax=ax)
327
+ ax.set_ylabel(f"Standard Deviation of {radiomics_feature}")
328
  st.pyplot(fig2)
329
+
330
+ def convert_df(df):
331
+ return df.write_csv()
332
+
333
+ csv= convert_df(filtered_df)
334
+ st.sidebar.download_button(
335
+ "Download the filtered dataset",
336
+ csv,
337
+ "TotalSegmentatorRadiomicsResults.csv",
338
+ "text/csv",
339
+ key='download-csv'
340
+ )
341
 
342
  # Define the pages
343
  if page == "Summary":