Keep the match list and the chart in step

#10
by lvwerra HF Staff - opened
Files changed (1) hide show
  1. taxonomy.py +12 -2
taxonomy.py CHANGED
@@ -504,13 +504,23 @@ def build_taxonomy_tab():
504
  return show(taxonomy.taxon_path(taxid) if taxid else DEFAULT_PATH)
505
 
506
  def taxonomy_best(text):
 
 
 
 
 
507
  choices = taxonomy.search(text)
508
- return taxonomy_view(choices[0][1] if choices else None)
 
 
 
 
 
509
 
510
  # No separate search button: the list follows what is typed, Enter takes
511
  # the closest match, and picking any row opens it.
512
  query.change(taxonomy_search, query, [matches, status], show_progress="hidden")
513
- query.submit(taxonomy_best, query, [tree, route, open_database])
514
  matches.input(taxonomy_view, matches, [tree, route, open_database])
515
  with gr.Accordion("About the tree and coverage", open=False, elem_classes="atlas-disclosure"):
516
  gr.Markdown("This tree follows **NCBI Taxonomy within Eukaryota**. Animals and fungi share the Opisthokonta branch; "
 
504
  return show(taxonomy.taxon_path(taxid) if taxid else DEFAULT_PATH)
505
 
506
  def taxonomy_best(text):
507
+ """Enter moves the chart, so it ticks the row it moved to as well.
508
+
509
+ Showing a lineage while the list it came from sits unselected reads
510
+ as two answers to the same question.
511
+ """
512
  choices = taxonomy.search(text)
513
+ if not choices:
514
+ return (*taxonomy_view(None), gr.Radio(choices=[], value=None),
515
+ "No matching eukaryotic taxa in this snapshot.")
516
+ taxid = choices[0][1]
517
+ return (*taxonomy_view(taxid), gr.Radio(choices=choices, value=taxid),
518
+ f"{len(choices)} matches, closest first. Showing **{choices[0][0].split(' · ')[0]}**.")
519
 
520
  # No separate search button: the list follows what is typed, Enter takes
521
  # the closest match, and picking any row opens it.
522
  query.change(taxonomy_search, query, [matches, status], show_progress="hidden")
523
+ query.submit(taxonomy_best, query, [tree, route, open_database, matches, status])
524
  matches.input(taxonomy_view, matches, [tree, route, open_database])
525
  with gr.Accordion("About the tree and coverage", open=False, elem_classes="atlas-disclosure"):
526
  gr.Markdown("This tree follows **NCBI Taxonomy within Eukaryota**. Animals and fungi share the Opisthokonta branch; "