Identify centroids within treatment groups using Wunifrac distances

Hello there -

I’ve visualized Wunifrac distances using emperor and found that the amount of variance between different treatment groups over time seems to vary considerably.

I would like to identify centroids for each individual (8 time points per person), and then measure the distance from their centroid to each of their data point coordinates.

Using these values I will then compare the amount of variance observed within each individual/treatment group.

Can anyone help me understand the ordination.txt file so that I can calculate these centroids and distances?

Thank you in advance for your time!


Hello @atgustin. If you are comfortable with Python I would recommend using QIIME2’s python interface. You would do something like:

from skbio import OrdinationResults
import qiime2 as q2

ordination = q2.Artifact.load('unweighted-unifrac.pcoa.qza').view(OrdinationResults)

# access the coordinates of the samples through the "samples" property

Since the samples property is a DataFrame you can index by row through the sample name (probably using your sample metadata) and select the subsets from which you want to calculate the centroids. The columns in this matrix represent the different PCoA axes. Perhaps you can do this calculation with a series of vectorization commands i.e. groupby, mean, etc.

Alternatively, if you would like to load this file in a different environment, there’s a comprehensive description of the ordination format here.


Thank you! I was just hatching a plan to do something similar using phyloseq, but I’m happier working in python. I’ll report back with results. Again, i appreciate your time!


As a means of learning to teach myself in the future - can I ask if there was a location where I could have queried this information for myself?

1 Like

Sounds great!

While the documentation is still evolving, QIIME’s Python docs can be found here. Most of the underlying objects are taken from scikit-bio, hence being familiar with that library also helps. Otherwise, the forum is the right place to ask about these sorts of things.


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