Example #1
0
def CladeRecursive(cell, a: list, censor: bool, color: bool):
    """ A recurssive function that takes in the root cell and traverses through cells to plot the lineage.
    The width of the lines show the phase of the cells.
    The color of the lines show the state of the cells.

    "a" should be: a = [Clade(lineage1.full_lineage[0].obs[2]+lineage1.full_lineage[0].obs[3])] which is the root cell
    The following is the source code used to create Clades manually:
    https://github.com/biopython/biopython/blob/fce4b11b4b8e414f1bf093a76e04a3260d782905/Bio/Phylo/BaseTree.py#L801
    """
    if color:
        if np.isfinite(cell.state):
            colorr = stateColors[cell.state]
        else:
            # in case that the cells we wish to plot, have not been assigned any states.
            colorr = "black"
    else:
        colorr = "black"

    if cell.isLeaf() and censor:
        if np.isfinite(cell.obs[2]) and np.isfinite(cell.obs[3]):
            length = cell.obs[2] + cell.obs[3]
        elif np.isnan(cell.obs[2]):
            length = cell.obs[3]
        elif np.isnan(cell.obs[3]):
            length = cell.obs[2]
        # Creating the clade and assigning the color
        my_clade = Clade(branch_length=length, width=1, color=colorr)
        # Assigning the line width according to the phase
        my_clade.G1lw = 2.0
        my_clade.G2lw = 1.0
        my_clade.G1 = cell.obs[2] if np.isfinite(cell.obs[2]) else 1e-4
        my_clade.G2 = cell.obs[3] if np.isfinite(cell.obs[3]) else 1e-4
        return my_clade

    else:
        clades = []
        if cell.left is not None and cell.left.observed:
            clades.append(CladeRecursive(cell.left, a, censor, color))
        if cell.right is not None and cell.right.observed:
            clades.append(CladeRecursive(cell.right, a, censor, color))
        if np.isnan(cell.obs[3]):  # if the cell got stuck in G1
            lengths = cell.obs[2]
        elif np.isnan(cell.obs[2]):  # is a root parent and G1 is not observed
            lengths = cell.obs[3]
        else:
            lengths = cell.obs[2] + cell.obs[3]  # both are observed
        my_clade = Clade(branch_length=lengths, width=1, clades=clades, color=colorr)
        my_clade.G1lw = 2.0
        my_clade.G2lw = 1.0
        my_clade.G1 = cell.obs[2] if np.isfinite(cell.obs[2]) else 1e-4
        my_clade.G2 = cell.obs[3] if np.isfinite(cell.obs[3]) else 1e-4
        return my_clade
Example #2
0
def CladeRecursive_MCF10A(cell, a: list, censor: bool, color: bool):
    """ A recurssive function that takes in the root cell and traverses through cells to plot the lineage.
    The width of the lines show the phase of the cells.
    The color of the lines show the state of the cells.

    "a" should be: a = [Clade(lineage1.full_lineage[0].obs[1])] which is the root cell
    """
    if color:
        if np.isfinite(cell.state):
            colorr = stateColors[cell.state]
        else:
            # in case that the cells we wish to plot, have not been assigned any states.
            colorr = "black"
    else:
        colorr = "black"

    if cell.isLeaf():
        length = cell.obs[1]
        # Creating the clade and assigning the color
        my_clade = Clade(branch_length=length, width=1, color=colorr)
        # Assigning the line width according to the phase
        my_clade.G1lw = 1.0
        my_clade.G2lw = 1.0
        my_clade.G1 = cell.obs[1]
        my_clade.G2 = 1e-4
        return my_clade
    else:
        clades = []
        if cell.left is not None and cell.left.observed:
            clades.append(CladeRecursive_MCF10A(cell.left, a, censor, color))
        if cell.right is not None and cell.right.observed:
            clades.append(CladeRecursive_MCF10A(cell.right, a, censor, color))
        lengths = cell.obs[1]
        my_clade = Clade(branch_length=lengths, width=1, clades=clades, color=colorr)
        my_clade.G1lw = 1.0
        my_clade.G2lw = 1.0
        my_clade.G1 = cell.obs[1]
        my_clade.G2 = 1e-4
        return my_clade