Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -863,9 +863,11 @@ def create_interface():
|
|
| 863 |
gr.Markdown("### 🌲 Phylogenetic Tree Visualization (ML Simplified Tree)")
|
| 864 |
tree_html = gr.HTML(
|
| 865 |
label="Interactive Tree",
|
| 866 |
-
value="<p>Click '
|
| 867 |
)
|
| 868 |
-
|
|
|
|
|
|
|
| 869 |
|
| 870 |
# File downloads
|
| 871 |
gr.Markdown("### 📁 Download Results")
|
|
@@ -885,78 +887,7 @@ def create_interface():
|
|
| 885 |
interactive=False
|
| 886 |
)
|
| 887 |
|
| 888 |
-
|
| 889 |
-
gr.Markdown("""
|
| 890 |
-
## About This Tool
|
| 891 |
-
|
| 892 |
-
### F Gene Analysis Pipeline
|
| 893 |
-
This comprehensive pipeline analyzes F genes through multiple computational approaches:
|
| 894 |
-
|
| 895 |
-
#### 🎯 Gene Boundary Detection
|
| 896 |
-
- Uses deep learning to identify and extract F gene sequences from larger genomic sequences
|
| 897 |
-
- Provides confidence scores for detected boundaries
|
| 898 |
-
- Automatically trims sequences to focus on the F gene region
|
| 899 |
-
|
| 900 |
-
#### 🔍 Gene Validation
|
| 901 |
-
- Employs k-mer based machine learning models to validate extracted sequences
|
| 902 |
-
- Provides probability scores indicating likelihood of being a genuine F gene
|
| 903 |
-
- Uses 6-mer frequency patterns for classification
|
| 904 |
-
|
| 905 |
-
#### 🌳 Phylogenetic Analysis
|
| 906 |
-
|
| 907 |
-
**Maximum Likelihood Trees:**
|
| 908 |
-
- Requires MAFFT (sequence alignment) and IQ-TREE (phylogenetic reconstruction)
|
| 909 |
-
- Performs model selection and bootstrap analysis
|
| 910 |
-
- Generates publication-quality phylogenetic trees
|
| 911 |
-
- Provides detailed evolutionary analysis
|
| 912 |
-
|
| 913 |
-
**Simplified Trees:**
|
| 914 |
-
- Uses built-in algorithms for quick phylogenetic analysis
|
| 915 |
-
- Interactive visualization with similarity-based clustering
|
| 916 |
-
- Faster alternative when external tools are not available
|
| 917 |
-
|
| 918 |
-
### Input Requirements
|
| 919 |
-
- **DNA Sequences**: ATCG format, minimum 50 bp for meaningful analysis
|
| 920 |
-
- **FASTA Files**: Standard FASTA format with single or multiple sequences
|
| 921 |
-
- **Similarity Threshold**: 1-99% for controlling phylogenetic analysis sensitivity
|
| 922 |
-
|
| 923 |
-
### Dependencies
|
| 924 |
-
|
| 925 |
-
**Required for ML Trees:**
|
| 926 |
-
```bash
|
| 927 |
-
# Ubuntu/Debian
|
| 928 |
-
sudo apt-get install mafft iqtree
|
| 929 |
-
|
| 930 |
-
# macOS
|
| 931 |
-
brew install mafft iqtree
|
| 932 |
-
|
| 933 |
-
# Conda
|
| 934 |
-
conda install -c bioconda mafft iqtree
|
| 935 |
-
```
|
| 936 |
-
|
| 937 |
-
### Output Files
|
| 938 |
-
- **Aligned FASTA**: Multiple sequence alignment in FASTA format
|
| 939 |
-
- **Tree File**: Newick format phylogenetic tree
|
| 940 |
-
- **HTML Tree**: Interactive visualization for web browsers (ML Simplified Tree)
|
| 941 |
-
|
| 942 |
-
### Troubleshooting
|
| 943 |
-
|
| 944 |
-
**Common Issues:**
|
| 945 |
-
- *"No similar sequences found"*: Lower the similarity threshold
|
| 946 |
-
- *"Sequence too short"*: Provide sequences longer than 50 bp
|
| 947 |
-
- *"MAFFT/IQ-TREE not found"*: Install required dependencies
|
| 948 |
-
- *"Model not available"*: Check model files are properly downloaded
|
| 949 |
-
|
| 950 |
-
**Performance Tips:**
|
| 951 |
-
- Use sequences between 100-2000 bp for optimal performance
|
| 952 |
-
- Limit to <50 sequences for faster tree construction
|
| 953 |
-
- Lower similarity thresholds find more distant relatives
|
| 954 |
-
- Higher thresholds focus on closely related sequences
|
| 955 |
-
|
| 956 |
-
### Citation
|
| 957 |
-
If you use this tool in your research, please cite the appropriate methods and tools used.
|
| 958 |
-
""")
|
| 959 |
-
|
| 960 |
# Event handlers
|
| 961 |
def run_analysis_text(dna_seq, sim_score, build_tree):
|
| 962 |
return run_pipeline(dna_seq, sim_score, build_tree)
|
|
@@ -974,16 +905,21 @@ def create_interface():
|
|
| 974 |
def clear_inputs():
|
| 975 |
return "", None, 95.0, False, "Ready to analyze"
|
| 976 |
|
| 977 |
-
def
|
| 978 |
if html_file and os.path.exists(html_file):
|
| 979 |
try:
|
| 980 |
-
|
| 981 |
file_url = f"/file={html_file}"
|
| 982 |
return gr.update(value=f"<script>window.open('{file_url}', '_blank');</script>")
|
| 983 |
except Exception as e:
|
| 984 |
-
return gr.update(value=f"<p>Error
|
| 985 |
return gr.update(value="<p>No tree file available. Run analysis to generate one.</p>")
|
| 986 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 987 |
# Connect events
|
| 988 |
run_btn.click(
|
| 989 |
fn=run_analysis_combined,
|
|
@@ -1000,12 +936,18 @@ def create_interface():
|
|
| 1000 |
outputs=[dna_input, fasta_file, similarity_score, build_ml_tree, status_display]
|
| 1001 |
)
|
| 1002 |
|
| 1003 |
-
|
| 1004 |
-
fn=
|
| 1005 |
inputs=[html_file],
|
| 1006 |
outputs=[tree_html]
|
| 1007 |
)
|
| 1008 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1009 |
# Example data loading
|
| 1010 |
gr.Markdown("### 🧪 Example Data")
|
| 1011 |
example_btn = gr.Button("Load Example F Gene Sequence", variant="secondary")
|
|
@@ -1020,7 +962,7 @@ def create_interface():
|
|
| 1020 |
)
|
| 1021 |
|
| 1022 |
return iface
|
| 1023 |
-
|
| 1024 |
# --- Main Execution ---
|
| 1025 |
if __name__ == "__main__":
|
| 1026 |
# Initialize and launch interface
|
|
|
|
| 863 |
gr.Markdown("### 🌲 Phylogenetic Tree Visualization (ML Simplified Tree)")
|
| 864 |
tree_html = gr.HTML(
|
| 865 |
label="Interactive Tree",
|
| 866 |
+
value="<p>Click 'Show Tree' to view the ML Simplified Tree in a new tab or 'Download Tree' to save it.</p>"
|
| 867 |
)
|
| 868 |
+
with gr.Row():
|
| 869 |
+
show_tree_btn = gr.Button("👁️ Show Tree", variant="secondary")
|
| 870 |
+
download_tree_btn = gr.Button("⬇️ Download Tree", variant="secondary")
|
| 871 |
|
| 872 |
# File downloads
|
| 873 |
gr.Markdown("### 📁 Download Results")
|
|
|
|
| 887 |
interactive=False
|
| 888 |
)
|
| 889 |
|
| 890 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 891 |
# Event handlers
|
| 892 |
def run_analysis_text(dna_seq, sim_score, build_tree):
|
| 893 |
return run_pipeline(dna_seq, sim_score, build_tree)
|
|
|
|
| 905 |
def clear_inputs():
|
| 906 |
return "", None, 95.0, False, "Ready to analyze"
|
| 907 |
|
| 908 |
+
def show_tree(html_file):
|
| 909 |
if html_file and os.path.exists(html_file):
|
| 910 |
try:
|
| 911 |
+
# Serve the file directly using Gradio's file endpoint
|
| 912 |
file_url = f"/file={html_file}"
|
| 913 |
return gr.update(value=f"<script>window.open('{file_url}', '_blank');</script>")
|
| 914 |
except Exception as e:
|
| 915 |
+
return gr.update(value=f"<p>Error showing tree: {str(e)}. Please use the 'Download Tree' button and open manually.</p>")
|
| 916 |
return gr.update(value="<p>No tree file available. Run analysis to generate one.</p>")
|
| 917 |
|
| 918 |
+
def download_tree(html_file):
|
| 919 |
+
if html_file and os.path.exists(html_file):
|
| 920 |
+
return gr.File.update(value=html_file, visible=True)
|
| 921 |
+
return gr.File.update(value=None, visible=False)
|
| 922 |
+
|
| 923 |
# Connect events
|
| 924 |
run_btn.click(
|
| 925 |
fn=run_analysis_combined,
|
|
|
|
| 936 |
outputs=[dna_input, fasta_file, similarity_score, build_ml_tree, status_display]
|
| 937 |
)
|
| 938 |
|
| 939 |
+
show_tree_btn.click(
|
| 940 |
+
fn=show_tree,
|
| 941 |
inputs=[html_file],
|
| 942 |
outputs=[tree_html]
|
| 943 |
)
|
| 944 |
|
| 945 |
+
download_tree_btn.click(
|
| 946 |
+
fn=download_tree,
|
| 947 |
+
inputs=[html_file],
|
| 948 |
+
outputs=[html_file]
|
| 949 |
+
)
|
| 950 |
+
|
| 951 |
# Example data loading
|
| 952 |
gr.Markdown("### 🧪 Example Data")
|
| 953 |
example_btn = gr.Button("Load Example F Gene Sequence", variant="secondary")
|
|
|
|
| 962 |
)
|
| 963 |
|
| 964 |
return iface
|
| 965 |
+
|
| 966 |
# --- Main Execution ---
|
| 967 |
if __name__ == "__main__":
|
| 968 |
# Initialize and launch interface
|