TreeTime Error: AttributeError: 'NoneType' object has no attribute 'shape'

Hi everybody,

I’ve run Nextstrain several times before and never had problems with TreeTime. Unfortunately, the error message I got now was not informative enough for me, so I couldn’t solve it by myself.

augur refine is using TreeTime version 0.8.4

4908.08 ***WARNING: TreeAnc._attach_sequences_to_nodes: NO SEQUENCE FOR LEAF:
        an/5053/2021

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

5375.97 TreeTime.reroot: with method or node: Wuhan/Hu-1/2019

6129.60 TreeTime.reroot: with method or node: Wuhan/Hu-1/2019
pruning leaf  Germany/BY-RKI-I-040963/2021
pruning leaf  Poland/2764WSN2021_wsseol/2021
...
pruning leaf  Belarus/HM-CRIE-7724096095/2021
pruning leaf  Poland/38c61S84/2022

7208.78 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`.
Traceback (most recent call last):
  File "/scratch/ws/1/dmse952c-p_cov2muta/ncov/bin/augur", line 10, in <module>
    sys.exit(main())
  File "/scratch/ws/1/dmse952c-p_cov2muta/ncov/lib/python3.9/site-packages/augur/__main__.py", line 10, in main
    return augur.run( argv[1:] )
  File "/scratch/ws/1/dmse952c-p_cov2muta/ncov/lib/python3.9/site-packages/augur/__init__.py", line 75, in run
    return args.__command__.run(args)
  File "/scratch/ws/1/dmse952c-p_cov2muta/ncov/lib/python3.9/site-packages/augur/refine.py", line 206, in run
    tt = refine(tree=T, aln=aln, ref=ref, dates=dates, confidence=args.date_confidence,
  File "/scratch/ws/1/dmse952c-p_cov2muta/ncov/lib/python3.9/site-packages/augur/refine.py", line 67, in refine
    tt.run(infer_gtr=infer_gtr, root=reroot, Tc=Tc, time_marginal=marginal,
  File "/scratch/ws/1/dmse952c-p_cov2muta/ncov/lib/python3.9/site-packages/treetime/treetime.py", line 155, in run
    self.optimize_tree(infer_gtr=infer_gtr,
  File "/scratch/ws/1/dmse952c-p_cov2muta/ncov/lib/python3.9/site-packages/treetime/treeanc.py", line 1305, in optimize_tree
    self.optimize_branch_len(verbose=0, store_old=False, mode=branch_length_mode)
  File "/scratch/ws/1/dmse952c-p_cov2muta/ncov/lib/python3.9/site-packages/treetime/treeanc.py", line 1074, in optimize_branch_len
    return self.optimize_branch_lengths_joint(**kwargs)
  File "/scratch/ws/1/dmse952c-p_cov2muta/ncov/lib/python3.9/site-packages/treetime/treeanc.py", line 1117, in optimize_branch_lengths_joint
    new_len = max(0,self.optimal_branch_length(node))
  File "/scratch/ws/1/dmse952c-p_cov2muta/ncov/lib/python3.9/site-packages/treetime/treeanc.py", line 1158, in optimal_branch_length
    self.add_branch_state(node)
  File "/scratch/ws/1/dmse952c-p_cov2muta/ncov/lib/python3.9/site-packages/treetime/treeanc.py", line 1062, in add_branch_state
    seq_pairs, multiplicity = self.gtr.state_pair(
  File "/scratch/ws/1/dmse952c-p_cov2muta/ncov/lib/python3.9/site-packages/treetime/gtr.py", line 606, in state_pair
    if seq_ch.shape != seq_p.shape:
AttributeError: 'NoneType' object has no attribute 'shape'

Thank you in advance!

Best wishes,
Dmitrii

Thanks for reporting. Would you be able to share the input files for this augur refine run so I can try to reproduce?

You’re right, the error message is not very informative. It’s something I can try to improve once we figure out what caused the problem.

It could be a bug in tree time or something up with your input sequences, something that should be caught at validation or somehow reported to the user as an actionable insight.

Could the problem be down to this sequence an/5053/2021?

See the warning you got:

4908.08 ***WARNING: TreeAnc._attach_sequences_to_nodes: NO SEQUENCE FOR LEAF:
        an/5053/2021

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

@corneliusroemer, thank you!

I missed this line. I’ve checked the aligned.fasta (the one that is used as input for the TreeTime) and found this sequence: >Lu’an/5053/2021.

Apparently, the character ’ confuses TreeTime algorithm, so it takes only the second part of the name.

I will try to rename this sequence in all input files and then will start the refine step again.

Best,
Dmitrii