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

Object of type int64 is not JSON serializable #1060

Closed
eshedroff opened this issue Oct 12, 2022 · 3 comments · Fixed by #1119
Closed

Object of type int64 is not JSON serializable #1060

eshedroff opened this issue Oct 12, 2022 · 3 comments · Fixed by #1119
Assignees
Labels
bug Something isn't working

Comments

@eshedroff
Copy link

eshedroff commented Oct 12, 2022

Current Behavior

Pathogen workflow throwing the following error when building the time-resolved tree: Object of type int64 is not JSON serializable

Expected behavior

Smooth run to generate time-resolved tree (and subsequently annotate and export)

How to reproduce

Steps to reproduce the current behavior:

  1. Run the following code in Biolinux given the attached files:
###This script repurposes the NextStrain Zika tutorial script to generate an EBOV .json file

#conda activate nextstrain

#$ -cwd
#Use current working directory
#create folder for nextstrain

mkdir -p results/

# If you used Docker run the following line:
#nextstrain shell .

# Index the sequences
augur index \
--sequences data/EBOV_Sudan_others_seq_OLD_only2.fasta \
--output results/sequences_index.tsv

# Filter the sequences
augur filter \
--sequences data/EBOV_Sudan_others_seq_OLD_only2.fasta \
--sequence-index results/sequences_index.tsv \
--metadata data/EBOV_metadata.txt \
--exclude config/dropped_strains.txt \
--output results/filtered.fasta #\
#--group-by country year \
--sequences-per-group 20 \
--min-date 1976

#Align the sequences
augur align \
--sequences results/filtered.fasta \
--reference-sequence config/AF272001_ebov_outgroup.gb \
--output results/aligned.fasta \
--fill-gaps

# Construct phylogenetic tree
augur tree \
--alignment results/aligned.fasta \
--output results/tree_raw.nwk

# Time-resolved tree
augur refine \
--tree results/tree_raw.nwk \
--alignment results/aligned.fasta \
--metadata data/EBOV_metadata.txt \
--output-tree results/tree.nwk \
--output-node-data results/branch.lengths.json \
--timetree \
--coalescent opt \
--date-confidence \
--date-inference marginal
  1. View error:
Traceback (most recent call last):
  File "/scicomp/home-pure/ubu2/miniconda3/envs/nextstrain/lib/python3.10/site-packages/augur/__init__.py", line 66, in run
    return args.__command__.run(args)
  File "/scicomp/home-pure/ubu2/miniconda3/envs/nextstrain/lib/python3.10/site-packages/augur/refine.py", line 316, in run
    write_json(node_data, node_data_fname)
  File "/scicomp/home-pure/ubu2/miniconda3/envs/nextstrain/lib/python3.10/site-packages/augur/utils.py", line 127, in write_json
    json.dump(data, handle, indent=indent, sort_keys=sort_keys)
  File "/scicomp/home-pure/ubu2/miniconda3/envs/nextstrain/lib/python3.10/json/__init__.py", line 179, in dump
    for chunk in iterable:
  File "/scicomp/home-pure/ubu2/miniconda3/envs/nextstrain/lib/python3.10/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/scicomp/home-pure/ubu2/miniconda3/envs/nextstrain/lib/python3.10/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/scicomp/home-pure/ubu2/miniconda3/envs/nextstrain/lib/python3.10/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/scicomp/home-pure/ubu2/miniconda3/envs/nextstrain/lib/python3.10/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/scicomp/home-pure/ubu2/miniconda3/envs/nextstrain/lib/python3.10/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/scicomp/home-pure/ubu2/miniconda3/envs/nextstrain/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type int64 is not JSON serializable

Possible solution

numpy int should be converted to a Python integer before converting to JSON string

Your environment: if browsing Nextstrain online

  • Operating system: Biolinux
  • Browser: Microsoft Edge

Additional context

Files to reproduce errors attached:
EBOV_test.zip

@eshedroff eshedroff added the bug Something isn't working label Oct 12, 2022
@tsibley tsibley changed the title not JSON serializable Object of type int64 is not JSON serializable Oct 13, 2022
@victorlin victorlin self-assigned this Nov 2, 2022
@victorlin victorlin moved this from New to Prioritized in Nextstrain planning (archived) Nov 2, 2022
@fabio-marcelo
Copy link

Hi everyone!
I've had the exactly same. Sorry my basic knowledge, but I can't figure out the possible solution "numpy int should be converted to a Python integer before converting to JSON string". Can anyone help me to solve the problem, please?

@victorlin
Copy link
Member

@eshedroff @fabio-marcelo sorry about this bug, thanks for reporting! The fix in the PR above should be available once it is merged and released in a new Augur version (hopefully sometime next week). If you want to use it immediately, you can do so by installing Augur manually from that PR's branch, or use Nextstrain's Docker runtime with this preview image: nextstrain/base:branch-victorlin-preview-augur-numpy-json-encoder.

@victorlin victorlin moved this from Prioritized to In Review in Nextstrain planning (archived) Jan 3, 2023
@github-project-automation github-project-automation bot moved this from In Review to Done in Nextstrain planning (archived) Jan 5, 2023
@fabio-marcelo
Copy link

Dear @victorlin thank you for the guidance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

3 participants