python/cell_cycle_gating/cellcycle_phases.py
def evaluate_cell_cycle_phase(log_dna, dna_gates, x_dna, 
                              log_edu, edu_gates, px_edu,
                              dna_peaks=None, edu_peaks=None,
                              nsmooth=5, ax=None):
    """Evaluates cell cycle phase of each cell based on gatings

    Parameters
    ----------
    log_dna : 1d array
        log DNA content across all cells in a well
    dna_gates : list of floats
        inner and outer gates defined by DNA content
    x_dna : 1d array
        uniformly spaced grid based on expected DNA content
    dna_peaks : list of floats
        G1, S and G2 peak locations
    log_edu : 1d array
        log EdU intensities across all cells in a well
    edu_gates : list of floats
        location of gates seperating S and G1/G2 based on EdU intensities
    px_edu : 1d array
        uniformly spaced grid based on expected EdU intensities
    edu_peaks : list of floats
        location of high and low edu peaks
    nsmooth : int
        smoothing parameter
    ax : subplot object
        provides positional reference for subplot in master summary plot
    
    Returns
    -------
    fractions : dict
        dictionary where keys are cell cycle phases and
        values are fractions of cells in each phase
    cell_id : 1d array
        membership of each cell in cell cycle phase (1=G1, 2=S, 3=G2)
    """
    cell_id = (1 * ((log_dna > dna_gates[0]) &  # G1
                    (log_dna < dna_gates[1]) &
                    (log_edu < edu_gates[0])) +
               2 * ((log_dna >= dna_gates[0]) &  # S
                    (log_dna < dna_gates[3]) &
                    (log_edu >= edu_gates[0])) +
                    #(log_edu < edu_gates[1])) +
               2.1 * ((log_dna >= dna_gates[1])  # S dropout
                      & (log_dna < dna_gates[2]) &
                      (log_edu < edu_gates[0])) +
               3 * ((log_dna >= dna_gates[2]) &  # G2
                    (log_dna < dna_gates[3]) &
                    (log_edu < edu_gates[0])) +
               0.5 * (log_dna < dna_gates[0]) +
               3.1 * (log_dna > dna_gates[3]))
    fractions = {}
    for state, val in zip(['subG1', 'G1', 'S', 'S_dropout', 'G2', 'beyondG2'],
                          [0.5, 1, 2, 2.1, 3, 3.1]):
        fractions[state] = np.mean(cell_id == (val % 4))

    if dna_peaks is not None:
        for ig in np.arange(1, 4):
            if sum(cell_id == ig) > 10:
                f_dna = get_kde(log_dna[cell_id == ig], x_dna)
                _, dna_loc, _ = findpeaks(
                    smooth.smooth(f_dna, 3 * nsmooth).tolist(),
                    npeaks=1)
                dna_peaks[ig-1] = x_dna[dna_loc]

                f_edu = get_kde(log_edu[cell_id == ig], px_edu)
                _, edu_loc, _ = findpeaks(
                    smooth.smooth(f_edu, 3 * nsmooth).tolist(),
                    npeaks=1)
                edu_peaks[ig-1] = px_edu[edu_loc]
            else:
                dna_peaks[ig-1] = np.mean(dna_gates[ig-1:2])
                edu_peaks[ig-1] = np.mean((edu_gates[0], (ig == 2)*edu_gates[1]))
            edu_peaks[1] = np.max((edu_peaks[1], edu_gates[0] + 0.1))
        peaks = [dna_peaks, edu_peaks]
    else:
        peaks = None
    if ax is not None:
        ax.pie(fractions.values(), labels=fractions.keys(),  autopct='%1.1f%%')
        ax.axis('equal')
    return fractions, cell_id, peaks
Evaluates cell cycle phase of each cell based on gatings

    Parameters
    ----------
    log_dna : 1d array
        log DNA content across all cells in a well
    dna_gates : list of floats
        inner and outer gates defined by DNA content
    x_dna : 1d array
        uniformly spaced grid based on expected DNA content
    dna_peaks : list of floats
        G1, S and G2 peak locations
    log_edu : 1d array
        log EdU intensities across all cells in a well
    edu_gates : list of floats
        location of gates seperating S and G1/G2 based on EdU intensities
    px_edu : 1d array
        uniformly spaced grid based on expected EdU intensities
    edu_peaks : list of floats
        location of high and low edu peaks
    nsmooth : int
        smoothing parameter
    ax : subplot object
        provides positional reference for subplot in master summary plot
    
    Returns
    -------
    fractions : dict
        dictionary where keys are cell cycle phases and
        values are fractions of cells in each phase
    cell_id : 1d array
        membership of each cell in cell cycle phase (1=G1, 2=S, 3=G2)
    
Evaluates cell cycle phase of each cell based on gatings
Parameters



Returns

fractions : dict
dictionary where keys are cell cycle phases and
values are fractions of cells in each phase
cell_id : 1d array
membership of each cell in cell cycle phase (1=G1, 2=S, 3=G2)
Evaluates cell cycle phase of each cell based on gatings Parameters Returns fractions : dict dictionary where keys are cell cycle phases and values are fractions of cells in each phase cell_id : 1d array membership of each cell in cell cycle phase ( 1 = G1 2 = S 3 = G2 )
def evaluate_cell_cycle_phase(log_dna, dna_gates, x_dna, 
                              log_edu, edu_gates, px_edu,
                              dna_peaks=None, edu_peaks=None,
                              nsmooth=5, ax=None):
    cell_id = (1 * ((log_dna > dna_gates[0]) &  
                    (log_dna < dna_gates[1]) &
                    (log_edu < edu_gates[0])) +
               2 * ((log_dna >= dna_gates[0]) &  
                    (log_dna < dna_gates[3]) &
                    (log_edu >= edu_gates[0])) +
               2.1 * ((log_dna >= dna_gates[1])   dropout
                      & (log_dna < dna_gates[2]) &
                      (log_edu < edu_gates[0])) +
               3 * ((log_dna >= dna_gates[2]) &  
                    (log_dna < dna_gates[3]) &
                    (log_edu < edu_gates[0])) +
               0.5 * (log_dna < dna_gates[0]) +
               3.1 * (log_dna > dna_gates[3]))
    fractions = {}
    for state, val in zip(['subG1', 'G1', 'S', 'S_dropout', 'G2', 'beyondG2'],
                          [0.5, 1, 2, 2.1, 3, 3.1]):
        fractions[state] = np.mean(cell_id == (val % 4))
    if dna_peaks is not None:
        for ig in np.arange(1, 4):
            if sum(cell_id == ig) > 10:
                f_dna = get_kde(log_dna[cell_id == ig], x_dna)
                _, dna_loc, _ = findpeaks(
                    smooth.smooth(f_dna, 3 * nsmooth).tolist(),
                    npeaks=1)
                dna_peaks[ig-1] = x_dna[dna_loc]
                f_edu = get_kde(log_edu[cell_id == ig], px_edu)
                _, edu_loc, _ = findpeaks(
                    smooth.smooth(f_edu, 3 * nsmooth).tolist(),
                    npeaks=1)
                edu_peaks[ig-1] = px_edu[edu_loc]
            else:
                dna_peaks[ig-1] = np.mean(dna_gates[ig-1:2])
                edu_peaks[ig-1] = np.mean((edu_gates[0], (ig == 2)*edu_gates[1]))
            edu_peaks[1] = np.max((edu_peaks[1], edu_gates[0] + 0.1))
        peaks = [dna_peaks, edu_peaks]
    else:
        peaks = None
    if ax is not None:
        ax.pie(fractions.values(), labels=fractions.keys(),  autopct='%1.1f%%')
        ax.axis('equal')
    return fractions, cell_id, peaks
def evaluate_cell_cycle_phase ( log_dna , dna_gates , x_dna , log_edu , edu_gates , px_edu , dna_peaks = None , edu_peaks = None , nsmooth = 5 , ax = None ) : cell_id = ( 1 * ( ( log_dna > dna_gates [ 0 ] ) & ( log_dna < dna_gates [ 1 ] ) & ( log_edu < edu_gates [ 0 ] ) ) + 2 * ( ( log_dna >= dna_gates [ 0 ] ) & ( log_dna < dna_gates [ 3 ] ) & ( log_edu >= edu_gates [ 0 ] ) ) + 2.1 * ( ( log_dna >= dna_gates [ 1 ] ) & ( log_dna < dna_gates [ 2 ] ) & ( log_edu < edu_gates [ 0 ] ) ) + 3 * ( ( log_dna >= dna_gates [ 2 ] ) & ( log_dna < dna_gates [ 3 ] ) & ( log_edu < edu_gates [ 0 ] ) ) + 0.5 * ( log_dna < dna_gates [ 0 ] ) + 3.1 * ( log_dna > dna_gates [ 3 ] ) ) fractions = { } for state , val in zip ( [ 'subG1' , 'G1' , 'S' , 'S_dropout' , 'G2' , 'beyondG2' ] , [ 0.5 , 1 , 2 , 2.1 , 3 , 3.1 ] ) : fractions [ state ] = np . mean ( cell_id == ( val % 4 ) ) if dna_peaks is not None : for ig in np . arange ( 1 , 4 ) : if sum ( cell_id == ig ) > 10 : f_dna = get_kde ( log_dna [ cell_id == ig ] , x_dna ) _ , dna_loc , _ = findpeaks ( smooth . smooth ( f_dna , 3 * nsmooth ) . tolist ( ) , npeaks = 1 ) dna_peaks [ ig - 1 ] = x_dna [ dna_loc ] f_edu = get_kde ( log_edu [ cell_id == ig ] , px_edu ) _ , edu_loc , _ = findpeaks ( smooth . smooth ( f_edu , 3 * nsmooth ) . tolist ( ) , npeaks = 1 ) edu_peaks [ ig - 1 ] = px_edu [ edu_loc ] else : dna_peaks [ ig - 1 ] = np . mean ( dna_gates [ ig - 1 : 2 ] ) edu_peaks [ ig - 1 ] = np . mean ( ( edu_gates [ 0 ] , ( ig == 2 ) * edu_gates [ 1 ] ) ) edu_peaks [ 1 ] = np . max ( ( edu_peaks [ 1 ] , edu_gates [ 0 ] + 0.1 ) ) peaks = [ dna_peaks , edu_peaks ] else : peaks = None if ax is not None : ax . pie ( fractions . values ( ) , labels = fractions . keys ( ) , autopct = '%1.1f%%' ) ax . axis ( 'equal' ) return fractions , cell_id , peaks
Evaluates cell cycle phase of each cell based on gatings
Parameters
Evaluates cell cycle phase of each cell based on gatings Parameters
"""Evaluates cell cycle phase of each cell based on gatings

    Parameters
    ----------
    log_dna : 1d array
        log DNA content across all cells in a well
    dna_gates : list of floats
        inner and outer gates defined by DNA content
    x_dna : 1d array
        uniformly spaced grid based on expected DNA content
    dna_peaks : list of floats
        G1, S and G2 peak locations
    log_edu : 1d array
        log EdU intensities across all cells in a well
    edu_gates : list of floats
        location of gates seperating S and G1/G2 based on EdU intensities
    px_edu : 1d array
        uniformly spaced grid based on expected EdU intensities
    edu_peaks : list of floats
        location of high and low edu peaks
    nsmooth : int
        smoothing parameter
    ax : subplot object
        provides positional reference for subplot in master summary plot
    
    Returns
    -------
    fractions : dict
        dictionary where keys are cell cycle phases and
        values are fractions of cells in each phase
    cell_id : 1d array
        membership of each cell in cell cycle phase (1=G1, 2=S, 3=G2)
    """ # G1 # S #(log_edu < edu_gates[1])) + # S dropout # G2
log_dna
dna_gates
x_dna
log_edu
edu_gates
px_edu
dna_peaks
edu_peaks
nsmooth
ax