lama/qc/organ_vol_plots.py
def pvalue_dist_plots(null: pd.DataFrame, alt: pd.DataFrame, thresholds: pd.DataFrame, outdir: Path):
    """
    Generate a series of histograms containing null and alternative distribution overlaid.
    Create a vertical line where the p-value threshold was set

    Parameters
    ----------
    null, alt
        each column shoul dbe a label number. Each row a p-value from a single permutation test
    thresholds
        index: label (number)
        must also have column 'p_thresh'
    outdir
        where to put the plots
    """

    def hist(values: pd.Series):
        # Drop NA values as they may exist if they have been QC'd out
        values.dropna(inplace=True)
        hist, bins = np.histogram(values, 100)
        hist = hist / np.sum(hist)
        width = 1.0 * (bins[1] - bins[0])
        center = (bins[:-1] + bins[1:]) / 2
        plt.bar(center, hist, align='center', width=width, alpha=0.5)

    x_label = 'log(p)'
    alt = np.log(alt)
    null = np.log(null)

    for col in alt:
        try:
            thresh = thresholds.loc[int(col), 'p_thresh']
            log_thresh = np.log(thresh)

            hist(alt[col])
            hist(null[col])
            plt.xlabel(x_label)

            outpath = outdir / f'{col}.png'

            plt.axvline(log_thresh, 0, 1, alpha=0.4, color='g')

            plt.legend(labels=['p threshold = {}'.format(format(thresh, '.3g')), 'alt', 'null'])
            plt.ylabel('Density')
            plt.title(col)
            plt.savefig(outpath)
            plt.close()
        except ValueError as e:
            logging.warn(f'Skipping pvalue dist plot for {col}')
            continue

    Generate a series of histograms containing null and alternative distribution overlaid.
    Create a vertical line where the p-value threshold was set

    Parameters
    ----------
    null, alt
        each column shoul dbe a label number. Each row a p-value from a single permutation test
    thresholds
        index: label (number)
        must also have column 'p_thresh'
    outdir
        where to put the plots
    
Generate a series of histograms containing null and alternative distribution overlaid.
Create a vertical line where the p-value threshold was set

Parameters

null, alt
each column shoul dbe a label number. Each row a p-value from a single permutation test
thresholds
index: label (number)
must also have column 'p_thresh'
outdir
where to put the plots
Generate a series of histograms containing null and alternative distribution overlaid . Create a vertical line where the p - value threshold was set Parameters null alt each column shoul dbe a label number . Each row a p - value from a single permutation test thresholds index : label ( number ) must also have column ' p_thresh ' outdir where to put the plots
def pvalue_dist_plots(null: pd.DataFrame, alt: pd.DataFrame, thresholds: pd.DataFrame, outdir: Path):
    def hist(values: pd.Series):
        values.dropna(inplace=True)
        hist, bins = np.histogram(values, 100)
        hist = hist / np.sum(hist)
        width = 1.0 * (bins[1] - bins[0])
        center = (bins[:-1] + bins[1:]) / 2
        plt.bar(center, hist, align='center', width=width, alpha=0.5)
    x_label = 'log(p)'
    alt = np.log(alt)
    null = np.log(null)
    for col in alt:
        try:
            thresh = thresholds.loc[int(col), 'p_thresh']
            log_thresh = np.log(thresh)
            hist(alt[col])
            hist(null[col])
            plt.xlabel(x_label)
            outpath = outdir / f'{col}.png'
            plt.axvline(log_thresh, 0, 1, alpha=0.4, color='g')
            plt.legend(labels=['p threshold = {}'.format(format(thresh, '.3g')), 'alt', 'null'])
            plt.ylabel('Density')
            plt.title(col)
            plt.savefig(outpath)
            plt.close()
        except ValueError as e:
            logging.warn(f'Skipping pvalue dist plot for {col}')
            continue
def pvalue_dist_plots ( null : pd . DataFrame , alt : pd . DataFrame , thresholds : pd . DataFrame , outdir : Path ) : def hist ( values : pd . Series ) : values . dropna ( inplace = True ) hist , bins = np . histogram ( values , 100 ) hist = hist / np . sum ( hist ) width = 1.0 * ( bins [ 1 ] - bins [ 0 ] ) center = ( bins [ : - 1 ] + bins [ 1 : ] ) / 2 plt . bar ( center , hist , align = 'center' , width = width , alpha = 0.5 ) x_label = 'log(p)' alt = np . log ( alt ) null = np . log ( null ) for col in alt : try : thresh = thresholds . loc [ int ( col ) , 'p_thresh' ] log_thresh = np . log ( thresh ) hist ( alt [ col ] ) hist ( null [ col ] ) plt . xlabel ( x_label ) outpath = outdir / f'{col}.png' plt . axvline ( log_thresh , 0 , 1 , alpha = 0.4 , color = 'g' ) plt . legend ( labels = [ 'p threshold = {}' . format ( format ( thresh , '.3g' ) ) , 'alt' , 'null' ] ) plt . ylabel ( 'Density' ) plt . title ( col ) plt . savefig ( outpath ) plt . close ( ) except ValueError as e : logging . warn ( f'Skipping pvalue dist plot for {col}' ) continue
Generate a series of histograms containing null and alternative distribution overlaid.
Generate a series of histograms containing null and alternative distribution overlaid .
"""
    Generate a series of histograms containing null and alternative distribution overlaid.
    Create a vertical line where the p-value threshold was set

    Parameters
    ----------
    null, alt
        each column shoul dbe a label number. Each row a p-value from a single permutation test
    thresholds
        index: label (number)
        must also have column 'p_thresh'
    outdir
        where to put the plots
    """ # Drop NA values as they may exist if they have been QC'd out
null
pd.DataFrame
alt
pd.DataFrame
thresholds
pd.DataFrame
outdir
Path