Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -208,7 +208,7 @@ def check_tool_availability():
|
|
| 208 |
|
| 209 |
# --- Pipeline Functions ---
|
| 210 |
def phylogenetic_placement(sequence: str, mafft_cmd: str, iqtree_cmd: str):
|
| 211 |
-
query_fasta = None
|
| 212 |
try:
|
| 213 |
if len(sequence.strip()) < 100:
|
| 214 |
return False, "Sequence too short (<100 bp).", None, None
|
|
@@ -235,11 +235,10 @@ def phylogenetic_placement(sequence: str, mafft_cmd: str, iqtree_cmd: str):
|
|
| 235 |
return False, "IQ-TREE placement failed.", aligned_with_query, None
|
| 236 |
success_msg = f"Placement completed!\nQuery ID: {query_id}\nAlignment: {os.path.basename(aligned_with_query)}\nTree: {os.path.basename(treefile)}"
|
| 237 |
return True, success_msg, aligned_with_query, treefile
|
| 238 |
-
except Exception as
|
| 239 |
-
logger.error(f"Phylogenetic placement failed: {
|
| 240 |
-
return False, f"Error: {str(
|
| 241 |
finally:
|
| 242 |
-
# FIXED: Properly handle cleanup with specific exception handling
|
| 243 |
if query_fasta and os.path.exists(query_fasta):
|
| 244 |
try:
|
| 245 |
os.unlink(query_fasta)
|
|
|
|
| 208 |
|
| 209 |
# --- Pipeline Functions ---
|
| 210 |
def phylogenetic_placement(sequence: str, mafft_cmd: str, iqtree_cmd: str):
|
| 211 |
+
query_fasta = None # Predefine to avoid scoping issues
|
| 212 |
try:
|
| 213 |
if len(sequence.strip()) < 100:
|
| 214 |
return False, "Sequence too short (<100 bp).", None, None
|
|
|
|
| 235 |
return False, "IQ-TREE placement failed.", aligned_with_query, None
|
| 236 |
success_msg = f"Placement completed!\nQuery ID: {query_id}\nAlignment: {os.path.basename(aligned_with_query)}\nTree: {os.path.basename(treefile)}"
|
| 237 |
return True, success_msg, aligned_with_query, treefile
|
| 238 |
+
except Exception as main_error: # Renamed from 'e' to avoid scoping issues
|
| 239 |
+
logger.error(f"Phylogenetic placement failed: {main_error}", exc_info=True)
|
| 240 |
+
return False, f"Error: {str(main_error)}", None, None
|
| 241 |
finally:
|
|
|
|
| 242 |
if query_fasta and os.path.exists(query_fasta):
|
| 243 |
try:
|
| 244 |
os.unlink(query_fasta)
|