Beispiel #1
0
def get_rowsidematrix(Features, Arguments):
    '''
    '''

    GrayScale = {
        -9: "gray10",
        -8: "gray20",
        -7: "gray30",
        -6: "gray40",
        -5: "gray50",
        -4: "gray60",
        -3: "gray70",
        -2: "gray80"
    }

    Matrix = dict([(Row.split()[0], Row.split()[1])
                   for Row in file(get_path("RowSideColors"))])

    PValues = []
    for Feature in Features:
        PValues.append(Matrix[Feature])

    Label = ["Mesenchymal"]
    Variates = [
        int(("%0.2e" % float(PValue)).split("e")[1]) for PValue in PValues
    ]
    Variates = [
        "black" if Variate <= -10 else
        ("white" if Variate >= -1 else GrayScale[Variate])
        for Variate in Variates
    ]

    return string_matrix(Features, Label, [Variates], Arguments)
Beispiel #2
0
def heatmap(Arguments):
    '''
    '''

    Data = load_data(Arguments)
    if Arguments.OrderBy: Data = reorder_data(Data, Arguments)

    #This is specifically the part you want plotted on the heatmap, NOT the sidebars
    Features, Variates = get_heatmap_data(Data, Arguments)
    Features = [Feature[:Feature.index(":")] for Feature in Features]

    ClusteredMatrix = ro.r["hierarchical_cluster_distance_matrix"](
        float_matrix(Data.Labels, Features, Variates, Arguments))
    Columns = list(ClusteredMatrix.colnames)
    Rows = list(ClusteredMatrix.rownames)
    Matrix = np.array(ClusteredMatrix)

    ZMatrix = z_matrix(Matrix)
    ColorPalette = list(ro.r["colorRampPalette"](ro.StrVector(
        ["blue", "white", "red"]))(100))
    ColorMatrix = [float2color(Vector, ColorPalette) for Vector in ZMatrix]
    exit()

    Heatmap = float_matrix(Data.Labels, Features, Variates, Arguments)

    Legend = False  #overwrite if ColSideColors is called

    if "colsidecolors" in [Option.lower() for Option in Arguments.Heatmap]:
        ColorFeatures, ColSideMatrix, Legend = get_colsidematrix(
            Data, Arguments)
        ColSideMatrix = transpose_matrix(
            string_matrix(Data.Labels, ColorFeatures, ColSideMatrix,
                          Arguments))
    else:
        ColSideMatrix = False

    if "rowsidecolors" in [Option.lower() for Option in Arguments.Heatmap]:
        RowSideMatrix = get_rowsidematrix(Features, Arguments)
    else:
        RowSideMatrix = False

    ro.r['pdf'](Arguments.Filename + '.pdf')
    if Legend: ro.r['par'](mar=ro.IntVector([1, 1, 1, 1]))
    ro.r['par'](**{'cex.axis': 0.8})
    get_heatmap(Heatmap,
                ColSideMatrix=ColSideMatrix,
                RowSideMatrix=RowSideMatrix,
                Legend=Legend)
    ro.r['dev.off']()

    return
Beispiel #3
0
def get_rowsidematrix(Features, Arguments):
    '''
    '''
    
    GrayScale = {-9:"gray10", -8:"gray20", -7:"gray30", -6:"gray40", -5:"gray50", -4:"gray60", -3:"gray70", -2:"gray80"}

    Matrix = dict([(Row.split()[0], Row.split()[1]) for Row in file(get_path("RowSideColors"))])
    
    PValues = []
    for Feature in Features:
        PValues.append(Matrix[Feature])

    Label = ["Mesenchymal"]
    Variates = [int(("%0.2e" %float(PValue)).split("e")[1]) for PValue in PValues]
    Variates = ["black" if Variate <= -10 else ("white" if Variate >= -1 else GrayScale[Variate]) for Variate in Variates]

    return string_matrix(Features, Label, [Variates], Arguments)
Beispiel #4
0
def heatmap(Arguments):
    '''
    '''

    Data = load_data(Arguments)
    if Arguments.OrderBy: Data = reorder_data(Data, Arguments)

    #This is specifically the part you want plotted on the heatmap, NOT the sidebars
    Features, Variates = get_heatmap_data(Data, Arguments)
    Features = [Feature[:Feature.index(":")] for Feature in Features]

    ClusteredMatrix = ro.r["hierarchical_cluster_distance_matrix"](float_matrix(Data.Labels, Features, Variates, Arguments))
    Columns = list(ClusteredMatrix.colnames)
    Rows = list(ClusteredMatrix.rownames)
    Matrix = np.array(ClusteredMatrix)
    
    ZMatrix = z_matrix(Matrix)
    ColorPalette = list(ro.r["colorRampPalette"](ro.StrVector(["blue", "white", "red"]))(100))
    ColorMatrix = [float2color(Vector, ColorPalette) for Vector in ZMatrix]
    exit()
    
    Heatmap = float_matrix(Data.Labels, Features, Variates, Arguments)
    
    Legend = False #overwrite if ColSideColors is called

    if "colsidecolors" in [Option.lower() for Option in Arguments.Heatmap]:
        ColorFeatures, ColSideMatrix, Legend = get_colsidematrix(Data, Arguments)
        ColSideMatrix = transpose_matrix(string_matrix(Data.Labels, ColorFeatures, ColSideMatrix, Arguments))
    else:
        ColSideMatrix = False

    if "rowsidecolors" in [Option.lower() for Option in Arguments.Heatmap]:
        RowSideMatrix = get_rowsidematrix(Features, Arguments)
    else:
        RowSideMatrix = False

    ro.r['pdf'](Arguments.Filename + '.pdf')
    if Legend: ro.r['par'](mar=ro.IntVector([1,1,1,1]))
    ro.r['par'](**{'cex.axis':0.8})
    get_heatmap(Heatmap, ColSideMatrix=ColSideMatrix, RowSideMatrix=RowSideMatrix, Legend=Legend)
    ro.r['dev.off']()
    
    return