|
a |
|
b/python-scripts/runSingleSVAE2.py |
|
|
1 |
from keras.layers import Input, Dense |
|
|
2 |
from keras.models import Model |
|
|
3 |
import numpy as np |
|
|
4 |
import pandas as pd |
|
|
5 |
import matplotlib.pyplot as plt |
|
|
6 |
from sklearn.cluster import KMeans |
|
|
7 |
from sklearn.cluster import k_means |
|
|
8 |
from sklearn.metrics import silhouette_score, davies_bouldin_score |
|
|
9 |
from sklearn.preprocessing import normalize |
|
|
10 |
import time |
|
|
11 |
from sklearn import metrics |
|
|
12 |
from myUtils import * |
|
|
13 |
from SVAEclass import VAE |
|
|
14 |
#from AEclass import AE |
|
|
15 |
import os |
|
|
16 |
|
|
|
17 |
if __name__ == '__main__': |
|
|
18 |
datapath = 'data/single-cell/' |
|
|
19 |
resultpath = 'result/single-cell/' |
|
|
20 |
# groundtruth = np.loadtxt('{}/c.txt'.format(datapath)) |
|
|
21 |
# groundtruth = list(np.int_(groundtruth)) |
|
|
22 |
|
|
|
23 |
omics = np.loadtxt('{}/omics.txt'.format(datapath)) |
|
|
24 |
omics = np.transpose(omics) |
|
|
25 |
omics1 = omics[0:206] |
|
|
26 |
omics2 = omics[206:412] |
|
|
27 |
omics1 = normalize(omics1, axis=0, norm='max') |
|
|
28 |
omics2 = normalize(omics2, axis=0, norm='max') |
|
|
29 |
#omics = np.concatenate((omics1, omics2), axis=1) |
|
|
30 |
|
|
|
31 |
encoding1_dim1 = 2048 |
|
|
32 |
encoding2_dim1 = 512 |
|
|
33 |
middle_dim1 = 1 |
|
|
34 |
dims1 = [encoding1_dim1, encoding2_dim1, middle_dim1] |
|
|
35 |
ae1 = VAE(omics1, dims1) |
|
|
36 |
ae1.train() |
|
|
37 |
ae1.autoencoder.summary() |
|
|
38 |
encoded_factor1 = ae1.predict(omics1) |
|
|
39 |
|
|
|
40 |
encoding1_dim2 = 2048 |
|
|
41 |
encoding2_dim2 = 512 |
|
|
42 |
middle_dim2 = 1 |
|
|
43 |
dims2 = [encoding1_dim2, encoding2_dim2, middle_dim2] |
|
|
44 |
ae2 = VAE(omics2, dims2) |
|
|
45 |
ae2.train() |
|
|
46 |
ae2.autoencoder.summary() |
|
|
47 |
encoded_factor2 = ae2.predict(omics2) |
|
|
48 |
|
|
|
49 |
|
|
|
50 |
encoded_factors = np.concatenate((encoded_factor1, encoded_factor2), axis=1) |
|
|
51 |
|
|
|
52 |
if not os.path.exists("{}/SVAE_FAETC_EM.txt".format(resultpath)): |
|
|
53 |
os.mknod("{}/SVAE_FAETC_EM.txt".format(resultpath)) |
|
|
54 |
np.savetxt("{}/SVAE_FAETC_EM.txt".format(resultpath), encoded_factors) |
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
|