re-type commited on
Commit
62b42ec
·
verified ·
1 Parent(s): 7d8c0b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -18
app.py CHANGED
@@ -96,7 +96,7 @@ except Exception as e:
96
  analyzer = None
97
 
98
  # --- Tree Analysis Function (Based on old Gradio API) ---
99
- def analyze_sequence_for_tree(sequence: str, matching_percentage: float = 95.0) -> str:
100
  """
101
  Analyze sequence and create phylogenetic tree using the working Gradio API pattern
102
  """
@@ -205,18 +205,18 @@ def read_fasta_file(file_obj):
205
  return ""
206
 
207
  # --- Full Pipeline ---
208
- def run_pipeline_from_file(fasta_file_obj):
209
  try:
210
  dna_input = read_fasta_file(fasta_file_obj)
211
  if not dna_input:
212
  return "Failed to read FASTA file", "", "", "", None, None, None, "No input sequence"
213
- return run_pipeline(dna_input)
214
  except Exception as e:
215
  error_msg = f"Pipeline error: {str(e)}"
216
  logging.error(error_msg)
217
  return error_msg, "", "", "", None, None, None, error_msg
218
 
219
- def run_pipeline(dna_input):
220
  try:
221
  # Clean input
222
  dna_input = dna_input.upper().strip()
@@ -283,8 +283,8 @@ def run_pipeline(dna_input):
283
  try:
284
  logging.info(f"Starting ML tree analysis with F gene sequence length: {len(processed_sequence)}")
285
 
286
- # Use the new tree analysis function
287
- tree_result = analyze_sequence_for_tree(processed_sequence, matching_percentage=95.0)
288
 
289
  if tree_result and not tree_result.startswith("Error:"):
290
  # Success - we have HTML content
@@ -301,7 +301,7 @@ def run_pipeline(dna_input):
301
 
302
  # Count sequences analyzed
303
  if analyzer.find_query_sequence(processed_sequence):
304
- matched_ids, perc = analyzer.find_similar_sequences(95.0)
305
  ml_output += f"\n- {len(matched_ids)} sequences analyzed"
306
  ml_output += f"\n- Similarity threshold: {perc:.1f}%"
307
  else:
@@ -345,18 +345,40 @@ with gr.Blocks(title="Viral Gene Phylogenetic Pipeline", theme=gr.themes.Soft())
345
  gr.Markdown("This pipeline processes DNA sequences through boundary detection, k-mer analysis, and phylogenetic tree construction.")
346
 
347
  with gr.Tab("📝 Paste DNA Sequence"):
348
- inp = gr.Textbox(
349
- label="DNA Input",
350
- placeholder="Paste your DNA sequence here (ACTG format)",
351
- lines=5
352
- )
 
 
 
 
 
 
 
 
 
 
 
353
  btn1 = gr.Button("🚀 Run Pipeline", variant="primary", size="lg")
354
 
355
  with gr.Tab("📁 Upload FASTA File"):
356
- file_input = gr.File(
357
- label="FASTA File",
358
- file_types=['.fasta', '.fa', '.txt']
359
- )
 
 
 
 
 
 
 
 
 
 
 
360
  btn2 = gr.Button("🚀 Run on FASTA", variant="primary", size="lg")
361
 
362
  # Outputs
@@ -381,12 +403,12 @@ with gr.Blocks(title="Viral Gene Phylogenetic Pipeline", theme=gr.themes.Soft())
381
  # Event handlers
382
  btn1.click(
383
  fn=run_pipeline,
384
- inputs=inp,
385
  outputs=[out1, out2, out3, out4, html, fasta, phy, tree_html]
386
  )
387
  btn2.click(
388
  fn=run_pipeline_from_file,
389
- inputs=file_input,
390
  outputs=[out1, out2, out3, out4, html, fasta, phy, tree_html]
391
  )
392
 
 
96
  analyzer = None
97
 
98
  # --- Tree Analysis Function (Based on old Gradio API) ---
99
+ def analyze_sequence_for_tree(sequence: str, matching_percentage: float) -> str:
100
  """
101
  Analyze sequence and create phylogenetic tree using the working Gradio API pattern
102
  """
 
205
  return ""
206
 
207
  # --- Full Pipeline ---
208
+ def run_pipeline_from_file(fasta_file_obj, similarity_score):
209
  try:
210
  dna_input = read_fasta_file(fasta_file_obj)
211
  if not dna_input:
212
  return "Failed to read FASTA file", "", "", "", None, None, None, "No input sequence"
213
+ return run_pipeline(dna_input, similarity_score)
214
  except Exception as e:
215
  error_msg = f"Pipeline error: {str(e)}"
216
  logging.error(error_msg)
217
  return error_msg, "", "", "", None, None, None, error_msg
218
 
219
+ def run_pipeline(dna_input, similarity_score=95.0):
220
  try:
221
  # Clean input
222
  dna_input = dna_input.upper().strip()
 
283
  try:
284
  logging.info(f"Starting ML tree analysis with F gene sequence length: {len(processed_sequence)}")
285
 
286
+ # Use the new tree analysis function with user-specified similarity
287
+ tree_result = analyze_sequence_for_tree(processed_sequence, matching_percentage=similarity_score)
288
 
289
  if tree_result and not tree_result.startswith("Error:"):
290
  # Success - we have HTML content
 
301
 
302
  # Count sequences analyzed
303
  if analyzer.find_query_sequence(processed_sequence):
304
+ matched_ids, perc = analyzer.find_similar_sequences(similarity_score)
305
  ml_output += f"\n- {len(matched_ids)} sequences analyzed"
306
  ml_output += f"\n- Similarity threshold: {perc:.1f}%"
307
  else:
 
345
  gr.Markdown("This pipeline processes DNA sequences through boundary detection, k-mer analysis, and phylogenetic tree construction.")
346
 
347
  with gr.Tab("📝 Paste DNA Sequence"):
348
+ with gr.Row():
349
+ with gr.Column(scale=3):
350
+ inp = gr.Textbox(
351
+ label="DNA Input",
352
+ placeholder="Paste your DNA sequence here (ACTG format)",
353
+ lines=5
354
+ )
355
+ with gr.Column(scale=1):
356
+ similarity_input = gr.Slider(
357
+ minimum=50,
358
+ maximum=99,
359
+ step=1,
360
+ value=95,
361
+ label="Similarity Threshold (%)",
362
+ info="Higher values = more similar sequences"
363
+ )
364
  btn1 = gr.Button("🚀 Run Pipeline", variant="primary", size="lg")
365
 
366
  with gr.Tab("📁 Upload FASTA File"):
367
+ with gr.Row():
368
+ with gr.Column(scale=3):
369
+ file_input = gr.File(
370
+ label="FASTA File",
371
+ file_types=['.fasta', '.fa', '.txt']
372
+ )
373
+ with gr.Column(scale=1):
374
+ similarity_input_file = gr.Slider(
375
+ minimum=50,
376
+ maximum=99,
377
+ step=1,
378
+ value=95,
379
+ label="Similarity Threshold (%)",
380
+ info="Higher values = more similar sequences"
381
+ )
382
  btn2 = gr.Button("🚀 Run on FASTA", variant="primary", size="lg")
383
 
384
  # Outputs
 
403
  # Event handlers
404
  btn1.click(
405
  fn=run_pipeline,
406
+ inputs=[inp, similarity_input],
407
  outputs=[out1, out2, out3, out4, html, fasta, phy, tree_html]
408
  )
409
  btn2.click(
410
  fn=run_pipeline_from_file,
411
+ inputs=[file_input, similarity_input_file],
412
  outputs=[out1, out2, out3, out4, html, fasta, phy, tree_html]
413
  )
414