Songbird error: local variable 'i' referenced before assignment

Dear community,

I came up with a difficult error when performing q2-songbird suggested pipeline. Need to say that I previously ran exactly the same command (but using another feature table) and it was executed successfully.

I also saw that could be a metadata related error (longitudinal pairwise difference error), but after checking carefully my metadata I discarded this option. Moreover, I had no problems running alfa and beta diversity metrics.

The command (from a genus-level collapsed table):

qiime songbird multinomial
--i-table ancom-24/table-patology-l6.qza
--m-metadata-file metadata-24.tsv
--p-formula "type"
--p-epochs 1000000
--p-differential-prior 0.1
--p-summary-interval 1
--p-learning-rate 0.0001
--p-batch-size 8
--o-differentials songbird/24/differentials-l6.qza
--o-regression-stats songbird/24/regression-stats-l6.qza
--o-regression-biplot songbird/24/regression-biplot-l6.qza

The error:

Traceback (most recent call last):
File "/home/pau/miniconda3/envs/qiime2-2020.6/lib/python3.6/site-packages/q2cli/", line 329, in call
results = action(**arguments)
File "", line 2, in multinomial
File "/home/pau/miniconda3/envs/qiime2-2020.6/lib/python3.6/site-packages/qiime2/sdk/", line 245, in bound_callable
output_types, provenance)
File "/home/pau/miniconda3/envs/qiime2-2020.6/lib/python3.6/site-packages/qiime2/sdk/", line 390, in callable_executor
output_views = self._callable(**view_args)
File "/home/pau/miniconda3/envs/qiime2-2020.6/lib/python3.6/site-packages/songbird/q2/", line 69, in multinomial
File "/home/pau/miniconda3/envs/qiime2-2020.6/lib/python3.6/site-packages/songbird/", line 213, in fit
UnboundLocalError: local variable 'i' referenced before assignment

Plugin error from songbird:

local variable 'i' referenced before assignment

See above for debug info.

Thanks a lot in advance :slight_smile:

It looks like i goes from 0 to

(self.N // self.batch_size) * epochs

You did not set epochs to zero so it is probably self.N that is zero, which is

self.N, self.p = trainX.shape

as in N is the number of training samples, so I would specify which samples should be train vs test, and make sure that table actually contains them and they were not filtered out unexpectedly.


Hi @dwt ! Thanks for your response, it was very helpfull!
I specified a train-test column in my metadata and worked! However, I have two more questions regarding this topic:

  • I am analyzing with songbird different groups of samples from my total samples. Why do some groups require to specify a train/test column while the analysis works well in others without specifying this column? (groups have more or less the same number of samples and samples are evenly distribuited regarding the analized field).

  • For the groups that the analysis works with both training column specified and not, results are different (Qsquared, etc). Which model should be taken as better formula? Qsquared values (when compared to null model) are generally higher when training column is not specified; while when specifying this column Qsqared values are very low or negative.

Thanks a lot for your time!!

My understanding is that the q squared is only meaningful when the training column is specified, otherwise the null model and the primary model may be trained on different samples.
As far as I know you should always prefer the models with the training columns specified, because you can measure their quality.

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.