roman-bushuiev commited on
Commit
12f0086
·
1 Parent(s): ac7edf1

Refactor table code

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -593,7 +593,7 @@ def _create_gradio_interface():
593
  DreaMS (Deep Representations Empowering the Annotation of Mass Spectra) is a transformer-based
594
  neural network designed to interpret tandem mass spectrometry (MS/MS) data (<a href="https://www.nature.com/articles/s41587-025-02663-3">Bushuiev et al., Nature Biotechnology, 2025</a>).
595
  This website provides an easy access to perform library matching with DreaMS against the <a href="https://huggingface.co/datasets/roman-bushuiev/MassSpecGym">MassSpecGym</a> spectral library (combination of GNPS, MoNA, and Pluskal lab data). Please upload
596
- your MS/MS file and click on the "Run DreaMS" button.
597
  """)
598
 
599
  # Input section
@@ -609,7 +609,7 @@ def _create_gradio_interface():
609
  inputs=[in_pth],
610
  label="Examples (click on a file to load as input)",
611
  )
612
-
613
  # Settings section
614
  with gr.Accordion("⚙️ Settings", open=False):
615
  calculate_modified_cosine = gr.Checkbox(
@@ -626,12 +626,16 @@ def _create_gradio_interface():
626
  df_file = gr.File(label="Download predictions as .csv", interactive=False, visible=True)
627
 
628
  # Results table
 
 
 
 
 
629
  df = gr.Dataframe(
630
- headers=["Row", "Scan number", "Retention time", "Charge", "Precursor m/z", "Molecule", "Spectrum",
631
- "DreaMS similarity", "Library ID"],
632
- datatype=["number", "number", "number", "str", "number", "html", "html", "number", "str"],
633
- col_count=(9, "fixed"),
634
- column_widths=["20px", "30px", "30px", "25px", "30px", "40px", "40px", "40px", "50px"],
635
  max_height=1000,
636
  show_fullscreen_button=True,
637
  show_row_numbers=False,
@@ -645,15 +649,13 @@ def _create_gradio_interface():
645
  # Function to update dataframe headers based on setting
646
  def update_headers(show_cosine):
647
  if show_cosine:
648
- return gr.update(headers=["Row", "Scan number", "Retention time", "Charge", "Precursor m/z", "Molecule", "Spectrum",
649
- "DreaMS similarity", "Library ID", "Modified cosine similarity"],
650
- col_count=(10, "fixed"),
651
- column_widths=["20px", "30px", "30px", "25px", "30px", "40px", "40px", "40px", "50px", "40px"])
652
  else:
653
- return gr.update(headers=["Row", "Scan number", "Retention time", "Charge", "Precursor m/z", "Molecule", "Spectrum",
654
- "DreaMS similarity", "Library ID"],
655
- col_count=(9, "fixed"),
656
- column_widths=["20px", "30px", "30px", "25px", "30px", "40px", "40px", "40px", "50px"])
657
 
658
  # Update headers when setting changes
659
  calculate_modified_cosine.change(
 
593
  DreaMS (Deep Representations Empowering the Annotation of Mass Spectra) is a transformer-based
594
  neural network designed to interpret tandem mass spectrometry (MS/MS) data (<a href="https://www.nature.com/articles/s41587-025-02663-3">Bushuiev et al., Nature Biotechnology, 2025</a>).
595
  This website provides an easy access to perform library matching with DreaMS against the <a href="https://huggingface.co/datasets/roman-bushuiev/MassSpecGym">MassSpecGym</a> spectral library (combination of GNPS, MoNA, and Pluskal lab data). Please upload
596
+ your file with MS/MS data and click on the "Run DreaMS" button.
597
  """)
598
 
599
  # Input section
 
609
  inputs=[in_pth],
610
  label="Examples (click on a file to load as input)",
611
  )
612
+
613
  # Settings section
614
  with gr.Accordion("⚙️ Settings", open=False):
615
  calculate_modified_cosine = gr.Checkbox(
 
626
  df_file = gr.File(label="Download predictions as .csv", interactive=False, visible=True)
627
 
628
  # Results table
629
+ headers = ["Row", "Scan number", "Retention time", "Charge", "Precursor m/z", "Molecule", "Spectrum",
630
+ "DreaMS similarity", "Library ID"]
631
+ datatype = ["number", "number", "number", "str", "number", "html", "html", "number", "str"]
632
+ column_widths = ["20px", "30px", "30px", "25px", "30px", "40px", "40px", "40px", "50px"]
633
+
634
  df = gr.Dataframe(
635
+ headers=headers,
636
+ datatype=datatype,
637
+ col_count=(len(headers), "fixed"),
638
+ column_widths=column_widths,
 
639
  max_height=1000,
640
  show_fullscreen_button=True,
641
  show_row_numbers=False,
 
649
  # Function to update dataframe headers based on setting
650
  def update_headers(show_cosine):
651
  if show_cosine:
652
+ return gr.update(headers=headers + ["Modified cosine similarity"],
653
+ col_count=(len(headers) + 1, "fixed"),
654
+ column_widths=column_widths + ["40px"])
 
655
  else:
656
+ return gr.update(headers=headers,
657
+ col_count=(len(headers), "fixed"),
658
+ column_widths=column_widths)
 
659
 
660
  # Update headers when setting changes
661
  calculate_modified_cosine.change(