how to convert qzv figure into pdf

Hello,

I am using Qiime2 2019.04 and like this very much.

But I am not able to understand how I can get the figure into a PDF from qzv file, I can view the figure in Qiime2view but it doesn't have an option for figure download just says download CSV file- where I can use that csv to get the figure in the PDF for publications?

Many thanks
Yogesh

1 Like

Hi! That's strange, usually it is easy to download .png file from .qzv. Can you attach the file from which you are not able to download the figure?

Thanks @timanix,

Like here in this link where is the option to download rarefaction figure as png?

https://view.qiime2.org/visualization/?type=html&src=https%3A%2F%2Fdocs.qiime2.org%2F2019.4%2Fdata%2Ftutorials%2Fmoving-pictures%2Falpha-rarefaction.qzv

Thanks
Yogesh

Yes, you are right, no .png file for rarefaction curve.

You can plot it in R, Python, or other suitable tool.
Python example on your data:

I can send you a code I used or write me a message witth columns in .csv file and metric to draw, and I will send you a figure back - it will not require a lot of work since all I need to adjust code I wrote earlier for my article.

1 Like

Hi @timanix,

could you please resend me the code on this email address: nabiyogesh@gmail.com

thanks
Yogesh

Hi @timanix,

I also have the same question as @Yogesh_Gupta does.
May I ask for the Python code too, if you don't mind?
If it's ok with you, I will PM you my email address.

Thank you so much

@fgara, @Yogesh_Gupta Yes, of course, I will send it today

1 Like

@fgara, @Yogesh_Gupta
Here is the code I used. Run it in Jupyter lab or Jupyter notebook, or adjust few things to run it elsewhere. Please, carefully inspect the output and compare the figure with one from Qiime2. In my case it was identical

#Run it in jupyter lab or notebook


import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd

%matplotlib inline 

qza = '/home/ty/Downloads/alpha-rarefaction.qzv' # path to rarefaction file from qiime2
a = !unzip $qza
digest = a[1].split('/')[0].replace('  inflating: ','')
inf = digest + '/data/observed_otus.csv'
otus = pd.read_csv(inf,index_col=0, sep=',')
!rm -r $digest 

cols = [col for col in otus.columns if 'iter' not in col]
mean,data = otus[cols],pd.DataFrame(columns=cols)
depths = [col.split('_')[0] for col in otus.columns if 'depth' in col]
otus = otus.drop(cols,axis=1)
otus.columns = depths
for depth in depths:
    mean['ASV'] = otus[depth].mean(axis=1)
    mean['depth']= depth.split('-')[-1]
    data = pd.concat([data,mean])
# here provide colors for each item that will be plotted
pal={'gut':'brown','left palm':'green','right palm':'blue','tongue':'red'} 
fig,ax = plt.subplots(figsize=(2.5,2),dpi=600,tight_layout=True)
sns.set(style='ticks',rc={"lines.linewidth":0.7,"axes.linewidth":0.5})
# use your column name to plot here instead of 'BodySite'
sns.lineplot(x='depth',y='ASV',data=data,palette=pal,hue='BodySite',sort=False,err_style='bars',\
             dashes=True,style='BodySite',ci=67)
ax.set_xlabel('Sequencing depth',fontsize=8)
ax.set_ylabel('Observed ASVs',fontsize=8)
ax.tick_params(axis='x', labelrotation=90)
ax.tick_params(axis='both',which='major',length=2,pad=0.5,labelsize=6)
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles=handles[1:],labels=labels[1:],fontsize=5,frameon=False,numpoints=4,borderaxespad=0,handletextpad=0.2,loc=2,)
plt.savefig('Infected_observed_ASVs.png', bbox_inches='tight')
3 Likes

Hi @timanix,
Thank you so much for this!
It's very kind of you :slight_smile:

1 Like

Hello @timanix,

I am getting an error while running the above script? I also loaded module for pandas and python on server.

code :

#!/usr/bin/env python

import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd

qza = 'alpha-rarefaction_20000.qzv' # path to rarefaction file from qiime2
a = !unzip $qza
digest = a[1].split('/')[0].replace('  inflating: ','')
inf = digest + '/data/observed_otus.csv'
otus = pd.read_csv(inf,index_col=0, sep=',')
!rm -r $digest 

cols = [col for col in otus.columns if 'iter' not in col]
mean,data = otus[cols],pd.DataFrame(columns=cols)
depths = [col.split('_')[0] for col in otus.columns if 'depth' in col]
otus = otus.drop(cols,axis=1)
otus.columns = depths
for depth in depths:
    mean['ASV'] = otus[depth].mean(axis=1)
    mean['depth']= depth.split('-')[-1]
    data = pd.concat([data,mean])

# here provide colors for each item that will be plotted
pal={'Leaf':'brown','Root':'green','Soil':'blue'} 
fig,ax = plt.subplots(figsize=(2.5,2),dpi=600,tight_layout=True)
sns.set(style='ticks',rc={"lines.linewidth":0.7,"axes.linewidth":0.5})
# use your column name to plot here instead of 'BodySite'

sns.lineplot(x='depth',y='ASV',data=data,palette=pal,hue='Compartment',sort=False,err_style='bars',\
             dashes=True,style='BodySite',ci=67)
ax.set_xlabel('Sequencing depth',fontsize=8)
ax.set_ylabel('Observed ASVs',fontsize=8)
ax.tick_params(axis='x', labelrotation=90)
ax.tick_params(axis='both',which='major',length=2,pad=0.5,labelsize=6)
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles=handles[1:],labels=labels[1:],fontsize=5,frameon=False,numpoints=4,borderaxespad=0,handletextpad=0.2,loc=2,)
plt.savefig('rarefaction_ASVs.png', bbox_inches='tight')
**Error:**
**python rarefaction.plot.py**
**  File "rarefaction.plot.py", line 9**
**    a = !unzip $qza**
**        ^**
**SyntaxError: invalid syntax**

Many thanks
Yogesh

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