예제 #1
0
def plotModuleCorr(cyDf,
                   labels,
                   plotLabel,
                   sampleStr='M',
                   dropped=None,
                   compCommVar=None):
    """Make a corr plot for a module."""
    modDf = makeModuleVariables(cyDf[labels.index],
                                labels,
                                dropped=dropped,
                                sampleStr=sampleStr)
    modVar = '%s%s' % (sampleStr, plotLabel)
    cyVars = labels2modules(labels, dropped=None)[plotLabel]
    if not compCommVar is None:
        cyVars.append(compCommVar)
    tmpDf = cyDf[cyVars].join(modDf[modVar]).copy()
    """Rename dropped columns with an asterisk but leave them on the plot"""
    if not dropped is None:
        tmpDf.columns = np.array([
            c + '*' if c in dropped and dropped[c] else c
            for c in tmpDf.columns
        ])

    figh = plt.gcf()
    figh.clf()
    combocorrplot(tmpDf, method='pearson')
    axh = plt.gca()
    axh.annotate('%s%s' % (sampleStr, plotLabel),
                 xy=(0.5, 0.99),
                 xycoords='figure fraction',
                 va='top',
                 ha='center')
예제 #2
0
파일: io.py 프로젝트: liel-cohen/CytoMod
def plot_module_correl(clust_object, folder):
    """Plot intra-module correlation"""
    i = 0
    for lab in list(
            cy.labels2modules(clust_object.labels,
                              clust_object.dropped).keys()):
        plt.figure(50 + i, figsize=(15, 9))
        cyplot.plotModuleCorr(clust_object.cyDf,
                              clust_object.labels,
                              lab,
                              dropped=clust_object.dropped)
        plt.figure(50 + i).savefig(os.path.join(
            folder,
            '%s_modules_correlations_%s.png' % (clust_object.name, lab)),
                                   dpi=300)
        i += 1
예제 #3
0
파일: io.py 프로젝트: liel-cohen/CytoMod
def plot_modules(clust_object, folder):
    '''Plot cytomod object modules information'''
    """Hierarchical clustering heatmap"""
    plt.figure(41, figsize=(15.5, 9.5))
    # colInds = plotHColCluster(ds[s].cyDf, method='complete', metric='pearson-signed', col_labels=ds[s].labels, col_dmat=ds[s].dmatDf)
    colInds = plotHColCluster(clust_object.cyDf,
                              method='complete',
                              metric='pearson-signed',
                              col_labels=clust_object.labels,
                              save_path=os.path.join(
                                  folder, '%s_hierchical_clust_heatmap.png' %
                                  clust_object.name))
    # plt.figure(41).savefig(os.path.join(folder, '%s_hierchical_clust_heatmap.png' % clust_object.name))
    """Heatmaps of pairwise reliability"""
    plt.figure(43, figsize=(15.5, 9.5))
    colInds = cyplot.plotHierClust(1 - clust_object.pwrel,
                                   clust_object.Z,
                                   labels=clust_object.labels,
                                   titleStr='Pairwise reliability (%s)' %
                                   clust_object.name.replace('_', ' '),
                                   vRange=(0, 1))
    plt.figure(43).savefig(os.path.join(folder,
                                        '%s_pwrel.png' % clust_object.name),
                           dpi=300)
    """color_label_legend"""
    plt.figure(48, figsize=(3, 3))
    plt.clf()
    axh = plt.subplot(1, 1, 1)
    colorLegend(palettable.colorbrewer.qualitative.Set3_6.mpl_colors,
                ['%s' % s for s in clust_object.modDf.columns],
                loc=10)
    axh.spines['right'].set_color('none')
    axh.spines['left'].set_color('none')
    axh.spines['top'].set_color('none')
    axh.spines['bottom'].set_color('none')
    axh.set_xticks([])
    axh.set_yticks([])
    axh.set_facecolor('white')

    plt.figure(48).savefig(os.path.join(folder, 'color_label_legend.png'),
                           dpi=300)
    """Plot intra-module correlation"""
    plt.figure(50, figsize=(15, 9))
    for lab in list(
            cy.labels2modules(clust_object.labels,
                              clust_object.dropped).keys()):
        cyplot.plotModuleCorr(clust_object.cyDf,
                              clust_object.labels,
                              lab,
                              dropped=clust_object.dropped)
        plt.figure(50).savefig(os.path.join(
            folder, '%s_mod_corr_%s.png' % (clust_object.name, lab)),
                               dpi=300)
    """Cytokine embedding"""
    plt.figure(901, figsize=(13, 9.7))
    cyplot.plotModuleEmbedding(clust_object.dmatDf,
                               clust_object.labels,
                               method='kpca')
    colors = palettable.colorbrewer.get_map(
        'Set1', 'qualitative', len(np.unique(clust_object.labels))).mpl_colors
    colorLegend(colors, [
        '%s%1.0f' % (clust_object.sampleStr, i)
        for i in np.unique(clust_object.labels)
    ],
                loc='lower left')
    plt.figure(901).savefig(os.path.join(folder,
                                         '%sembed.png' % clust_object.name),
                            dpi=300)