Plugin error: qiime diversity adonis

When I ran the command below, I got an error message (displayed by verbose). However, this command was okay last month.
From the message below, the error is related to the installed R version???
May you please help me to understand the problem and how to figure it out?

qiime diversity adonis \--i-distance-matrix unwe
ighted_unifrac_distance_matrix.qza \--m-metadata-file metadataq.tsv \--o-visualization unweighted-adonis-year-treat.qzv \--p-formula Year+PathogenTreatment \--verbose

Running external command line application. This may print messages to stdout and/or stderr.
The command being run is below. This command cannot be manually re-run as it will depend on temporary files that no longer exist.

Command: run_adonis.R /tmp/tmpe0l6z4ju/dm.tsv /tmp/tmpe0l6z4ju/md.tsv Year+PathogenTreatment 999 1 /tmp/qiime2-temp-nz9dap_i/adonis.tsv

R version 3.5.1 (2018-07-02) 
Loading required package: permute
Loading required package: lattice
This is vegan 2.5-6
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
  contrasts can be applied only to factors with 2 or more levels
Calls: adonis ... model.matrix -> model.matrix.default -> contrasts<-
Execution halted
Traceback (most recent call last):
  File "/home/eman/anaconda3/envs/qiime2-2019.10/lib/python3.6/site-packages/q2cli/", line 328, in __call__
    results = action(**arguments)
  File "</home/eman/anaconda3/envs/qiime2-2019.10/lib/python3.6/site-packages/>", line 2, in adonis
  File "/home/eman/anaconda3/envs/qiime2-2019.10/lib/python3.6/site-packages/qiime2/sdk/", line 240, in bound_callable
    output_types, provenance)
  File "/home/eman/anaconda3/envs/qiime2-2019.10/lib/python3.6/site-packages/qiime2/sdk/", line 445, in _callable_executor_
    ret_val = self._callable(output_dir=temp_dir, **view_args)
  File "/home/eman/anaconda3/envs/qiime2-2019.10/lib/python3.6/site-packages/q2_diversity/_beta/", line 375, in adonis
  File "/home/eman/anaconda3/envs/qiime2-2019.10/lib/python3.6/site-packages/q2_diversity/_beta/", line 401, in _run_command, check=True)
  File "/home/eman/anaconda3/envs/qiime2-2019.10/lib/python3.6/", line 418, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['run_adonis.R', '/tmp/tmpe0l6z4ju/dm.tsv', '/tmp/tmpe0l6z4ju/md.tsv', 'Year+PathogenTreatment', '999', '1', '/tmp/qiime2-temp-nz9dap_i/adonis.tsv']' returned non-zero exit status 1.

Here’s your main error: contrasts can be applied only to factors with 2 or more levels

This tells me that one of your metadata variables, either Year or PathogenTreatment, does not have 2 or more levels.



I have 2 levels for the year variable (2016 and 2017), and I entered them as (β€œ2016”, β€œ2017”) in the metadata file, so the year is not treated as numbers.
For pathogen treatment, I have also 2 levels; C and E

Does this command work if you test them separately? Like this:
--p-formula Year
--p-formula PathogenTreatment

Are Year and PathogenTreatment fully blocked, or does each Year only have one treatment?


I tested each variable separately, year worked well, but pathogen treatment generated diversity plugin error.
Both treatments are there in each year



Would you be willing to share your metadata? Maybe I can spot something wrong with it…


I will be sending the metadata file to your business e.mail if you do not mind.

Thanks so much

I sent it to your gmail.

Hello Eman Khalaf,

I’ve replied to your email, but I also wanted to mention this here.

I do not provide private support for forum questions. I want to make sure that people can benefit from my answers (and correct my mistakes!) from all over the internet.



metadataq.tsv (3.0 KB)

The file is uploaded here!


1 Like

Hi @Eman,
Honestly I am not sure what the problem is here, the metadata look okay β€” but obviously the issue lies with the PathogenTreatment column:

Ultimately this is error is coming from R, and it sounds like this is a common error with several R packages that is somewhat difficult to diagnose and reproduce. This stackoverflow post has a very detailed answer for how to diagnose and troubleshoot this β€” I recommend following these steps in R to figure out what is wrong with your metadata.

Please follow up here if you are able to solve this issue β€” we have not seen this error before with adonis (except in cases where missing data or missing levels were obvious sources) so this will be useful for the community in case others run into this.


1 Like

I will follow the link, but I have a question; the command run in qiime from linux terminal,not R. I mean is R installation involved in qiime environment?

1 Like

Yes, this action is wrapping vegan-r to run adonis in R.

You can see exactly what is going on in R from the error report. This is the command being run in R:

and you can see the output from R here:

You can export your distance matrix, import to R, and then run vegan-adonis directly to replicate this error.

1 Like

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