figure.ubiquity_abundance_boxplots.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:microbiomeHD 作者: cduvallet 项目源码 文件源码
def plot_ubiq_abun_boxplot(tidy, metric, calculation):
    """
    Plot boxplot where x-axis is 'overall_significance' of genus, and values
    are either ubiquity or abundance in tidy (with the respective metric and
    calculation type)

    Parameters
    ----------
    tidy : pandas dataframe
        has columns overall_significance, value, patient, metric, and calculation
    metric : str
        'abundance' or 'ubiquity'
    calculation: str
        'from_pooled_mean' or 'mean_of_datasets'

    Returns
    -------
    ax : Axis object
    """
    fig, ax = plt.subplots(figsize=(5.5,4))
    tmp = tidy.query('metric == @metric')\
              .query('calculation == @calculation')\
              .query('patient == "total"')

    boxprops = {'edgecolor': 'k', 'facecolor': 'w'}
    lineprops = {'color': 'k'}

    # Plot log10(abundance)
    if metric == 'abundance':
        tmp.loc[tmp.index, 'value'] = tmp['value'].apply(np.log10)

    sns.boxplot(data=tmp, x='overall_significance', y='value',
                fliersize=0, ax=ax, color='w',
                order=['health', 'disease', 'mixed', 'not_sig'],
                **{'boxprops': boxprops, 'medianprops': lineprops,
                   'whiskerprops': lineprops, 'capprops': lineprops})

    sns.stripplot(data=tmp, x='overall_significance', y='value',
                  jitter=True, linewidth=0.6, split=True, ax=ax,
                  order=['health', 'disease', 'mixed', 'not_sig'],
                  color='w')
    return fig, ax
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号