Runing Adonis with strata

I know that this fucntionality is going to be implemented in one of the new releases of Qiime2, but in case if someone need it before the corresponding update, here is a short tutorial how to perform Adonis analysis with strata (cage effect, or restricted permutations) without any knowledge of R through terminal.

First of all, you will need to obtain a modified R script from Qiime2:
run_adonis.R (759 Bytes). It was modified to accept "strata" as additional parameter. Store it somewhere you will be able to acces.

Extract a distance matrix from the distance_matrix.qza:

qiime tools export \
  --input-path Core-metrics/jaccard_distance_matrix.qza \
  --output-path path/

If in the matrix not all samples from metadata are represented, create a new metadata file with only samples from the matrix to avoid adonis errors.

When all files ready, run in the terminal with qiime2 activated:

#Modify variables here
adonisR=path/run_adonis.R        #path to the script
matrix=path/distance-matrix.tsv  #path to the matrix
metadata=path/metadata.tsv       #path to the metadata
column=Column_to_test            #column to test
perms=999                        #number of permutations
njobs=2                          #number of jobs/threads
strata=Column_as_strata          #column as strata 
res=path/res.tsv                 #path to the output file

chmod +x $adonisR
$adonisR $matrix $metadata $column $perms $njobs $strata $res

The run will produce the output file with a p-value of permanova test.
To run it in a pairwise mode, one will need to filter matrix and metadata files to contain only one pair for the run for each of the pairs to be tested, then p-values should be adjusted for multiple comparissons. All steps can be implemented in python for automatisation. In R, one can run it directly as R function without this script.