re-type commited on
Commit
728dcf1
·
verified ·
1 Parent(s): e82ada4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -208,6 +208,7 @@ def check_tool_availability():
208
 
209
  # --- Pipeline Functions ---
210
  def phylogenetic_placement(sequence: str, mafft_cmd: str, iqtree_cmd: str):
 
211
  try:
212
  if len(sequence.strip()) < 100:
213
  return False, "Sequence too short (<100 bp).", None, None
@@ -238,12 +239,12 @@ def phylogenetic_placement(sequence: str, mafft_cmd: str, iqtree_cmd: str):
238
  logger.error(f"Phylogenetic placement failed: {e}", exc_info=True)
239
  return False, f"Error: {str(e)}", None, None
240
  finally:
241
- if 'query_fasta' in locals() and os.path.exists(query_fasta):
 
242
  try:
243
  os.unlink(query_fasta)
244
- except Exception as e: # Fixed bare 'except'
245
- logger.warning(f"Failed to clean up {query_fasta}: {e}")
246
-
247
  def analyze_sequence_for_tree(sequence: str, matching_percentage: float):
248
  try:
249
  logger.debug("Starting tree analysis...")
 
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
 
239
  logger.error(f"Phylogenetic placement failed: {e}", exc_info=True)
240
  return False, f"Error: {str(e)}", None, None
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)
246
+ except Exception as cleanup_error:
247
+ logger.warning(f"Failed to clean up {query_fasta}: {cleanup_error}")
 
248
  def analyze_sequence_for_tree(sequence: str, matching_percentage: float):
249
  try:
250
  logger.debug("Starting tree analysis...")