Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError raised when extracting barcodes from custom PB tree. #266

Open
watronfire opened this issue Jan 8, 2025 · 1 comment · May be fixed by #267
Open

KeyError raised when extracting barcodes from custom PB tree. #266

watronfire opened this issue Jan 8, 2025 · 1 comment · May be fixed by #267

Comments

@watronfire
Copy link

Hey y'all,

I'm attempting to extract lineage barcodes from a custom cholera PB tree using the following freyja command:

freyja barcode-build --pb o1_cholera.no_missing.pb --outdir freyja-barcodes/ --noncl

Here is the tree: o1_cholera.no_missing.pb.zip

However, this raises a KeyError during the separating combined splits step. See the following traceback:

Getting outbreak data
Downloading a new global tree
Converting tree info to barcodes
Reading custom tree at: o1_cholera.no_missing.pb
Building barcodes from global phylogenetic tree
separating combined splits
Traceback (most recent call last):
  File "/PHShome/nm104/mambaforge/envs/phonebook/bin/freyja", line 10, in <module>
    sys.exit(cli())
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/freyja/_cli.py", line 312, in barcode_build
    df_barcodes = convert_to_barcodes(df)
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/freyja/convert_paths2barcodes.py", line 32, in convert_to_barcodes
    df_barcodes = df_barcodes.drop(columns='')
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/pandas/core/frame.py", line 5581, in drop
    return super().drop(
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/pandas/core/generic.py", line 4788, in drop
    obj = obj._drop_axis(labels, axis, level=level, errors=errors)
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/pandas/core/generic.py", line 4830, in _drop_axis
    new_axis = axis.drop(labels, errors=errors)
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 7070, in drop
    raise KeyError(f"{labels[mask].tolist()} not found in axis")
KeyError: "[''] not found in axis"

The specific line the error is referencing is below, and I believe the issue is that Freyja assumes the barcode dataframe will contain a column with the name "".

df_barcodes = df_barcodes.drop(columns='')

However, if I put a breakpoint before this statement and debug, I find that the dataframe generated by my tree doesn't have this empty column. Additionally, if I wrap the line in a conditional (if "" in df.columns:), the error is not raised and the command runs without a issue, and I assume the barcodes are chill.

I'll make a PR with the fix now, but wanted to post this issue so its tracked, if y'all want to explore my PB (attached) or whatever.

@watronfire watronfire linked a pull request Jan 8, 2025 that will close this issue
@watronfire
Copy link
Author

My environment, if it matters:

  • python 3.9.19
  • pandas 2.2.3
  • usher 0.6.3
  • freyja 1.5.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant