Пример #1
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
Пример #2
0
def write_matrix(Arguments):
    '''
    Take any data that has been preprocessed (i.e., exists in your projects MOCA.data folder) and write a human 
    readable version to the current working directory. Useful if you need to load the matrices into a different utility, 
    tho why would anyone need to do that :) Also useful to load previously selected setworks back into MOCA for further
    optimization. You can also use the LabelList and FeatureList arguments to further customize what goes into these 
    matrices (that part is handled in the main DataHandler:load_data). 
    '''

    Data = load_data(Arguments)
    
    Labels = Data.Labels

    if set(Arguments.UntransformedData).difference(set(Arguments.Data)):
        print "It appears you have some datatypes passed to 'Untransformed = ' that you didn't load via 'Data ='."
        print "Only datatypes loaded via 'Data = ' can be written to matrix...transformed or not!"

    if set(Arguments.Data).difference(set(Arguments.UntransformedData)):
        Features = [Data.Transformed.Features[DataType] for DataType in Arguments.Data \
                    if DataType not in Arguments.UntransformedData]
        Variates = [Data.Transformed.Variates[DataType] for DataType in Arguments.Data \
                    if DataType not in Arguments.UntransformedData]
    
        Features = list(chain(*Features))
        Variates = list(chain(*Variates))
    
        CSVfile = open(Arguments.Filename + ".csv", "wb")
        CSVwriter = csv.writer(CSVfile, dialect='excel')
        CSVwriter.writerow(Labels)
        for Feature in Features:
             CSVwriter.writerow([Feature] + Variates[Features.index(Feature)])
        CSVfile.close()
        
    if Arguments.UntransformedData:
        Features = [Data.Features[DataType] for DataType in Arguments.Data \
                    if DataType in Arguments.UntransformedData]
        Variates = [Data.Variates[DataType] for DataType in Arguments.Data \
                    if DataType in Arguments.UntransformedData]
    
        Features = list(chain(*Features))
        Variates = list(chain(*Variates))

        CSVfile = open(Arguments.Filename + "_untransformed.csv", "wb")
        CSVwriter = csv.writer(CSVfile, dialect='excel')
        CSVwriter.writerow(Labels)
        for Feature in Features:
            CSVwriter.writerow([Feature] + Variates[Features.index(Feature)])
        CSVfile.close()
    
    return
Пример #3
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