nextstrain / augur

Pipeline components for real-time phylodynamic analysis
https://docs.nextstrain.org/projects/augur/
GNU Affero General Public License v3.0
268 stars 128 forks source link

Refine throws: `ERROR: 'NoneType' object has no attribute 'shape'` #1062

Open corneliusroemer opened 1 year ago

corneliusroemer commented 1 year ago

Current Behavior

Augur refine throws ERROR: 'NoneType' object has no attribute 'shape' when running the monkeypox build

Expected behavior

A more useful error is thrown if there's a data problem, or no error is thrown if this is a bug

How to reproduce

wget https://github.com/nextstrain/augur/files/9794437/augur-1062.tar.zst.txt
tar xf augur-1062.tar.zst.txt
augur refine             --tree results/hmpxv1/tree_fixed.nwk    \
     --alignment results/hmpxv1/masked.fasta    --metadata results/hmpxv1/metadata.tsv   \
   --output-tree results/hmpxv1/tree.nwk        --timetree        --root MK783032 MK783030  \
   --precision 3       --keep-polytomies       --clock-rate 5.7e-05   --clock-std-dev 2e-5    \
   --output-node-data results/hmpxv1/branch_lengths.json    --coalescent opt        \
     --date-inference marginal      --date-confidence       --clock-filter-iqd 0

Full log:

        augur refine             --tree results/hmpxv1/tree_fixed.nwk             --alignment results/hmpxv1/masked.fasta             --metadata results/hmpxv1/metadata.tsv             --output-tree results/hmpxv1/tree.nwk             --timetree             --root MK783032 MK783030             --precision 3             --keep-polytomies             --clock-rate 5.7e-05             --clock-std-dev 2e-5             --output-node-data results/hmpxv1/branch_lengths.json             --coalescent opt             --date-inference marginal             --date-confidence             --clock-filter-iqd 0

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/treetime/treetime.py", line 57, in run
    return self._run(**kwargs)
  File "/usr/local/lib/python3.7/site-packages/treetime/treetime.py", line 212, in _run
    max_iter=1, method_anc = method_anc, **seq_kwargs)
  File "/usr/local/lib/python3.7/site-packages/treetime/treeanc.py", line 1358, in optimize_tree
    self.optimize_branch_lengths_joint(verbose=0, store_old=False, mode=branch_length_mode)
  File "/usr/local/lib/python3.7/site-packages/treetime/treeanc.py", line 1162, in optimize_branch_lengths_joint
    new_len = max(0,self.optimal_branch_length(node))
  File "/usr/local/lib/python3.7/site-packages/treetime/treeanc.py", line 1203, in optimal_branch_length
    self.add_branch_state(node)
  File "/usr/local/lib/python3.7/site-packages/treetime/treeanc.py", line 1110, in add_branch_state
    ignore_gaps = self.ignore_gaps)
  File "/usr/local/lib/python3.7/site-packages/treetime/gtr.py", line 605, in state_pair
    if seq_ch.shape != seq_p.shape:
augur refine is using TreeTime version 0.9.4
AttributeError: 'NoneType' object has no attribute 'shape'
87.49       ***WARNING: TreeAnc._check_alignment_tree_gtr_consistency: NO SEQUENCE FOR
            LEAF: 'None'
ERROR: 'NoneType' object has no attribute 'shape' 

87.50       ***WARNING: TreeAnc: 1 nodes don't have a matching sequence in the
ERROR in TreeTime.run: An error occurred which was not properly handled in TreeTime. If this error persists, please let us know by filing a new issue including the original command and the error above at: https://github.com/neherlab/treetime/issues 
            alignment. POSSIBLE ERROR.
ERROR from TreeTime: An error occurred in TreeTime (see above). This may be due to an issue with TreeTime or Augur.
96.90       WARNING: Previous versions of TreeTime (<0.7.0) RECONSTRUCTED sequences of
Please report you are calling TreeTime via Augur. 
            tips at positions with AMBIGUOUS bases. This resulted in unexpected
            behavior is some cases and is no longer done by default. If you want to
            replace those ambiguous sites with their most likely state, rerun with
            `reconstruct_tip_states=True` or `--reconstruct-tip-states`.

@anna-parker

anna-parker commented 1 year ago

Thanks for flagging this! It seems to be a general bug that if a node sequence is not in the alignment treetime will print a warning and then crash instead of throwing an exception.

jameshadfield commented 1 year ago

I ran into this error today (I think?) using augur version 17.1.0 (TreeTime version 0.9.2).

In my case, the input tree (created using augur tree) had changed taxa names from (e.g.) Coted'Ivoire/IPCI-DVE-GR1822/2022 to Coted_Ivoire/IPCI-DVE-GR1642/2022, thus falling out of sync with the metadata & alignnment. A more helpful error message would be great here 🙏

Full error in my case:

27.09   ***WARNING: TreeAnc._check_alignment_tree_gtr_consistency: NO SEQUENCE FOR
        LEAF: 'Coted_Ivoire/IPCI-DVE-GR1822/2022'

27.11   ***WARNING: TreeAnc._check_alignment_tree_gtr_consistency: NO SEQUENCE FOR
        LEAF: 'Coted_Ivoire/IPCI-DVE-GR1901/2022'

27.14   ***WARNING: TreeAnc._check_alignment_tree_gtr_consistency: NO SEQUENCE FOR
        LEAF: 'Coted_Ivoire/IPCI-DVE-GR1642/2022'

27.17   ***WARNING: TreeAnc._check_alignment_tree_gtr_consistency: NO SEQUENCE FOR
        LEAF: 'Coted_Ivoire/IPCI-DVE-GR2193/2022'

27.21   ***WARNING: TreeAnc: 4 nodes don't have a matching sequence in the
        alignment. POSSIBLE ERROR.

29.88   WARNING: Previous versions of TreeTime (<0.7.0) RECONSTRUCTED sequences of
        tips at positions with AMBIGUOUS bases. This resulted in unexpected
        behavior is some cases and is no longer done by default. If you want to
        replace those ambiguous sites with their most likely state, rerun with
        `reconstruct_tip_states=True` or `--reconstruct-tip-states`.
ERROR: Was unable to refine time trees:

'NoneType' object has no attribute 'shape'
anna-parker commented 1 year ago

Hi, @jameshadfield - so I think this error should be solved by the merged PR above: https://github.com/neherlab/treetime/pull/213 - in the augur and TreeTime master, or TreeTime version 0.9.4. But would be great to know which data you used and the full command in augur refine so I can check for sure :-)