reichlab / variant-nowcast-hub

A repository to store COVID-19 variant nowcasts collected as a modeling hub.
MIT License
4 stars 0 forks source link

more graceful handling of error when `"root_sequence"` key is not found in `reference_data` #6

Open elray1 opened 2 months ago

elray1 commented 2 months ago

when I run assign_clades and specify the date 2023-10-01, I get a tremendous amount of output that includes a printout of a lot of json that i think is the reference tree, followed by the text below. I believe this may be because this is an older tree that does not contain the root_sequence as part of the tree? It might be nice to save the user that output and throw a more concise error if the reference tree doesn't contain the root sequence.

elray1 commented 2 months ago

... actually, I now see there is some handling of this already, here. Here's (some of) the output I saw. Maybe we could do something like log all of this and manually raise a shorter error?

│ │                  │   │   │   │   │   │   │   },                                              │ │
│ │                  │   │   │   │   │   │   │   {                                               │ │
│ │                  │   │   │   │   │   │   │   │   'name': 'B.1.260',                          │ │
│ │                  │   │   │   │   │   │   │   │   'node_attrs': {                             │ │
│ │                  │   │   │   │   │   │   │   │   │   'div': 5,                               │ │
│ │                  │   │   │   │   │   │   │   │   │   'qc.overallScore': {'value': 0},        │ │
│ │                  │   │   │   │   │   │   │   │   │   'partiallyAliased': {                   │ │
│ │                  │   │   │   │   │   │   │   │   │   │   'value': 'B.1.260'                  │ │
│ │                  │   │   │   │   │   │   │   │   │   },                                      │ │
│ │                  │   │   │   │   │   │   │   │   │   'totalAminoacidSubstitutions': {        │ │
│ │                  │   │   │   │   │   │   │   │   │   │   'value': 2                          │ │
│ │                  │   │   │   │   │   │   │   │   │   },                                      │ │
│ │                  │   │   │   │   │   │   │   │   │   'totalFrameShifts': {'value': 0},       │ │
│ │                  │   │   │   │   │   │   │   │   │   'clade_membership': {'value': '20A'},   │ │
│ │                  │   │   │   │   │   │   │   │   │   'qc.stopCodons.totalStopCodons': {      │ │
│ │                  │   │   │   │   │   │   │   │   │   │   'value': 0                          │ │
│ │                  │   │   │   │   │   │   │   │   │   },                                      │ │
│ │                  │   │   │   │   │   │   │   │   │   'clade_display': {'value': '20A'},      │ │
│ │                  │   │   │   │   │   │   │   │   │   'Nextclade_pango': {                    │ │
│ │                  │   │   │   │   │   │   │   │   │   │   'value': 'B.1.260'                  │ │
│ │                  │   │   │   │   │   │   │   │   │   },                                      │ │
│ │                  │   │   │   │   │   │   │   │   │   'clade_nextstrain': {'value': '20A'},   │ │
│ │                  │   │   │   │   │   │   │   │   │   ... +2                                  │ │
│ │                  │   │   │   │   │   │   │   │   },                                          │ │
│ │                  │   │   │   │   │   │   │   │   'branch_attrs': {                           │ │
│ │                  │   │   │   │   │   │   │   │   │   'mutations': {'nuc': ['C26735T']}       │ │
│ │                  │   │   │   │   │   │   │   │   }                                           │ │
│ │                  │   │   │   │   │   │   │   },                                              │ │
│ │                  │   │   │   │   │   │   │   {                                               │ │
│ │                  │   │   │   │   │   │   │   │   'name': 'B.1.377',                          │ │
│ │                  │   │   │   │   │   │   │   │   'node_attrs': {                             │ │
│ │                  │   │   │   │   │   │   │   │   │   'div': 7,                               │ │
│ │                  │   │   │   │   │   │   │   │   │   'qc.overallScore': {'value': 0},        │ │
│ │                  │   │   │   │   │   │   │   │   │   'partiallyAliased': {                   │ │
│ │                  │   │   │   │   │   │   │   │   │   │   'value': 'B.1.377'                  │ │
│ │                  │   │   │   │   │   │   │   │   │   },                                      │ │
│ │                  │   │   │   │   │   │   │   │   │   'totalAminoacidSubstitutions': {        │ │
│ │                  │   │   │   │   │   │   │   │   │   │   'value': 6                          │ │
│ │                  │   │   │   │   │   │   │   │   │   },                                      │ │
│ │                  │   │   │   │   │   │   │   │   │   'totalFrameShifts': {'value': 0},       │ │
│ │                  │   │   │   │   │   │   │   │   │   'clade_membership': {'value': '20A'},   │ │
│ │                  │   │   │   │   │   │   │   │   │   'qc.stopCodons.totalStopCodons': {      │ │
│ │                  │   │   │   │   │   │   │   │   │   │   'value': 0                          │ │
│ │                  │   │   │   │   │   │   │   │   │   },                                      │ │
│ │                  │   │   │   │   │   │   │   │   │   'clade_display': {'value': '20A'},      │ │
│ │                  │   │   │   │   │   │   │   │   │   'Nextclade_pango': {                    │ │
│ │                  │   │   │   │   │   │   │   │   │   │   'value': 'B.1.377'                  │ │
│ │                  │   │   │   │   │   │   │   │   │   },                                      │ │
│ │                  │   │   │   │   │   │   │   │   │   'clade_nextstrain': {'value': '20A'},   │ │
│ │                  │   │   │   │   │   │   │   │   │   ... +2                                  │ │
│ │                  │   │   │   │   │   │   │   │   },                                          │ │
│ │                  │   │   │   │   │   │   │   │   'branch_attrs': {                           │ │
│ │                  │   │   │   │   │   │   │   │   │   'mutations': {                          │ │
│ │                  │   │   │   │   │   │   │   │   │   │   'nuc': [                            │ │
│ │                  │   │   │   │   │   │   │   │   │   │   │   'G28300T',                      │ │
│ │                  │   │   │   │   │   │   │   │   │   │   │   'G28883A',                      │ │
│ │                  │   │   │   │   │   │   │   │   │   │   │   'A28998G'                       │ │
│ │                  │   │   │   │   │   │   │   │   │   │   ],                                  │ │
│ │                  │   │   │   │   │   │   │   │   │   │   'N': ['Q9H', 'G204R', 'Q242R'],     │ │
│ │                  │   │   │   │   │   │   │   │   │   │   'ORF9b': ['S6I']                    │ │
│ │                  │   │   │   │   │   │   │   │   │   },                                      │ │
│ │                  │   │   │   │   │   │   │   │   │   'labels': {                             │ │
│ │                  │   │   │   │   │   │   │   │   │   │   'aa': 'N: Q9H, G204R, Q242R; ORF9b: │ │
│ │                  S6I'                                                                        │ │
│ │                  │   │   │   │   │   │   │   │   │   }                                       │ │
│ │                  │   │   │   │   │   │   │   │   }                                           │ │
│ │                  │   │   │   │   │   │   │   },                                              │ │
│ │                  │   │   │   │   │   │   │   ... +30                                         │ │
│ │                  │   │   │   │   │   │   ]                                                   │ │
│ │                  │   │   │   │   │   }                                                       │ │
│ │                  │   │   │   │   ]                                                           │ │
│ │                  │   │   │   }                                                               │ │
│ │                  │   │   ]                                                                   │ │
│ │                  │   }                                                                       │ │
│ │                  }                                                                           │ │
│ │       response = <Response [200]>                                                            │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
KeyError: 'root_sequence'

Traceback (most recent call last):
  File "/Users/elray/research/epi/covid/variant-modeling/variant-nowcast-hub/data-pipeline/.venv/bin/assign_clades", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/elray/research/epi/covid/variant-modeling/variant-nowcast-hub/data-pipeline/.venv/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/elray/research/epi/covid/variant-modeling/variant-nowcast-hub/data-pipeline/.venv/lib/python3.11/site-packages/rich_click/rich_command.py", line 152, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/elray/research/epi/covid/variant-modeling/variant-nowcast-hub/data-pipeline/.venv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/elray/research/epi/covid/variant-modeling/variant-nowcast-hub/data-pipeline/.venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/elray/research/epi/covid/variant-modeling/variant-nowcast-hub/data-pipeline/src/covid_variant_pipeline/assign_clades.py", line 136, in main
    reference_tree_path, root_sequence_path = save_reference_info(as_of_date)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/elray/research/epi/covid/variant-modeling/variant-nowcast-hub/data-pipeline/src/covid_variant_pipeline/assign_clades.py", line 80, in save_reference_info
    reference = get_reference_data(NEXTCLADE_BASE_URL, as_of_date)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/elray/research/epi/covid/variant-modeling/variant-nowcast-hub/data-pipeline/src/covid_variant_pipeline/util/reference.py", line 47, in get_reference_data
    raise e
  File "/Users/elray/research/epi/covid/variant-modeling/variant-nowcast-hub/data-pipeline/src/covid_variant_pipeline/util/reference.py", line 41, in get_reference_data
    reference["root_sequence"] = reference_data["root_sequence"]
                                 ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
KeyError: 'root_sequence'