Ejemplo n.º 1
0
def load_gexpressions(idList, labelList, percentage):
    os.getcwd()  #Para conocer el directorio actual
    # Connect to database to obtain data according to idList ids
    res = pa.runNorm(idList, 'webapp/[email protected]:1521')

    # convert data to proper dataframe
    cont = 0
    df = pd.DataFrame(index=res[cont].tolist())
    for i in labelList:
        cont += 1
        df[i] = res[cont].tolist()

    ## obtain unstable genes
    ngenes = int(df.index.size * percentage)
    unstable_genes = fs.findUnstable(df.values, ngenes)

    ## select unstable genes from dataframe to plot
    M = pd.DataFrame()
    for g in unstable_genes:
        M = pd.concat([M, df.iloc[[g]]])

    # transform to zscope in axis 1 (rows)
    dfzs1 = sst.zscore(M.values, axis=1, ddof=1)
    dfz = pd.DataFrame(index=M.index, data=dfzs1, columns=labelList)

    return dfz
Ejemplo n.º 2
0
def generate_heatmap(idList, labelList, percentage):

    path = os.getcwd()
    # Connect to database to obtain data according to idList ids
    res = pa.runNorm(idList, 'webapp/[email protected]:1521')

    # convert data to proper dataframe
    cont = 0
    df = pd.DataFrame(index=res[cont].tolist())
    for i in labelList:
        cont += 1
        df[i] = res[cont].tolist()

    ## obtain unstable genes
    ngenes = int(df.index.size * percentage)
    unstable_genes = fs.findUnstable(df.values, ngenes)

    ## select unstable genes from dataframe to plot
    M = pd.DataFrame()
    for g in unstable_genes:
        M = pd.concat([M, df.iloc[[g]]])

    # transform to zscope in axis 1 (rows)
    dfzs1 = sst.zscore(M.values, axis=1, ddof=1)
    dfz = pd.DataFrame(index=M.index, data=dfzs1, columns=labelList)

    # generate hetmap plot
    # add colored label
    #sns_plot = sns.clustermap(dfz, figsize=(len(labelList)/2, ngenes/2), cmap='viridis', metric="correlation", row_colors=row_colors)
    sns_plot = sns.clustermap(dfz,
                              figsize=(ngenes / 3, ngenes / 2),
                              cmap='viridis')

    #obtain time stamp
    ts = time.time()
    st = datetime.fromtimestamp(ts).strftime('%Y-%m-%d_%H%M%S')

    #save figure with hetmap
    figpath = path + "\\output_" + st + ".png"
    sns_plot.savefig(figpath)

    return figpath
Ejemplo n.º 3
0
df['E2'] = res[2].tolist()
df['E3'] = res[3].tolist()
df['E20'] = res[4].tolist()
df['E21'] = res[5].tolist()
df['E22'] = res[6].tolist()
df['E25'] = res[7].tolist()
df['E31'] = res[8].tolist()
df['E32'] = res[9].tolist()

sns.clustermap(df, figsize=(5, 100), cmap='viridis')

df.describe()

df.to_csv('dataset.csv')

unstable_genes = fs.findUnstable(df.values, 100)

M = pd.DataFrame()
for g in unstable_genes:
    M = pd.concat([M, df.iloc[[g]]])

sns.clustermap(M, figsize=(5, 50), cmap='viridis')

# =============================================================================
# df=pd.DataFrame(index=res[0].tolist(),data=sst.zscore(res[1],axis=0, ddof=1).tolist(),columns=['E1'])  # 1st row as the column names
# df['E2']=sst.zscore(res[2],axis=1, ddof=10).tolist()
# df['E3']=sst.zscore(res[3],axis=1, ddof=10).tolist()
# df['E20']=sst.zscore(res[4],axis=1, ddof=10).tolist()
# df['E21']=sst.zscore(res[5],axis=1, ddof=10).tolist()
# df['E22']=sst.zscore(res[6],axis=1, ddof=10).tolist()
# df['E25']=sst.zscore(res[7],axis=1, ddof=10).tolist()