Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import subprocess
|
|
| 6 |
import pandas as pd
|
| 7 |
from predictor import GenePredictor
|
| 8 |
from tensorflow.keras.models import load_model
|
| 9 |
-
|
| 10 |
import logging
|
| 11 |
import os
|
| 12 |
|
|
@@ -19,9 +19,9 @@ try:
|
|
| 19 |
keras_model = load_model("best_model.keras")
|
| 20 |
with open("kmer_to_index.pkl", "rb") as f:
|
| 21 |
kmer_to_index = pickle.load(f)
|
| 22 |
-
logging.info("Models and kmer_to_index loaded successfully")
|
| 23 |
except FileNotFoundError as e:
|
| 24 |
-
logging.error(f"Model or file not found: {e}")
|
| 25 |
raise
|
| 26 |
except Exception as e:
|
| 27 |
logging.error(f"Error loading models or files: {e}")
|
|
@@ -51,7 +51,7 @@ def save_to_fasta(name, sequence, path):
|
|
| 51 |
|
| 52 |
def save_to_csv(sequence, path):
|
| 53 |
try:
|
| 54 |
-
df = pd.DataFrame({"
|
| 55 |
df.to_csv(path, index=False)
|
| 56 |
logging.info(f"CSV file saved to {path}")
|
| 57 |
return "CSV file saved successfully"
|
|
@@ -93,19 +93,19 @@ def run_full_pipeline(dna_input):
|
|
| 93 |
# Step 3b: Run MAFFT and IQTree
|
| 94 |
mafft_status = run_mafft_and_iqtree(step2_out)
|
| 95 |
|
| 96 |
-
# Step 3c: Run ML Simplified Tree
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
ml_output =
|
| 100 |
-
|
| 101 |
-
|
|
|
|
| 102 |
else:
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
html_file = None
|
| 109 |
|
| 110 |
return {
|
| 111 |
"Boundary Model Output": step1_out,
|
|
@@ -131,7 +131,7 @@ def run_full_pipeline(dna_input):
|
|
| 131 |
# --------- Gradio Interface and API ---------
|
| 132 |
with gr.Blocks() as gr_interface:
|
| 133 |
gr.Markdown("# Sequential Phylogenetic Inference Pipeline")
|
| 134 |
-
gr.Markdown("This pipeline runs
|
| 135 |
|
| 136 |
dna_input = gr.Textbox(label="Input DNA Sequence")
|
| 137 |
submit_button = gr.Button("Run Pipeline")
|
|
|
|
| 6 |
import pandas as pd
|
| 7 |
from predictor import GenePredictor
|
| 8 |
from tensorflow.keras.models import load_model
|
| 9 |
+
import ml_simplified_tree # Import the module
|
| 10 |
import logging
|
| 11 |
import os
|
| 12 |
|
|
|
|
| 19 |
keras_model = load_model("best_model.keras")
|
| 20 |
with open("kmer_to_index.pkl", "rb") as f:
|
| 21 |
kmer_to_index = pickle.load(f)
|
| 22 |
+
logging.info("Models and kmer_to_index loaded successfully from Space")
|
| 23 |
except FileNotFoundError as e:
|
| 24 |
+
logging.error(f"Model or file not found in Space: {e}")
|
| 25 |
raise
|
| 26 |
except Exception as e:
|
| 27 |
logging.error(f"Error loading models or files: {e}")
|
|
|
|
| 51 |
|
| 52 |
def save_to_csv(sequence, path):
|
| 53 |
try:
|
| 54 |
+
df = pd.DataFrame({"F-gene": [sequence], "Accession Number": ["Query"], "ML": ["Unknown"], "Genotype": ["Unknown"]})
|
| 55 |
df.to_csv(path, index=False)
|
| 56 |
logging.info(f"CSV file saved to {path}")
|
| 57 |
return "CSV file saved successfully"
|
|
|
|
| 93 |
# Step 3b: Run MAFFT and IQTree
|
| 94 |
mafft_status = run_mafft_and_iqtree(step2_out)
|
| 95 |
|
| 96 |
+
# Step 3c: Run ML Simplified Tree using PhylogeneticTreeAnalyzer
|
| 97 |
+
analyzer = ml_simplified_tree.PhylogeneticTreeAnalyzer()
|
| 98 |
+
if not analyzer.load_data("f_gene_clean_dataset.csv"):
|
| 99 |
+
ml_output = "Error: Failed to load data"
|
| 100 |
+
else:
|
| 101 |
+
if not analyzer.find_query_sequence(step2_out):
|
| 102 |
+
ml_output = "Error: Invalid query sequence"
|
| 103 |
else:
|
| 104 |
+
matched_ids, actual_percentage = analyzer.find_similar_sequences(analyzer.matching_percentage)
|
| 105 |
+
analyzer.create_interactive_tree(matched_ids, actual_percentage)
|
| 106 |
+
ml_output = f"Tree generated and saved as phylogenetic_tree_normalized_horizontal.html" if os.path.exists("phylogenetic_tree_normalized_horizontal.html") else "Error: Tree generation failed"
|
| 107 |
+
|
| 108 |
+
html_file = "phylogenetic_tree_normalized_horizontal.html" if os.path.exists("phylogenetic_tree_normalized_horizontal.html") else None
|
|
|
|
| 109 |
|
| 110 |
return {
|
| 111 |
"Boundary Model Output": step1_out,
|
|
|
|
| 131 |
# --------- Gradio Interface and API ---------
|
| 132 |
with gr.Blocks() as gr_interface:
|
| 133 |
gr.Markdown("# Sequential Phylogenetic Inference Pipeline")
|
| 134 |
+
gr.Markdown("This pipeline runs: Boundary-Aware Model → Keras Model → MAFFT/IQTree & ML Tree")
|
| 135 |
|
| 136 |
dna_input = gr.Textbox(label="Input DNA Sequence")
|
| 137 |
submit_button = gr.Button("Run Pipeline")
|