biocore / songbird

Vanilla regression methods for microbiome differential abundance analysis
BSD 3-Clause "New" or "Revised" License
54 stars 25 forks source link

Error message: UnboundLocalError: local variable 'i' referenced before assignment #161

Closed pig-raffles closed 1 year ago

pig-raffles commented 2 years ago

Hi,

I get the error message "UnboundLocalError: local variable 'i' referenced before assignment", when I run this command:

songbird multinomial \ --input-biom input.biom \ --metadata-file Metadata.txt \ --formula "Treatment" \ --epochs 10000 \ --min-sample-count 0 \ --min-feature-count 0 \ --differential-prior 0.5 \ --summary-interval 1 \ --summary-dir results

Do you have any idea what this means and how I can prevent it? I have checked my biom format ("biom summarize-table") and it displays the correct number of samples/observations

Thanks,

Alan

pig-raffles commented 2 years ago

Just to add more detail, the problem seems to occur here:

"...anaconda3/envs/songbird_env/lib/python3.7/site-packages/songbird/multinomial.py", line 213, in fit iter_n.append(i) UnboundLocalError: local variable 'i' referenced before assignment

mortonjt commented 2 years ago

Can you give the full traceback?

This error is basically saying that num_iter < 0, which only happens if your batch size is larger than the total number of samples. How large is your biom table? Does your biom table have samples with a sequencing depth less than 1000 (the default for min-sample-count?

You can also try tweaking --batch-size? (i.e. set --batch-size to 1), if your biom table does have less than 5 samples total.

pig-raffles commented 2 years ago

My sample size is pretty small (8 samples, comprising two experimental groups of 4 individuals that I want to compare). If you look at the biom summarize-table output below, none of the samples have min-sample-counts less than 1000.

Looking at --batch-size the default value is 5. For my data set should I set that to 4 to match my dataset structure?

Also below is the full traceback for the issue reported in my previous message.

Thanks!

$ biom summarize-table -i input.biom.biom Num samples: 8 Num observations: 5,762 Total count: 68,471,133 Table density (fraction of non-zero values): 0.723

Counts/sample summary: Min: 1,456,270.000 Max: 19,266,108.000 Median: 6,585,525.500 Mean: 8,558,891.625 Std. dev.: 6,766,641.388 Sample Metadata Categories: None provided Observation Metadata Categories: None provided Here is the full traceback:

$ songbird multinomial \ --input-biom input.biom \ --metadata-file Metadata.txt \ --formula "Treatment" \ --epochs 10000 \ --min-sample-count 0 \ --min-feature-count 0 \ --differential-prior 0.5 \ --summary-interval 10 \ --summary-dir results WARNING:tensorflow:From .../anaconda3/envs/songbird_env/bin/songbird:191: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

2022-04-28 14:05:04.226137: I tensorflow/core/platform/cpu_feature_guard.cc:145] This TensorFlow binary is optimized with Intel(R) MKL-DNN to use the following CPU instructions in performance critical operations: SSE4.1 SSE4.2 To enable them in non-MKL-DNN operations, rebuild TensorFlow with the appropriate compiler flags. 2022-04-28 14:05:04.226813: I tensorflow/core/common_runtime/process_util.cc:115] Creating new thread pool with default inter op setting: 8. Tune using inter_op_parallelism_threads for best performance. WARNING:tensorflow:From .../anaconda3/envs/songbird_env/bin/songbird:194: The name tf.set_random_seed is deprecated. Please use tf.compat.v1.set_random_seed instead.

WARNING:tensorflow:From .../anaconda3/envs/songbird_env/lib/python3.7/site-packages/songbird/multinomial.py:70: multinomial (from tensorflow.python.ops.random_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.random.categorical instead. WARNING:tensorflow:From .../anaconda3/envs/songbird_env/lib/python3.7/site-packages/songbird/multinomial.py:81: The name tf.random_normal is deprecated. Please use tf.random.normal instead.

WARNING:tensorflow:From .../anaconda3/envs/songbird_env/lib/python3.7/site-packages/songbird/multinomial.py:86: Normal.init (from tensorflow.python.ops.distributions.normal) is deprecated and will be removed after 2019-01-01. Instructions for updating: The TensorFlow Distributions library has moved to TensorFlow Probability (https://github.com/tensorflow/probability). You should update all references to use tfp.distributions instead of tf.distributions. WARNING:tensorflow:From .../anaconda3/envs/songbird_env/lib/python3.7/site-packages/tensorflow_core/python/ops/distributions/normal.py:160: Distribution.init (from tensorflow.python.ops.distributions.distribution) is deprecated and will be removed after 2019-01-01. Instructions for updating: The TensorFlow Distributions library has moved to TensorFlow Probability (https://github.com/tensorflow/probability). You should update all references to use tfp.distributions instead of tf.distributions. WARNING:tensorflow:From .../anaconda3/envs/songbird_env/lib/python3.7/site-packages/songbird/multinomial.py:95: Multinomial.init (from tensorflow.python.ops.distributions.multinomial) is deprecated and will be removed after 2019-01-01. Instructions for updating: The TensorFlow Distributions library has moved to TensorFlow Probability (https://github.com/tensorflow/probability). You should update all references to use tfp.distributions instead of tf.distributions. WARNING:tensorflow:From .../anaconda3/envs/songbird_env/lib/python3.7/site-packages/songbird/multinomial.py:110: The name tf.summary.scalar is deprecated. Please use tf.compat.v1.summary.scalar instead.

WARNING:tensorflow:From .../anaconda3/envs/songbird_env/lib/python3.7/site-packages/songbird/multinomial.py:116: The name tf.train.AdamOptimizer is deprecated. Please use tf.compat.v1.train.AdamOptimizer instead.

WARNING:tensorflow:From .../anaconda3/envs/songbird_env/lib/python3.7/site-packages/tensorflow_core/python/ops/clip_ops.py:301: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.where in 2.0, which has the same broadcast rule as np.where WARNING:tensorflow:From .../anaconda3/envs/songbird_env/lib/python3.7/site-packages/songbird/multinomial.py:124: The name tf.summary.histogram is deprecated. Please use tf.compat.v1.summary.histogram instead.

WARNING:tensorflow:From .../anaconda3/envs/songbird_env/lib/python3.7/site-packages/songbird/multinomial.py:125: The name tf.summary.merge_all is deprecated. Please use tf.compat.v1.summary.merge_all instead.

WARNING:tensorflow:From .../anaconda3/envs/songbird_env/lib/python3.7/site-packages/songbird/multinomial.py:127: The name tf.summary.FileWriter is deprecated. Please use tf.compat.v1.summary.FileWriter instead.

WARNING:tensorflow:From .../anaconda3/envs/songbird_env/lib/python3.7/site-packages/songbird/multinomial.py:131: The name tf.global_variables_initializer is deprecated. Please use tf.compat.v1.global_variables_initializer instead.

WARNING:tensorflow:From .../anaconda3/envs/songbird_env/lib/python3.7/site-packages/songbird/multinomial.py:163: The name tf.train.Saver is deprecated. Please use tf.compat.v1.train.Saver instead.

0it [00:00, ?it/s] Traceback (most recent call last): File "...anaconda3/envs/songbird_env/bin/songbird", line 225, in songbird() File "...anaconda3/envs/songbird_env/lib/python3.7/site-packages/click/core.py", line 1128, in call return self.main(args, kwargs) File "/Users/alan02/opt/anaconda3/envs/songbird_env/lib/python3.7/site-packages/click/core.py", line 1053, in main rv = self.invoke(ctx) File "...anaconda3/envs/songbird_env/lib/python3.7/site-packages/click/core.py", line 1659, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "...anaconda3/envs/songbird_env/lib/python3.7/site-packages/click/core.py", line 1395, in invoke return ctx.invoke(self.callback, ctx.params) File "...anaconda3/envs/songbird_env/lib/python3.7/site-packages/click/core.py", line 754, in invoke return __callback(args, **kwargs) File "...anaconda3/envs/songbird_env/bin/songbird", line 202, in multinomial silent=silent, File "...anaconda3/envs/songbird_env/lib/python3.7/site-packages/songbird/multinomial.py", line 213, in fit iter_n.append(i) UnboundLocalError: local variable 'i' referenced before assignment

mortonjt commented 1 year ago

Hi, has this error been resolved? You may need to squeeze the batch size down to one if it is still not working

mortonjt commented 1 year ago

I'm assuming that this has been resolved, thus closing.

See here for similar issues : https://forum.qiime2.org/t/songbird-error-local-variable-i-referenced-before-assignment/20175