anvio icon indicating copy to clipboard operation
anvio copied to clipboard

[BUG] Pandas error in `anvi-get-codon-frequencies`

Open philipwoods opened this issue 1 year ago • 6 comments

Short description of the problem

When running anvi-get-codon-frequencies, there is a TypeError in how pandas is used in _make_gene_codon_frequency_table.

anvi'o version

Anvi'o .......................................: marie (v8)
Python .......................................: 3.10.13

Profile database .............................: 38
Contigs database .............................: 21
Pan database .................................: 16
Genome data storage ..........................: 7
Auxiliary data storage .......................: 2
Structure database ...........................: 2
Metabolic modules database ...................: 4
tRNA-seq database ............................: 2

System info

The operating system is Red Hat enterprise Linux. Anvi'o was installed in a conda environment.

Detailed description of the issue

When running anvi-get-codon-frequencies I get the following error:

Traceback (most recent call last):
  File "/export/data1/sw/anaconda3-2019.07/envs/anvio-8/bin/anvi-get-codon-frequencies", line 420, in <module>
    main(args)
  File "/export/data1/sw/anaconda3-2019.07/envs/anvio-8/bin/anvi-get-codon-frequencies", line 115, in main
    frequency_df = multigenome_codon_usage.get_frequencies(
  File "/export/data1/sw/anaconda3-2019.07/envs/anvio-8/lib/python3.10/site-packages/anvio/codonusage.py", line 2265, in get_frequencies
    frequency_df = next(frequency_table_generator)
  File "/export/data1/sw/anaconda3-2019.07/envs/anvio-8/lib/python3.10/site-packages/anvio/codonusage.py", line 2281, in _get_genome_frequency_table
    genome_codon_usage = SingleGenomeCodonUsage(
  File "/export/data1/sw/anaconda3-2019.07/envs/anvio-8/lib/python3.10/site-packages/anvio/codonusage.py", line 89, in __init__
    self._make_gene_codon_frequency_table()
  File "/export/data1/sw/anaconda3-2019.07/envs/anvio-8/lib/python3.10/site-packages/anvio/codonusage.py", line 231, in _make_gene_codon_frequency_table
    gene_codon_frequency_df = gene_codon_frequency_df[constants.codon_to_AA]
  File "/export/data1/sw/anaconda3-2019.07/envs/anvio-8/lib/python3.10/site-packages/pandas/core/frame.py", line 4051, in __getitem__
    check_dict_or_set_indexers(key)
  File "/export/data1/sw/anaconda3-2019.07/envs/anvio-8/lib/python3.10/site-packages/pandas/core/indexing.py", line 2783, in check_dict_or_set_indexers
    raise TypeError(
TypeError: Passing a dict as an indexer is not supported. Use a list instead.

philipwoods avatar Jul 27 '24 18:07 philipwoods

I see a lot of pandas errors reported lately. I wonder if there was an update recently that causes all these incompatibility issues.

Note for self: we should always finalize requirements.txt with explicit version numbers prior to release :(

meren avatar Jul 28 '24 06:07 meren

Fwiw, I'm running 2 recent installations of anvio-dev in Ubuntu and Rocky Linux, both with pandas=1.4.4 and I haven't had any issues. (I even ran anvi-get-codon-frequencies in case it was a program-specific issue; no errors either).

I see a pretty old anaconda install, from when the flexible solve for environment deps was the default - less painful, but more prone to environments not being properly set.

xvazquezc avatar Jul 29 '24 01:07 xvazquezc

For what it's worth, I can verify that pandas 1.4.4 is installed in the environment:

(anvio-8) [pwoods@ocean revision]$ conda list | grep pandas
pandas                    1.4.4                    pypi_0    pypi

philipwoods avatar Jul 29 '24 22:07 philipwoods

This is very interesting. @philipwoods, would you consider sharing your contigs-db file and the exact command you're running on it to get this error? Maybe we can try to reproduce it on our end and see if we can solve it.

meren avatar Jul 29 '24 22:07 meren

I get the error while running anvi-get-codon-frequencies -c ANME-2a_sp._Agg-19359.db -o test.txt with the attached contigs database. ANME-2a_sp._Agg-19359.zip

philipwoods avatar Jul 30 '24 05:07 philipwoods

I just finished installing an anvio-dev environment and the command above ran with no issue, which is confusing but possibly also useful debugging information.

philipwoods avatar Jul 30 '24 18:07 philipwoods