hiyata commited on
Commit
e9f8387
·
verified ·
1 Parent(s): d1cde92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -64
app.py CHANGED
@@ -8,6 +8,8 @@ import matplotlib.pyplot as plt
8
  import matplotlib.colors as mcolors
9
  import io
10
  from PIL import Image
 
 
11
 
12
  ###############################################################################
13
  # 1. MODEL DEFINITION
@@ -474,9 +476,6 @@ def analyze_subregion(state, header, region_start, region_end):
474
 
475
  return (region_info, heatmap_img, hist_img)
476
 
477
- # Add these imports at the top of the file, after existing imports
478
- from scipy.interpolate import interp1d
479
- import numpy as np
480
 
481
  ###############################################################################
482
  # NEW SECTION: COMPARATIVE ANALYSIS FUNCTIONS
@@ -638,66 +637,6 @@ Negative values (blue) indicate regions where Sequence 1 is more "human-like"
638
 
639
  return comparison_text, heatmap_img, hist_img
640
 
641
- ###############################################################################
642
- # NEW TAB TO GRADIO
643
- ###############################################################################
644
-
645
- # Inside the Gradio interface definition, add this new tab:
646
- with gr.Tab("3) Comparative Analysis"):
647
- gr.Markdown("""
648
- **Compare Two Sequences**
649
- Upload or paste two FASTA sequences to compare their SHAP patterns.
650
- The sequences will be normalized to the same length for comparison.
651
-
652
- **Color Scale**:
653
- - Red: Sequence 2 is more human-like in this region
654
- - Blue: Sequence 1 is more human-like in this region
655
- - White: No substantial difference
656
- """)
657
-
658
- with gr.Row():
659
- with gr.Column(scale=1):
660
- file_input1 = gr.File(
661
- label="Upload first FASTA file",
662
- file_types=[".fasta", ".fa", ".txt"],
663
- type="filepath"
664
- )
665
- text_input1 = gr.Textbox(
666
- label="Or paste first FASTA sequence",
667
- placeholder=">sequence1\nACGTACGT...",
668
- lines=5
669
- )
670
-
671
- with gr.Column(scale=1):
672
- file_input2 = gr.File(
673
- label="Upload second FASTA file",
674
- file_types=[".fasta", ".fa", ".txt"],
675
- type="filepath"
676
- )
677
- text_input2 = gr.Textbox(
678
- label="Or paste second FASTA sequence",
679
- placeholder=">sequence2\nACGTACGT...",
680
- lines=5
681
- )
682
-
683
- compare_btn = gr.Button("Compare Sequences", variant="primary")
684
-
685
- comparison_text = gr.Textbox(
686
- label="Comparison Results",
687
- lines=12,
688
- interactive=False
689
- )
690
-
691
- with gr.Row():
692
- diff_heatmap = gr.Image(label="SHAP Difference Heatmap")
693
- diff_hist = gr.Image(label="Distribution of SHAP Differences")
694
-
695
- compare_btn.click(
696
- analyze_sequence_comparison,
697
- inputs=[file_input1, file_input2, text_input1, text_input2],
698
- outputs=[comparison_text, diff_heatmap, diff_hist]
699
- )
700
-
701
  ###############################################################################
702
  # 9. BUILD GRADIO INTERFACE
703
  ###############################################################################
@@ -788,7 +727,61 @@ with gr.Blocks(css=css) as iface:
788
  inputs=[seq_state, header_state, region_start, region_end],
789
  outputs=[subregion_info, subregion_img, subregion_hist_img]
790
  )
791
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
792
  gr.Markdown("""
793
  ### Interface Features
794
  - **Overall Classification** (human vs non-human) using k-mer frequencies.
 
8
  import matplotlib.colors as mcolors
9
  import io
10
  from PIL import Image
11
+ from scipy.interpolate import interp1d
12
+ import numpy as np
13
 
14
  ###############################################################################
15
  # 1. MODEL DEFINITION
 
476
 
477
  return (region_info, heatmap_img, hist_img)
478
 
 
 
 
479
 
480
  ###############################################################################
481
  # NEW SECTION: COMPARATIVE ANALYSIS FUNCTIONS
 
637
 
638
  return comparison_text, heatmap_img, hist_img
639
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
640
  ###############################################################################
641
  # 9. BUILD GRADIO INTERFACE
642
  ###############################################################################
 
727
  inputs=[seq_state, header_state, region_start, region_end],
728
  outputs=[subregion_info, subregion_img, subregion_hist_img]
729
  )
730
+
731
+ with gr.Tab("3) Comparative Analysis"):
732
+ gr.Markdown("""
733
+ **Compare Two Sequences**
734
+ Upload or paste two FASTA sequences to compare their SHAP patterns.
735
+ The sequences will be normalized to the same length for comparison.
736
+
737
+ **Color Scale**:
738
+ - Red: Sequence 2 is more human-like in this region
739
+ - Blue: Sequence 1 is more human-like in this region
740
+ - White: No substantial difference
741
+ """)
742
+
743
+ with gr.Row():
744
+ with gr.Column(scale=1):
745
+ file_input1 = gr.File(
746
+ label="Upload first FASTA file",
747
+ file_types=[".fasta", ".fa", ".txt"],
748
+ type="filepath"
749
+ )
750
+ text_input1 = gr.Textbox(
751
+ label="Or paste first FASTA sequence",
752
+ placeholder=">sequence1\nACGTACGT...",
753
+ lines=5
754
+ )
755
+
756
+ with gr.Column(scale=1):
757
+ file_input2 = gr.File(
758
+ label="Upload second FASTA file",
759
+ file_types=[".fasta", ".fa", ".txt"],
760
+ type="filepath"
761
+ )
762
+ text_input2 = gr.Textbox(
763
+ label="Or paste second FASTA sequence",
764
+ placeholder=">sequence2\nACGTACGT...",
765
+ lines=5
766
+ )
767
+
768
+ compare_btn = gr.Button("Compare Sequences", variant="primary")
769
+
770
+ comparison_text = gr.Textbox(
771
+ label="Comparison Results",
772
+ lines=12,
773
+ interactive=False
774
+ )
775
+
776
+ with gr.Row():
777
+ diff_heatmap = gr.Image(label="SHAP Difference Heatmap")
778
+ diff_hist = gr.Image(label="Distribution of SHAP Differences")
779
+
780
+ compare_btn.click(
781
+ analyze_sequence_comparison,
782
+ inputs=[file_input1, file_input2, text_input1, text_input2],
783
+ outputs=[comparison_text, diff_heatmap, diff_hist]
784
+ )
785
  gr.Markdown("""
786
  ### Interface Features
787
  - **Overall Classification** (human vs non-human) using k-mer frequencies.