export disparity results from procrustes analysis into string

Hi,
I have performed procrustes analysis vis python api (qiime2-2021.11). I have managed to export normalised ordinations into pandas, however I cannot figure out how to export disparity results into a string format - I wan't to use it in my plot's title.

plt.title('PROCRUSTES ANALYSIS - TRUE AND PREDICTED DATA. Disparity = {:.2f}'.format(disparity)

this is the code I'm using for procrustes analysis

reference = calculate_bc_distmat(ref_file)
other = calculate_bc_distmat(other_file)

procrustes_results = procrustes_analysis(reference.pcoa, other.pcoa)

reference_procrustes = procrustes_results.transformed_reference.view(OrdinationResults).samples
other_procrustes = procrustes_results.transformed_other.view(OrdinationResults).samples

I would appreciate any help with that matter.
Thank you!

Hi @zzkar,

Welcome back to the forum! Happy to provide some assistance here.

Thanks for sharing the details on your procrustes analysis - I do have one question from what you provided above:

reference = calculate_bc_distmat(ref_file)
other = calculate_bc_distmat(other_file)

procrustes_results = procrustes_analysis(reference.pcoa, other.pcoa)

reference_procrustes = procrustes_results.transformed_reference.view(OrdinationResults).samples
other_procrustes = procrustes_results.transformed_other.view(OrdinationResults).samples

You've set your procrustes_results variable to procrustes_analysis(reference.pcoa, other.pcoa) but you haven't included the third return value in your procrustes analysis (which is where the disparity value should be coming from). Unless I've missed something, where are you assigning that return value?

Here is the artifact API reference for this method, showing these three return values:
Screen Shot 2022-01-11 at 12.58.51 PM

Here's an example (from your previous commands above) of how you can pull out the disparity value from the disparity_results:

import pandas as pd
from qiime2 import Artifact
from qiime2.plugins.diversity.methods import procrustes_analysis

procrustes_results = procrustes_analysis(reference.pcoa, other.pcoa)

stat_df = procrustes_results.disparity_results.view(pd.DataFrame)

disp = stat_df['true M^2 value']['results']

As a quick overview of what I've done here, I'm first setting the stat_df variable using the disparity_results element, viewing as a pandas dataframe. I can then pull out the actual disparity value (which will be a float) by pulling that from the dataframe. From here, you can change that value to a string, or whatever else you may need for your analysis!

Hope this helps! Let us know if you're still having trouble pulling out the disparity value in your analysis.

Cheers :lizard:

1 Like

@zzkar,

Just as a heads up (to prevent any confusion on your end) - I modified my original response to account for some initial misunderstandings on my end (sorry about that!). What you see above is my modified response. Let me know if you have any questions! :nerd_face:

2 Likes