@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')