Python Tutorial: Data Visualization with Dokdo API

Hi everyone,

My name is Seung-been Lee, and I go by Steven. I’m currently a senior researcher at a next-generation sequencing company in South Korea. I started doing microbiome analysis only this September. If it wasn’t for QIIME 2, I would not have been able to pick up my project so quickly and smoothly. Therefore, I am very grateful for the QIIME 2 team for their amazing work and user support, as well as the QIIME 2 community for their kind and helpful discussions.

That being said, one main task I have to constantly do for my microbiome project is creating publication-quality figures. QIIME 2 already provides Visualizations and QIIME 2 View, both of which are extremely useful for exploring the output data interactively. However, I noticed that these options are not robust enough for me when it comes to making figures for presentation (e.g. PowerPoint). For example, you cannot currently download alpha rarefaction curve from the alpha-rarefaction.qzv file. For other Visualizations, you can download the figure as a PNG/SVG file, but you cannot change its axis, legend, title, etc. Moreover, once created, those visualization files cannot be modified to, for example, make a subset of the samples (e.g. a taxonomic bar plot). Therefore, the user would have to go way back to perform sample filtration, redo the analysis, and create a new visualization file again, which can be burdensome and time-consuming.

At this point, let me be very clear: I’m not saying QIIME 2 Visualizations should be able to do all the things I metnioned above. I would say it’s actually better QIIME 2 doesn’t do those because then its code can stay simple and focused on the method’s core functionality. And the QIIME 2 user can employ other tools to make the plots however they want. For example, if you are coming from the world of R software, you already have the famous tools available such as Phyloseq and qiime2R.

The issue for me was, even though I can code in both Python and R, I’m way more proficient in Python, and I could not find any Python packages for plotting QIIME 2 objects/files efficiently. That is why I wrote the Dokdo package myself. Dokdo is a lightweight Python package for microbiome sequencing analysis, which can be used as a command line tool and as a Python module. Dokdo is designed to be used with QIIME 2. There is no installation for Dokdo. Simply clone the Dokdo repository and you are good to go. Only QIIME 2 is required.

For the purpose of this tutorial, I will only describe the Dokdo API and how it can be used to make pretty figures using QIIME 2 files/objects directly. For more details, please visit the Dokdo repository and its Wiki page. Note also that this tutorial was inspired by the famous qiime2R tutorial by Jordan Bisanz.

If you have any questions/suggestions/feature requests/etc., please let me know in the comment section.

Table of Contents

Introduction

This page describes the Dokdo API, which is designed to be used with Jupyter Notebook in Python. Make sure your notebook is open within an environment where QIIME 2 is installed. This page assumes you are using the latest Dokdo version 1.1.0. If you are using an older version, please consider updating.

At the beginning of your notebook, enter the following to import the Dokdo API.

import sys
sys.path.append('/path/to/dokdo') # You should change this.
import api

Add the following to make figures. You should have the matplotlib package already installed in your environment because it is included in QIIME 2 installation. With the magic function %matplotlib inline, the output of plotting methods will be displayed inline within Jupyter Notebook.

import matplotlib.pyplot as plt
%matplotlib inline

Tips

Setting Figure Properties

In this section, you’ll learn how to control various properties of a figure using the denoising_stats_plot() method as an example. This method creates a grouped box chart using denoising statistics from the DADA 2 algorithm.

Let’s start with a toy example. The figure below does not have a legend, which is bad, but let’s not worry about that now.

qza_file = 'data/atacama-soil-microbiome-tutorial/denoising-stats.qza'
metadata_file = 'data/atacama-soil-microbiome-tutorial/sample-metadata.tsv'

api.denoising_stats_plot(qza_file, metadata_file, 'transect-name')

plt.tight_layout()

Setting-Figure-Properties-1C

Aesthetics

We can change the figure style. I personally like the seaborn package’s default style.

import seaborn as sns

with sns.axes_style('darkgrid'):
    api.denoising_stats_plot(qza_file, metadata_file, 'transect-name')

plt.tight_layout()

Setting-Figure-Properties-2C

If you’re coming from the world of R software, you may find the ggplot style more soothing for your eyes.

import matplotlib.pyplot as plt

with plt.style.context('ggplot'):
    api.denoising_stats_plot(qza_file, metadata_file, 'transect-name')

plt.tight_layout()

Setting-Figure-Properties-3C

Note that in both cases, the styling is set locally. If you are planning to make many plots and if you want to set the style for all of them (i.e. globally), use the following:

import seaborn as sns
sns.set()

# import matplotlib.pyplot as plt
# plt.style.use('ggplot')

Finally, if you want to turn off the styling at any point after setting it globally, use the following:

# import matplotlib
# matplotlib.rc_file_defaults()

Plot Size

There are various ways you can control the figure size. The easiest way is to use the figsize argument in a plotting method call, as shown below.

api.denoising_stats_plot(qza_file, metadata_file, 'transect-name', figsize=(9, 3))

plt.tight_layout()

Setting-Figure-Properties-4C

If you plan to draw more than one plot in the same figure, you can specify the figure size using the figsize argument in the following way.

fig, [ax1, ax2] = plt.subplots(1, 2, figsize=(9, 3))

api.denoising_stats_plot(qza_file, metadata_file, 'transect-name', ax=ax1)
api.denoising_stats_plot(qza_file, metadata_file, 'transect-name', ax=ax2)

plt.tight_layout()

Setting-Figure-Properties-5C

You can also set the figure width/height ratios using width_ratios and height_ratios from gridspec_kw.

fig, [ax1, ax2] = plt.subplots(1, 2, figsize=(9, 3), gridspec_kw={'width_ratios': [8, 2]})

api.denoising_stats_plot(qza_file, metadata_file, 'transect-name', ax=ax1)
api.denoising_stats_plot(qza_file, metadata_file, 'transect-name', ax=ax2)

plt.tight_layout()

Setting-Figure-Properties-6C

Alternatively, you can combine plot spaces to control the width/height ratios using gridspec.

import matplotlib.gridspec as gridspec

fig, axes  = plt.subplots(2, 2, figsize=(9, 5))

api.denoising_stats_plot(qza_file, metadata_file, 'transect-name', ax=axes[0][0])
api.denoising_stats_plot(qza_file, metadata_file, 'transect-name', ax=axes[1][0])

gs = axes[0, 1].get_gridspec()

for ax in axes[0:2, 1]:
    ax.remove()
    
axbig = fig.add_subplot(gs[0:2, 1])
api.denoising_stats_plot(qza_file, metadata_file, 'transect-name', ax=axbig)

plt.tight_layout()

Setting-Figure-Properties-7C

Title, Axis, Legend

Each plotting method takes a dictionary argument called artist_kwargs as input that is passed down to the private method _artist() as shown below. For example, the show_legend argument is set as False by default, which means if you want to include a figure legend, you should include artist_kwargs=dict(show_legend=False) in the method call. Note that different methods can have a different set of default keyword arguments (e.g. xlabel is different between the denoising_stats_plot() and read_quality_plot() methods).

_artist(ax, title=None, xlabel=None, ylabel=None, zlabel=None, hide_xtexts=False, hide_ytexts=False, hide_ztexts=False, hide_xlabel=False, hide_ylabel=False, hide_zlabel=False, hide_xticks=False, hide_yticks=False, hide_zticks=False, hide_xticklabels=False, hide_yticklabels=False, hide_zticklabels=False, xticks=None, yticks=None, xticklabels=None, yticklabels=None, xrot=None, xha=None, xmin=None, xmax=None, ymin=None, ymax=None, xlog=False, ylog=False, show_legend=False, legend_loc='best', legend_ncol=1, legend_labels=None, legend_short=False, remove_duplicates=False, legend_only=False)
    This method controls various properties of a figure.
    
    Parameters
    ----------
    ax : matplotlib.axes.Axes
        Axes object to draw the plot onto.
    title : str, optional
        Sets the figure title.
    xlabel : str, optional
        Set the x-axis label.
    ylabel : str, optional
        Set the y-axis label.
    zlabel : str, optional
        Set the z-axis label.
    hide_xtexts : bool, default: False
        Hides all the x-axis texts.
    hide_ytexts : bool, default: False
        Hides all the y-axis texts.
    hide_ztexts : bool, default: False
        Hides all the z-axis texts.
    hide_xlabel : bool, default: False
        Hides the x-axis label.
    hide_ylabel : bool, default: False
        Hides the y-axis label.
    hide_zlabel : bool, default: False
        Hides the z-axis label.
    hide_xticks : bool, default: False
        Hides ticks and tick labels for the x-axis.
    hide_yticks : bool, default: False
        Hides ticks and tick labels for the y-axis.
    hide_zticks : bool, default: False
        Hides ticks and tick labels for the z-axis.
    hide_xticklabels : bool, default: False
        Hides tick labels for the x-axis.
    hide_yticklabels : bool, default: False
        Hides tick labels for the y-axis.
    hide_zticklabels : bool, default: False
        Hides tick labels for the z-axis.
    xticks : list, optional
        Positions of x-axis ticks.
    yticks : list, optional
        Positions of y-axis ticks.
    xticklabels : list, optional
        Tick labels for the x-axis.
    yticklabels : list, optional
        Tick labels for the y-axis.
    xrot : float, optional
        Rotation degree of tick labels for the x-axis.
    xha : str, optional
        Horizontal alignment of tick labels for the x-axis.
    xmin : float, optional
        Minimum value for the x-axis.
    xmax : float, optional
        Maximum value for the x-axis.
    ymin : float, optional
        Minimum value for the y-axis.
    ymax : float, optional
        Maximum value for the x-axis.
    xlog : bool, default: False
        Draw the x-axis in log scale.
    ylog : bool, default: False
        Draw the y-axis in log scale.
    show_legend : bool, default: False
        Show the figure legend.
    legend_loc : str, default: 'best'
        Legend location specified as in matplotlib.pyplot.legend.
    legend_ncol : int, default: 1
        Number of columns that the legend has.
    legend_only : bool, default: False
        Clear the figure and display the legend only.
    
    Returns
    -------
    matplotlib.axes.Axes
        Returns the Axes object with the plot drawn onto it.

Below are some simple examples.

qza_file = 'data/atacama-soil-microbiome-tutorial/denoising-stats.qza'
metadata_file = 'data/atacama-soil-microbiome-tutorial/sample-metadata.tsv'

fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(10, 8))

artist_kwargs1 = dict(title='My title')
artist_kwargs2 = dict(title='ylog=True', ylog=True, ymin=0.5E1, ymax=1.5E5)
artist_kwargs3 = dict(title='legend_ncol=2', show_legend=True, legend_ncol=2)
artist_kwargs4 = dict(title='hide_yticks=True', hide_yticks=True)

api.denoising_stats_plot(qza_file, metadata_file, 'transect-name', ax=ax1, artist_kwargs=artist_kwargs1)
api.denoising_stats_plot(qza_file, metadata_file, 'transect-name', ax=ax2, artist_kwargs=artist_kwargs2)
api.denoising_stats_plot(qza_file, metadata_file, 'transect-name', ax=ax3, artist_kwargs=artist_kwargs3)
api.denoising_stats_plot(qza_file, metadata_file, 'transect-name', ax=ax4, artist_kwargs=artist_kwargs4)

plt.tight_layout()

Plotting Legend Separately

In some situations, we may wish to plot the graph and the legend separately. For example, the taxa_abundance_bar_plot() method by default displays the whole taxa name, which can be quite long and disrupting as shown below.

qzv_file = 'data/moving-pictures-tutorial/taxa-bar-plots.qzv'
api.taxa_abundance_bar_plot(qzv_file, level=2, count=8, figsize=(9, 5), artist_kwargs=dict(show_legend=True))

plt.tight_layout()

Plotting-Legend-Separately-1C

We can ameliorate the issue by plotting the legend separately with legend_only=True (note that in this particular case, there is also the short_legend=True option which makes a pretty legend for the taxaonomy bar plot).

fig, [ax1, ax2] = plt.subplots(1, 2, figsize=(11, 5), gridspec_kw={'width_ratios': [9, 1]})

api.taxa_abundance_bar_plot(qzv_file, ax=ax1, level=2, count=8)
api.taxa_abundance_bar_plot(qzv_file, ax=ax2, level=2, count=8, artist_kwargs=dict(legend_loc='upper left', legend_only=True))

plt.tight_layout()

Plotting QIIME 2 Objects

Thus far, for plotting purposes, we have only used files created by the QIIME 2 CLI (i.e. .qza and .qzv files). However, we can also plot objects created by the QIIME 2 API.

For example, we can directly plot the Artifact object from the diversity.visualizers.alpha_rarefaction() method (i.e. QIIME 2 API).

from qiime2 import Artifact
from qiime2 import Metadata
from qiime2.plugins import diversity

table = Artifact.load('data/moving-pictures-tutorial/table.qza')
phylogeny = Artifact.load('data/moving-pictures-tutorial/rooted-tree.qza')
metadata = Metadata.load('data/moving-pictures-tutorial/sample-metadata.tsv')

rarefaction_result = diversity.visualizers.alpha_rarefaction(table=table, metadata=metadata, phylogeny=phylogeny, max_depth=4000)
rarefaction = rarefaction_result.visualization

api.alpha_rarefaction_plot(rarefaction)

plt.tight_layout()

Plotting-QIIME-2-Objects-1C

As expected, above gives the same result as using the Visualization file created by the qiime diversity alpha-rarefaction command (QIIME 2 CLI).

qzv_file = 'data/moving-pictures-tutorial/alpha-rarefaction.qzv'

api.alpha_rarefaction_plot(qzv_file)

plt.tight_layout()

Plotting-QIIME-2-Objects-2C

General Methods

get_mf

get_mf(metadata)
    This method automatically detects the type of input metadata and converts 
    it to DataFrame object.
    
    Parameters
    ----------
    metadata : str or qiime2.Metadata
        Metadata file or object.
    
    Returns
    -------
    pandas.DataFrame
        DataFrame object containing metadata.

This is a simple example.

mf = api.get_mf('data/moving-pictures-tutorial/sample-metadata.tsv')
mf.head()
barcode-sequence body-site year month day subject reported-antibiotic-usage days-since-experiment-start
sample-id
L1S8 AGCTGACTAGTC gut 2008.0 10.0 28.0 subject-1 Yes 0.0
L1S57 ACACACTATGGC gut 2009.0 1.0 20.0 subject-1 No 84.0
L1S76 ACTACGTGTGGT gut 2009.0 2.0 17.0 subject-1 No 112.0
L1S105 AGTGCGATGCGT gut 2009.0 3.0 17.0 subject-1 No 140.0
L2S155 ACGATGCGACCA left palm 2009.0 1.0 20.0 subject-1 No 84.0

ordinate

ordinate(table, metadata=None, where=None, metric='jaccard', phylogeny=None)
    This method wraps multiple QIIME 2 methods to perform ordination and 
    returns Artifact object containing PCoA results.
    
    Under the hood, this method filters the samples (if requested), performs 
    rarefying to the sample with the minimum read depth, computes distance 
    matrix, and then runs PCoA.
    
    Parameters
    ----------
    table : str
        Table file.
    metadata : str or qiime2.Metadata, optional
        Metadata file or object.
    where : str, optional
        SQLite WHERE clause specifying sample metadata criteria.
    metric : str, default: 'jaccard'
        Metric used for distance matrix computation ('jaccard',
        'bray_curtis', 'unweighted_unifrac', or 'weighted_unifrac').
    phylogeny : str, optional
        Rooted tree file. Required if using 'unweighted_unifrac', or 
        'weighted_unifrac' as metric.
    
    Returns
    -------
    qiime2.Artifact
        Artifact object containing PCoA results.
    
    See Also
    --------
    beta_2d_plot
    beta_3d_plot
    
    Notes
    -----
    The resulting Artifact object can be directly used for plotting by the 
    beta_2d_plot() method.

Below is a simple example. Note that the default distance metric used is jaccard. The resulting object pcoa can be directly used for plotting by the beta_2d_plot method as shown below.

qza_file = 'data/moving-pictures-tutorial/table.qza'
metadata_file = 'data/moving-pictures-tutorial/sample-metadata.tsv'

pcoa = api.ordinate(qza_file)
api.beta_2d_plot(pcoa, metadata=metadata_file, hue='body-site', artist_kwargs=dict(show_legend=True))

plt.tight_layout()

ordinate-1C

You can choose a subset of samples.

pcoa = api.ordinate(qza_file, metadata=metadata_file, where="[body-site] IN ('gut', 'left palm')")
api.beta_2d_plot(pcoa, metadata=metadata_file, hue='body-site', artist_kwargs=dict(show_legend=True))

plt.tight_layout()

ordinate-2C

Main Plotting Methods

read_quality_plot

read_quality_plot(demux, strand='forward', ax=None, figsize=None, artist_kwargs=None)
    This method creates a read quality plot.
    
    Parameters
    ----------
    demux : str or qiime2.Visualization
        Visualization file or object from the q2-demux plugin.
    strand : str, default: 'forward'
        Read strand to be displayed (either 'forward' or 'reverse').
    ax : matplotlib.axes.Axes, optional
        Axes object to draw the plot onto, otherwise uses the current Axes.
    figsize : tuple, optional
        Width, height in inches. Format: (float, float).
    artist_kwargs : dict, optional
        Keyword arguments passed down to the _artist() method.
    
    Returns
    -------
    matplotlib.axes.Axes
        Returns the Axes object with the plot drawn onto it.
    
    Notes
    -----
    Example usage of the q2-demux plugin:
        CLI -> $ qiime demux summarize [OPTIONS]
        API -> from qiime2.plugins.demux.visualizers import summarize

Below is a simple example.

qzv_file = 'data/atacama-soil-microbiome-tutorial/demux-subsample.qzv'

fig, [ax1, ax2] = plt.subplots(1, 2)

artist_kwargs1 = dict(title='Forward read')
artist_kwargs2 = dict(title='Reverse read', hide_ylabel=True, hide_yticklabels=True)

api.read_quality_plot(qzv_file, strand='forward', ax=ax1, artist_kwargs=artist_kwargs1)
api.read_quality_plot(qzv_file, strand='reverse', ax=ax2, artist_kwargs=artist_kwargs2)

plt.tight_layout()

read_quality_plot-1C

denoising_stats_plot

denoising_stats_plot(stats, metadata, where, ax=None, figsize=None, pseudocount=False, order=None, hide_nsizes=False, artist_kwargs=None)
    This method creates a grouped box chart using denoising statistics from 
    the DADA 2 algorithm.
    
    Parameters
    ----------
    stats : str or qiime2.Artifact
        Artifact file or object from the q2-dada2 plugin.
    metadata : str or qiime2.Metadata
        Metadata file or object.
    where : str
        Column name of the sample metadata.
    ax : matplotlib.axes.Axes, optional
        Axes object to draw the plot onto, otherwise uses the current Axes.
    figsize : tuple, optional
        Width, height in inches. Format: (float, float).
    pseudocount : bool, default: False
        Add pseudocount to remove zeros.
    order : list, optional
        Order to plot the categorical levels in.
    hide_nsizes : bool, default: False
        Hide sample size from x-axis labels.
    artist_kwargs : dict, optional
        Keyword arguments passed down to the _artist() method.
    
    Returns
    -------
    matplotlib.axes.Axes
        Returns the Axes object with the plot drawn onto it.
    
    Notes
    -----
    Example usage of the q2-dada2 plugin:
        CLI -> qiime dada2 denoise-paired [OPTIONS]
        API -> from qiime2.plugins.dada2.methods import denoise_paired

Below is a simple example.

qza_file = 'data/atacama-soil-microbiome-tutorial/denoising-stats.qza'
metadata_file = 'data/atacama-soil-microbiome-tutorial/sample-metadata.tsv'

api.denoising_stats_plot(qza_file, metadata_file, 'transect-name', artist_kwargs=dict(show_legend=True))

plt.tight_layout()

denoising_stats_plot-1C

alpha_rarefaction_plot

alpha_rarefaction_plot(rarefaction, hue='sample-id', metric='shannon', ax=None, figsize=None, hue_order=None, artist_kwargs=None)
    This method creates an alpha rarefaction plot.
    
    Parameters
    ----------
    rarefaction : str or qiime2.Visualization
        Visualization file or object from the q2-diversity plugin.
    hue : str, default: 'sample-id'
        Grouping variable that will produce lines with different colors.
    metric : str, default: 'shannon'
        Diversity metric ('shannon', 'observed_features', or 'faith_pd').
    ax : matplotlib.axes.Axes, optional
        Axes object to draw the plot onto, otherwise uses the current Axes.
    figsize : tuple, optional
        Width, height in inches. Format: (float, float).
    hue_order : list, optional
        Specify the order of categorical levels of the 'hue' semantic.
    artist_kwargs : dict, optional
        Keyword arguments passed down to the _artist() method.
    
    Returns
    -------
    matplotlib.axes.Axes
        Returns the Axes object with the plot drawn onto it.
    
    Notes
    -----
    Example usage of the q2-diversity plugin:
        CLI -> qiime diversity alpha-rarefaction [OPTIONS]
        API -> from qiime2.plugins.diversity.visualizers import alpha_rarefaction

Below is a simple example.

qzv_file = 'data/moving-pictures-tutorial/alpha-rarefaction.qzv'
artist_kwargs = dict(show_legend=True, legend_ncol=5)

api.alpha_rarefaction_plot(qzv_file, figsize=(8, 5), artist_kwargs=artist_kwargs)

plt.tight_layout()

alpha_rarefaction_plot-1C

We can also group the samples by body-site.

artist_kwargs = dict(show_legend=True)

api.alpha_rarefaction_plot(qzv_file, hue='body-site', metric='observed_features', figsize=(8, 5), artist_kwargs=artist_kwargs)

plt.tight_layout()

alpha_rarefaction_plot-2C

alpha_diversity_plot

alpha_diversity_plot(significance, where, ax=None, figsize=None, add_swarmplot=False, order=None, artist_kwargs=None)
    This method creates an alpha diversity plot.
    
    Parameters
    ----------
    significance : str or qiime2.Visualization
        Visualization file or object from the q2-diversity plugin.
    where : str
        Column name to be used for the x-axis.
    ax : matplotlib.axes.Axes, optional
        Axes object to draw the plot onto, otherwise uses the current Axes.
    figsize : tuple, optional
        Width, height in inches. Format: (float, float).
    add_swarmplot : bool, default: False
        Add a swarm plot on top of the box plot.
    order : list, optional
        Order to plot the categorical levels in.
    artist_kwargs : dict, optional
        Keyword arguments passed down to the _artist() method.
    
    Returns
    -------
    matplotlib.axes.Axes
        Returns the Axes object with the plot drawn onto it.
    
    Notes
    -----
    Example usage of the q2-diversity plugin:
        CLI -> qiime diversity alpha-group-significance [OPTIONS]
        API -> from qiime2.plugins.diversity.visualizers import alpha_group_significance

Below is a simple example.

qzv_file = 'data/moving-pictures-tutorial/faith-pd-group-significance.qzv'

api.alpha_diversity_plot(qzv_file, 'body-site')

plt.tight_layout()

alpha_diversity_plot-1C

beta_2d_plot

beta_2d_plot(ordination, metadata=None, hue=None, size=None, style=None, s=80, alpha=None, ax=None, figsize=None, hue_order=None, style_order=None, legend_type='brief', artist_kwargs=None)
    This method creates a 2D beta diversity plot.
    
    Parameters
    ----------
    ordination : str or qiime2.Artifact
        Artifact file or object from the q2-diversity plugin.
    metadata : str or qiime2.Metadata, optional
        Metadata file or object.
    hue : str, optional
        Grouping variable that will produce points with different colors.
    size : str, optional
        Grouping variable that will produce points with different sizes.
    style : str, optional
        Grouping variable that will produce points with different markers.
    s : int, default: 80
        Marker size.
    alpha : float, optional
        Proportional opacity of the points.
    ax : matplotlib.axes.Axes, optional
        Axes object to draw the plot onto, otherwise uses the current Axes.
    figsize : tuple, optional
        Width, height in inches. Format: (float, float).
    hue_order : list, optional
        Specify the order of categorical levels of the 'hue' semantic.
    style_order : list, optional
        Specify the order of categorical levels of the 'style' semantic.
    legend_type : str, default: 'brief'
        Legend type as in seaborn.scatterplot ('brief' or 'full').
    artist_kwargs : dict, optional
        Keyword arguments passed down to the _artist() method.
    
    Returns
    -------
    matplotlib.axes.Axes
        Returns the Axes object with the plot drawn onto it.
    
    See Also
    --------
    ordinate
    beta_3d_plot
    
    Notes
    -----
    Example usage of the q2-diversity plugin:
        CLI -> qiime diversity pcoa [OPTIONS]
        API -> from qiime2.plugins.diversity.methods import pcoa

Below is a simple example.

qza_file = 'data/moving-pictures-tutorial/unweighted_unifrac_pcoa_results.qza'

api.beta_2d_plot(qza_file)

plt.tight_layout()

beta_2d_plot-1C

We can color the datapoints with hue. We can also change the style of datapoints with style. If the variable of interest is numeric, we can use size to control the size of datapoints. Finally, we can combine all those groupings.

metadata_file = 'data/moving-pictures-tutorial/sample-metadata.tsv'

fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(8, 8))

artist_kwargs1 = dict(show_legend=True, title="hue='body-site'")
artist_kwargs2 = dict(show_legend=True, title="style='subject'")
artist_kwargs3 = dict(show_legend=True, title="size='days-since-experiment-start'")
artist_kwargs4 = dict(title="Combined groupings")

api.beta_2d_plot(qza_file, metadata_file, ax=ax1, hue='body-site', artist_kwargs=artist_kwargs1)
api.beta_2d_plot(qza_file, metadata_file, ax=ax2, style='subject', artist_kwargs=artist_kwargs2)
api.beta_2d_plot(qza_file, metadata_file, ax=ax3, size='days-since-experiment-start', artist_kwargs=artist_kwargs3)
api.beta_2d_plot(qza_file, metadata_file, ax=ax4, hue='body-site', style='subject', size='days-since-experiment-start', artist_kwargs=artist_kwargs4)

plt.tight_layout()

beta_3d_plot

beta_3d_plot(ordination, metadata, hue=None, azim=-60, elev=30, s=80, ax=None, figsize=None, hue_order=None, artist_kwargs=None)
    This method creates a 3D beta diversity plot.
    
    Parameters
    ----------
    ordination : str or qiime2.Artifact
        Artifact file or object from the q2-diversity plugin.
    metadata : str or qiime2.Metadata
        Metadata file or object.
    hue : str, optional
        Grouping variable that will produce points with different colors.
    azim : int, default: -60
        Elevation viewing angle.
    elev : int, default: 30
        Azimuthal viewing angle.
    s : int, default: 80
        Marker size.
    ax : matplotlib.axes.Axes, optional
        Axes object to draw the plot onto, otherwise uses the current Axes.
    figsize : tuple, optional
        Width, height in inches. Format: (float, float).
    hue_order : list, optional
        Specify the order of categorical levels of the 'hue' semantic.
    artist_kwargs : dict, optional
        Keyword arguments passed down to the _artist() method.
    
    Returns
    -------
    matplotlib.axes.Axes
        Returns the Axes object with the plot drawn onto it.
    
    See Also
    --------
    ordinate
    beta_2d_plot
    
    Notes
    -----
    Example usage of the q2-diversity plugin:
        CLI -> qiime diversity pcoa [OPTIONS]
        API -> from qiime2.plugins.diversity.methods import pcoa

Below is a simple example.

qza_file = 'data/moving-pictures-tutorial/unweighted_unifrac_pcoa_results.qza'
metadata_file = 'data/moving-pictures-tutorial/sample-metadata.tsv'

api.beta_3d_plot(qza_file, metadata_file, 'body-site', figsize=(6, 6), artist_kwargs=dict(show_legend=True))

plt.tight_layout()

beta_3d_plot-1A

We can control the camera angle with elev and azim.

fig = plt.figure(figsize=(12, 6))

ax1 = fig.add_subplot(1, 2, 1, projection='3d')
ax2 = fig.add_subplot(1, 2, 2, projection='3d')

api.beta_3d_plot(qza_file, metadata_file, ax=ax1, hue='body-site', elev=15)
api.beta_3d_plot(qza_file, metadata_file, ax=ax2, hue='body-site', azim=70)

plt.tight_layout()

distance_matrix_plot

distance_matrix_plot(distance_matrix, bins=100, pairs=None, ax=None, figsize=None, artist_kwargs=None)
    This method creates a histogram from a distance matrix.
    
    Parameters
    ----------
    distance_matrix : str or qiime2.Artifact
        Artifact file or object from the q2-diversity-lib plugin.
    bins : int, optional
        Number of bins to be displayed.
    pairs : list, optional
        List of sample pairs to be shown in red vertical lines.
    ax : matplotlib.axes.Axes, optional
        Axes object to draw the plot onto, otherwise uses the current Axes.
    figsize : tuple, optional
        Width, height in inches. Format: (float, float).
    artist_kwargs : dict, optional
        Keyword arguments passed down to the _artist() method.
    
    Returns
    -------
    matplotlib.axes.Axes
        Returns the Axes object with the plot drawn onto it.
    
    Notes
    -----
    Example usage of the q2-diversity-lib plugin:
        CLI -> qiime diversity-lib jaccard [OPTIONS]
        API -> from qiime2.plugins.diversity_lib.methods import jaccard

Below is a simple example.

qza_file = 'data/moving-pictures-tutorial/unweighted_unifrac_distance_matrix.qza'

api.distance_matrix_plot(qza_file)

plt.tight_layout()

distance_matrix_plot-1

We can indicate the distance between any two samples on top of the histogram using pairs.

api.distance_matrix_plot(qza_file, pairs=[['L1S8', 'L1S57'], ['L2S175', 'L2S204']])

plt.tight_layout()

distance_matrix_plot-2

taxa_abundance_bar_plot

taxa_abundance_bar_plot(taxa, metadata=None, level=1, by=None, ax=None, figsize=None, width=0.8, count=0, exclude_samples=None, include_samples=None, exclude_taxa=None, sort_by_names=False, colors=None, label_columns=None, orders=None, sample_names=None, csv_file=None, taxa_names=None, sort_by_mean1=True, sort_by_mean2=True, sort_by_mean3=True, show_others=True, artist_kwargs=None)
    This method creates a taxa abundance plot.
    
    Although the input visualization file should contain medatadata already, 
    you can replace it with new metadata by using the 'metadata' option.
    
    Parameters
    ----------
    taxa : str or qiime2.Visualization
        Visualization file or object from the q2-taxa plugin.
    metadata : str or qiime2.Metadata, optional
        Metadata file or object.
    level : int, default: 1
        Taxonomic level at which the features should be collapsed.
    by : list, optional
        Column name(s) to be used for sorting the samples. Using 'index' will 
        sort the samples by their name, in addition to other column name(s) 
        that may have been provided. If multiple items are provided, sorting 
        will occur by the order of the items.
    ax : matplotlib.axes.Axes, optional
        Axes object to draw the plot onto, otherwise uses the current Axes.
    figsize : tuple, optional
        Width, height in inches. Format: (float, float).
    width : float, default: 0.8
        The width of the bars.
    count : int, default: 0
        The number of taxa to display. When 0, display all.
    exclude_samples : dict, optional
        Filtering logic used for sample exclusion.
        Format: {'col': ['item', ...], ...}.
    include_samples : dict, optional
        Filtering logic used for sample inclusion.
        Format: {'col': ['item', ...], ...}.
    exclude_taxa : list, optional
        The taxa names to be excluded when matched. Case insenstivie.
    sort_by_names : bool, default: False
        If true, sort the columns (i.e. species) to be displayed by name.
    colors : list, optional
        The bar colors.
    label_columns : list, optional
        The column names to be used as the x-axis labels.
    orders : dict, optional
        Dictionary of {column1: [element1, element2, ...], column2: 
        [element1, element2...], ...} to indicate the order of items. Used to 
        sort the sampels by the user-specified order instead of ordering 
        numerically or alphabetically.
    sample_names : list, optional
        List of sample IDs to be included.
    csv_file : str, optional
        Path of the .csv file to output the dataframe to.
    taxa_names : list, optional
        List of taxa names to be displayed.
    sort_by_mean1 : bool, default: True
        Sort taxa by their mean relative abundance before sample filtration.
    sort_by_mean2 : bool, default: True
        Sort taxa by their mean relative abundance after sample filtration by 
        'include_samples' or 'exclude_samples'.
    sort_by_mean3 : bool, default: True
        Sort taxa by their mean relative abundance after sample filtration by 
        'sample_names'.
    show_others : bool, default: True
        Include the 'Others' category.
    artist_kwargs : dict, optional
        Keyword arguments passed down to the _artist() method.
    
    Returns
    -------
    matplotlib.axes.Axes
        Returns the Axes object with the plot drawn onto it.
    
    See Also
    --------
    taxa_abundance_box_plot
    
    Notes
    -----
    Example usage of the q2-taxa plugin:
        CLI -> qiime taxa barplot [OPTIONS]
        API -> from qiime2.plugins.taxa.visualizers import barplot

Below is a simple example showing taxonomic abundance at the kingdom level (i.e. level=1), which is the default taxonomic rank.

qzv_file = 'data/moving-pictures-tutorial/taxa-bar-plots.qzv'

api.taxa_abundance_bar_plot(qzv_file, figsize=(10, 7), artist_kwargs=dict(show_legend=True))

plt.tight_layout()

We can change the taxonomic rank from kingdom to species by setting level=7. Note that I removed show_legend=True because otherwise there will be too many taxa to display on the legend.

api.taxa_abundance_bar_plot(qzv_file, figsize=(10, 7), level=7)

plt.tight_layout()

We can only show the top seven most abundant species plus ‘Others’ with count=8.

artist_kwargs = dict(show_legend=True, legend_loc='upper left', legend_short=True)
api.taxa_abundance_bar_plot(qzv_file, figsize=(10, 7), level=7, count=8, artist_kwargs=artist_kwargs)

plt.tight_layout()

We can plot the figure and the legend separately.

fig, [ax1, ax2] = plt.subplots(1, 2, figsize=(12, 7), gridspec_kw={'width_ratios': [9, 1]})

artist_kwargs = dict(legend_only=True, legend_loc='upper left', legend_short=True)

api.taxa_abundance_bar_plot(qzv_file, ax=ax1, level=7, count=8)
api.taxa_abundance_bar_plot(qzv_file, ax=ax2, level=7, count=8, artist_kwargs=artist_kwargs)

plt.tight_layout()

We can sort the samples by the body-site column in metadata with by=['body-site']. To check whether the sorting worked properly, we can change the x-axis tick labels to include each sample’s body-site with label_columns.

artist_kwargs = dict(show_legend=True, legend_loc='upper left', legend_short=True)
api.taxa_abundance_bar_plot(qzv_file,
                            by=['body-site'],
                            label_columns=['body-site', 'sample-id'],
                            figsize=(10, 7),
                            level=7,
                            count=8,
                            artist_kwargs=artist_kwargs)

plt.tight_layout()

If you want to sort the samples in a certain order instead of ordering numerically or alphabetically, use the orders option.

artist_kwargs = dict(show_legend=True, legend_loc='upper left', legend_short=True)

api.taxa_abundance_bar_plot(qzv_file,
                            by=['body-site'],
                            label_columns=['body-site', 'sample-id'],
                            figsize=(10, 7),
                            level=7,
                            count=8,
                            orders={'body-site': ['left palm', 'tongue', 'gut', 'right palm']},
                            artist_kwargs=artist_kwargs)

plt.tight_layout()

We can only display the ‘gut’ and ‘tongue’ samples with include_samples.

fig, [ax1, ax2] = plt.subplots(1, 2, figsize=(9, 7), gridspec_kw={'width_ratios': [9, 1]})

kwargs = dict(include_samples={'body-site': ['gut', 'tongue']},
              by=['body-site'],
              label_columns=['body-site', 'sample-id'],
              level=7,
              count=8)

artist_kwargs = dict(legend_only=True, legend_loc='upper left', legend_short=True)

api.taxa_abundance_bar_plot(qzv_file, ax=ax1, **kwargs)
api.taxa_abundance_bar_plot(qzv_file, ax=ax2, artist_kwargs=artist_kwargs, **kwargs)

plt.tight_layout()

We can make multiple bar charts grouped by body-site. When making a grouped bar chart, it’s important to include sort_by_mean2=False in order to have the same bar colors for the same taxa across different groups.

fig, [ax1, ax2, ax3, ax4, ax5] = plt.subplots(1, 5, figsize=(16, 7), gridspec_kw={'width_ratios': [2, 2, 2, 2, 1]})

kwargs = {'level': 7, 'count': 8, 'sort_by_mean2': False}

artist_kwargs1 = dict(title='gut')
artist_kwargs2 = dict(title='left palm', hide_ylabel=True, hide_yticks=True)
artist_kwargs3 = dict(title='right palm', hide_ylabel=True, hide_yticks=True)
artist_kwargs4 = dict(title='tongue', hide_ylabel=True, hide_yticks=True)
artist_kwargs5 = dict(legend_only=True, legend_loc='upper left', legend_short=True)

api.taxa_abundance_bar_plot(qzv_file, ax=ax1, artist_kwargs=artist_kwargs1, include_samples={'body-site': ['gut']}, **kwargs)
api.taxa_abundance_bar_plot(qzv_file, ax=ax2, artist_kwargs=artist_kwargs2, include_samples={'body-site': ['left palm']}, **kwargs)
api.taxa_abundance_bar_plot(qzv_file, ax=ax3, artist_kwargs=artist_kwargs3, include_samples={'body-site': ['right palm']}, **kwargs)
api.taxa_abundance_bar_plot(qzv_file, ax=ax4, artist_kwargs=artist_kwargs4, include_samples={'body-site': ['tongue']}, **kwargs)
api.taxa_abundance_bar_plot(qzv_file, ax=ax5, artist_kwargs=artist_kwargs5, **kwargs)

plt.tight_layout()

We can select specific samples with sample_names. We can also manually set the x-axis tick labels with xticklabels. Finally, you can pick specific colors for the bars.

fig, [ax1, ax2, ax3] = plt.subplots(1, 3, figsize=(10, 5))

kwargs = dict(level=7, count=3, sample_names=['L2S382', 'L4S112'])

artist_kwargs1 = dict(show_legend=True, legend_short=True, legend_loc='upper right', title="sample_names=['L2S382', 'L4S112']")
artist_kwargs2 = dict(show_legend=True, legend_short=True, legend_loc='upper right', title="xticklabels=['A', 'B']", xticklabels=['A', 'B'])
artist_kwargs3 = dict(show_legend=True, legend_short=True, legend_loc='upper right', title="colors=['tab:blue', 'tab:orange', 'tab:gray']")

api.taxa_abundance_bar_plot(qzv_file, ax=ax1, artist_kwargs=artist_kwargs1, **kwargs)
api.taxa_abundance_bar_plot(qzv_file, ax=ax2, artist_kwargs=artist_kwargs2, **kwargs)
api.taxa_abundance_bar_plot(qzv_file, ax=ax3, artist_kwargs=artist_kwargs3, colors=['tab:blue', 'tab:orange', 'tab:gray'], **kwargs)

plt.tight_layout()

taxa_abundance_box_plot

taxa_abundance_box_plot(taxa, hue=None, hue_order=None, add_datapoints=False, level=1, by=None, ax=None, figsize=None, count=0, exclude_samples=None, include_samples=None, exclude_taxa=None, sort_by_names=False, sample_names=None, csv_file=None, size=5, pseudocount=False, taxa_names=None, brief_xlabels=False, show_means=False, meanprops=None, show_others=True, sort_by_mean=True, artist_kwargs=None)
    This method creates a taxa abundance box plot.
    
    Parameters
    ----------
    taxa : str or qiime2.Visualization
        Visualization file or object from the q2-taxa plugin.
    hue : str, optional
        Grouping variable that will produce boxes with different colors.
    hue_order : list, optional
        Specify the order of categorical levels of the 'hue' semantic.
    add_datapoints : bool, default: False
        Show datapoints on top of the boxes.
    level : int, default: 1
        Taxonomic level at which the features should be collapsed.
    by : list, optional
        Column name(s) to be used for sorting the samples. Using 'index' will 
        sort the samples by their name, in addition to other column name(s) 
        that may have been provided. If multiple items are provided, sorting 
        will occur by the order of the items.
    ax : matplotlib.axes.Axes, optional
        Axes object to draw the plot onto, otherwise uses the current Axes.
    figsize : tuple, optional
        Width, height in inches. Format: (float, float).
    count : int, default: 0
        The number of taxa to display. When 0, display all.
    exclude_samples : dict, optional
        Filtering logic used for sample exclusion.
        Format: {'col': ['item', ...], ...}.
    include_samples : dict, optional
        Filtering logic used for sample inclusion.
        Format: {'col': ['item', ...], ...}.
    exclude_taxa : list, optional
        The taxa names to be excluded when matched. Case insenstivie.
    sort_by_names : bool, default: False
        If true, sort the columns (i.e. species) to be displayed by name.
    sample_names : list, optional
        List of sample IDs to be included.
    csv_file : str, optional
        Path of the .csv file to output the dataframe to.
    size : float, default: 5.0
        Radius of the markers, in points.
    pseudocount : bool, default: False
        Add pseudocount to remove zeros.
    taxa_names : list, optional
        List of taxa names to be displayed.
    brief_xlabels : bool, default: False
        If true, only display the smallest taxa rank in the x-axis labels.
    show_means : bool, default: False
        Add means to the boxes.
    meanprops : dict, optional
        The meanprops argument as in matplotlib.pyplot.boxplot.
    show_others : bool, default: True
        Include the 'Others' category.
    sort_by_mean : bool, default: True
        Sort taxa by their mean relative abundance after sample filtration.
    artist_kwargs : dict, optional
        Keyword arguments passed down to the _artist() method.
    
    Returns
    -------
    matplotlib.axes.Axes
        Returns the Axes object with the plot drawn onto it.
    
    See Also
    --------
    taxa_abundance_bar_plot
    addpairs
    
    Notes
    -----
    Example usage of the q2-taxa plugin:
        CLI -> qiime taxa barplot [OPTIONS]
        API -> from qiime2.plugins.taxa.visualizers import barplot

Below is a simple example showing taxonomic abundance at the phylum level (i.e. level=2).

qzv_file = 'data/moving-pictures-tutorial/taxa-bar-plots.qzv'

api.taxa_abundance_box_plot(qzv_file, level=2)

plt.tight_layout()

taxa_abundance_box_plot-1C

We can control how many taxa to display with count. Also, we can make the x-axis tick labels pretty with brief_xlabels. We can manually set the x-axis tick labels with xticklabels. Lastly, we can select specific taxa to display with taxa_names.

fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(10, 10))

kwargs = {'level' : 2}

artist_kwargs1 = dict(title='count=4')
artist_kwargs2 = dict(title='brief_xlabels=True')
artist_kwargs3 = dict(xticklabels=['A', 'B', 'C', 'D'], title="xticklabels=['A', 'B', 'C', 'D']")
artist_kwargs4 = dict(title="taxa_names=[...]")

api.taxa_abundance_box_plot(qzv_file, ax=ax1, count=4, artist_kwargs=artist_kwargs1, **kwargs)
api.taxa_abundance_box_plot(qzv_file, ax=ax2, count=4, brief_xlabels=True, artist_kwargs=artist_kwargs2, **kwargs)
api.taxa_abundance_box_plot(qzv_file, ax=ax3, count=4, artist_kwargs=artist_kwargs3, **kwargs)
api.taxa_abundance_box_plot(qzv_file, ax=ax4, taxa_names=['k__Bacteria;p__Firmicutes', 'k__Bacteria;p__Proteobacteria'], artist_kwargs=artist_kwargs4, **kwargs)

plt.tight_layout()

We can group the boxes by a metadata column with hue. For this plot, we will draw the y-axis in log scale with ylog. To do this, we actually need to adjust the y-axis limits with ymin and ymax, and also add a pseudocount of 1 to remove 0s with pseudocount (because 0s cannot be shown in log scale). We will also add data points with add_datapoints=True.

artist_kwargs = dict(ylog=True, ymin=0.05, ymax=200, show_legend=True)

api.taxa_abundance_box_plot(qzv_file,
                            level=2,
                            figsize=(10, 7),
                            hue='body-site',
                            size=3,
                            count=4,
                            pseudocount=True,
                            add_datapoints=True,
                            artist_kwargs=artist_kwargs)

plt.tight_layout()

ancom_volcano_plot

ancom_volcano_plot(ancom, ax=None, figsize=None, artist_kwargs=None)
    This method creates an ANCOM volcano plot.
    
    Parameters
    ----------
    ancom : str
        Visualization file or object from the q2-composition plugin.
    ax : matplotlib.axes.Axes, optional
        Axes object to draw the plot onto, otherwise uses the current Axes.
    figsize : tuple, optional
        Width, height in inches. Format: (float, float).
    artist_kwargs : dict, optional
        Keyword arguments passed down to the _artist() method.
    
    Returns
    -------
    matplotlib.axes.Axes
        Returns the Axes object with the plot drawn onto it.
    
    Notes
    -----
    Example usage of the q2-composition plugin:
        CLI -> qiime composition ancom [OPTIONS]
        API -> from qiime2.plugins.composition.visualizers import ancom

Below is a simple example.

api.ancom_volcano_plot('data/moving-pictures-tutorial/ancom-subject.qzv', figsize=(8, 5))

plt.tight_layout()

ancom_volcano_plot-1A

Other Plotting Methods

addsig

addsig(x1, x2, y, t='', h=1.0, lw=1.0, lc='black', tc='black', ax=None, figsize=None)
    This method adds signifiance annotation between two groups in a box plot.
    
    Parameters
    ----------
    x1 : float
        Position of the first box.
    x2 : float
        Position of the second box.
    y : float
        Bottom position of the drawing.
    t : str, default: ''
        Text.
    h : float, default: 1.0
        Height of the drawing.
    lw : float, default: 1.0
        Line width.
    lc : str, default: 'black'
        Line color.
    tc : str, default: 'black'
        Text color.
    ax : matplotlib.axes.Axes, optional
        Axes object to draw the plot onto, otherwise uses the current Axes.
    figsize : tuple, optional
        Width, height in inches. Format: (float, float).
    
    Returns
    -------
    matplotlib.axes.Axes
        Returns the Axes object with the plot drawn onto it.

Below is a simple example.

ax = api.alpha_diversity_plot('data/moving-pictures-tutorial/faith-pd-group-significance.qzv',
                              'body-site',
                              figsize=(8, 5),
                              artist_kwargs=dict(ymin=0, ymax=25))

api.addsig(0, 1, 20, t='***', ax=ax)
api.addsig(1, 2, 22, t='ns', ax=ax)

plt.tight_layout()

addsig-1A

addpairs

addpairs(taxon, csv_file, subject, category, group1, group2, p1=-0.2, p2=0.2, ax=None, figsize=None)
    This method adds lines between two groups in a plot generated by the 
    taxa_abundance_box_plot() method.
    
    This method also prints the p-value for Wilcoxon signed-rank test.
    
    Parameters
    ----------
    taxon : str
        Target taxon name.
    csv_file : str
        Path to csv file.
    subject : str
        Column name to indicate pair information.
    category : str
        Column name to be studied.
    group1 : str
        First group in the category column.
    group2 : str
        Second group in the category column.
    p1 : float, default: -0.2
        Start position of the lines.
    p2 : float, default: 0.2
        End position of the lines.
    ax : matplotlib.axes.Axes, optional
        Axes object to draw the plot onto, otherwise uses the current Axes.
    figsize : tuple, optional
        Width, height in inches. Format: (float, float).
    
    Returns
    -------
    matplotlib.axes.Axes
        Returns the Axes object with the plot drawn onto it.
    
    See Also
    --------
    taxa_abundance_box_plot

Below is a simple example where we pretend we only have the samples shown below. We are interested in comparing the relative abundance of Preteobacteria between the left palm and the right palm. We also want to perofrm the comparison in the context of days-since-experiment-start (i.e. paired comparison).

from qiime2 import Metadata

metadata = Metadata.load('data/moving-pictures-tutorial/sample-metadata.tsv')
sample_names = ['L2S240', 'L3S242', 'L2S155', 'L4S63', 'L2S175', 'L3S313', 'L2S204', 'L4S112', 'L2S222', 'L4S137']
metadata = metadata.filter_ids(sample_names)
mf = api.get_mf(metadata)
mf
barcode-sequence body-site year month day subject reported-antibiotic-usage days-since-experiment-start
sample-id
L2S155 ACGATGCGACCA left palm 2009.0 1.0 20.0 subject-1 No 84.0
L2S175 AGCTATCCACGA left palm 2009.0 2.0 17.0 subject-1 No 112.0
L2S204 ATGCAGCTCAGT left palm 2009.0 3.0 17.0 subject-1 No 140.0
L2S222 CACGTGACATGT left palm 2009.0 4.0 14.0 subject-1 No 168.0
L3S242 ACAGTTGCGCGA right palm 2008.0 10.0 28.0 subject-1 Yes 0.0
L3S313 AGTGTCACGGTG right palm 2009.0 2.0 17.0 subject-1 No 112.0
L2S240 CATATCGCAGTT left palm 2008.0 10.0 28.0 subject-2 Yes 0.0
L4S63 CTCGTGGAGTAG right palm 2009.0 1.0 20.0 subject-2 No 84.0
L4S112 GCGTTACACACA right palm 2009.0 3.0 17.0 subject-2 No 140.0
L4S137 GAACTGTATCTC right palm 2009.0 4.0 14.0 subject-2 No 168.0
qzv_file = 'data/moving-pictures-tutorial/taxa-bar-plots.qzv'


ax = api.taxa_abundance_box_plot(qzv_file,
                                 level=2,
                                 hue='body-site',
                                 taxa_names=['k__Bacteria;p__Proteobacteria'],
                                 show_others=False,
                                 figsize=(6, 6),
                                 sample_names=sample_names,
                                 add_datapoints=True,
                                 include_samples={'body-site': ['left palm', 'right palm']},
                                 csv_file='output/Dokdo-API/addpairs.csv',
                                 artist_kwargs=dict(show_legend=True, ymax=70))

plt.tight_layout()
api.addpairs('k__Bacteria;p__Proteobacteria', 'output/Dokdo-API/addpairs.csv', 'days-since-experiment-start', 'body-site', 'left palm', 'right palm', ax=ax)
api.addsig(-0.2, 0.2, 65, t='p-value = 0.0625', ax=ax)

addpairs-1C

8 Likes

Hi! Thank you for an excellent tutorial!
It would be nice to have it earlier when I was redrawing a lot of figures from Qiime2 in Python and Jupyter lab :laughing:
Will save it for the future

4 Likes

Hi @sbslee, this is really neat! :desktop_computer:

Thank you so much for sharing this with the :qiime2: community!

3 Likes

Hello! This is just to announce that a new version of Dokdo is available (1.1.0). The tutorial has been updated to reflect the changes as well. If you have any questions, please let me know.

4 Likes