Exemplo n.º 1
0
import sys
import numpy as np
import numpy.ma as ma
import matplotlib.pyplot as plt
import pdb
sys.path.insert(0, "../")
from Utils import util as ut

chro = "13"

struc = np.load(
    "../Generated_Structures/ipsc_missing_2_rep_1_eta_1000_alpha_0.6_lr_0.0001_epoch_400_res_50000_step_21_chro_"
    + str(chro) + ".npy")
real_map = ut.loadConstraintAsMat(
    "../Real_Data/iPluripotent/day_D2_rep_1_chro_" + str(chro))
struc_map = ut.struc2contacts(struc[4])
struc_map = np.clip(struc_map, 0, 10)
real_map = np.clip(real_map, 0, 30)
real_pear = ma.corrcoef(ma.masked_invalid(real_map))
struc_pear = ma.corrcoef(ma.masked_invalid(struc_map))

pca_real = PCA(n_components=1)
pca_struc = PCA(n_components=1)
ab_real = pca_real.fit_transform(real_pear)
ab_struc = pca_struc.fit_transform(struc_pear)
real_vec = np.squeeze(ab_real)
struc_vec = np.squeeze(ab_struc)

fig, ax = plt.subplots(3, 2)
ax[0, 0].imshow(np.clip(struc_map, 0, 10), cmap="Reds")
ax[0, 1].imshow(np.clip(real_map, 0, 30), cmap="Reds")
Exemplo n.º 2
0
for chro in chros:
    for missing, missing_time in zip(missings, missing_times):
        for day in days:
            print(str(chro), str(day), str(missing))
            #chro         = 3
            #day          = 'D2'
            #missing      = 2
            #missing_time = 4
            real_map = ut.loadConstraintAsMat(
                "../Real_Data/iPluripotent/day_" + str(day) + "_rep_1_chro_" +
                str(chro))
            struc = np.load(
                "../Generated_Structures/ipsc_missing_" + str(missing) +
                "_rep_1_eta_1000_alpha_0.6_lr_0.0001_epoch_400_res_50000_step_21_chro_"
                + str(chro) + ".npy")
            struc_map = ut.struc2contacts(struc[missing_time])

            #shrink to 100kb
            real_map_torch = torch.from_numpy(real_map)
            real_map_torch = real_map_torch.unsqueeze(0).unsqueeze(0)
            resized_real_map = torch.nn.functional.avg_pool2d(real_map_torch,
                                                              kernel_size=2)
            resized_real_map = resized_real_map.squeeze()
            real_map = resized_real_map.numpy()

            struc_map_torch = torch.from_numpy(struc_map)
            struc_map_torch = struc_map_torch.unsqueeze(0).unsqueeze(0)
            resized_struc_map = torch.nn.functional.avg_pool2d(struc_map_torch,
                                                               kernel_size=2)
            resized_struc_map = resized_struc_map.squeeze()
            struc_map = resized_struc_map.numpy()
Exemplo n.º 3
0
import numpy as np
import matplotlib.pyplot as plt
import numpy.ma as ma
import pdb
from sklearn.decomposition import PCA
import sys
sys.path.insert(0, "../")
import matplotlib.pyplot as plt
from Utils import util as ut
import sys

struc_file = sys.argv[1]
out_file = sys.argv[2]

start_time = time.time()
struc = np.load(struc_file)
AB_VEC = np.zeros((struc.shape[0], struc.shape[1]))

for i, ti in enumerate(range(0, struc.shape[0])):
    print("(" + str(i) + "/" + str(struc.shape[0]) + ")" + ":" +
          str(time.time() - start_time))
    struc_snap = struc[ti]
    contact = ut.struc2contacts(struc_snap)
    contact = np.clip(contact, 0, 10)
    pear = ma.corrcoef(ma.masked_invalid(contact))
    pca = PCA(n_components=1)
    AB = pca.fit_transform(pear)
    AB_VEC[i] = np.squeeze(AB)

np.save(out_file, AB_VEC)
Exemplo n.º 4
0
for chro in chros:
	for day in days:
		print(str(chro),str(day))
		real_map[day]    = ut.loadConstraintAsMat("../Real_Data/iPluripotent/day_"+str(day)+"_rep_1_chro_"+str(chro))
		real_map_torch   = torch.from_numpy(real_map[day])
		real_map_torch   = real_map_torch.unsqueeze(0).unsqueeze(0)
		resized_real_map = torch.nn.functional.avg_pool2d(real_map_torch, kernel_size=2)
		resized_real_map = resized_real_map.squeeze()
		real_map[day]    = resized_real_map.numpy()


	struc = np.load("../Generated_Structures/ipsc_full_rep_1_eta_1000_alpha_0.6_lr_0.0001_epoch_400_res_50000_step_21_chro_"+str(chro)+".npy")
	for struc_time in struc_times:
		print(str(chro), str(struc_time))
		struc_map[struc_time] = ut.struc2contacts(struc[struc_time])
		struc_map_torch        = torch.from_numpy(struc_map[struc_time])
		struc_map_torch        = struc_map_torch.unsqueeze(0).unsqueeze(0)
		resized_struc_map      = torch.nn.functional.avg_pool2d(struc_map_torch, kernel_size=2)
		resized_struc_map      = resized_struc_map.squeeze()
		struc_map[struc_time]  = resized_struc_map.numpy()
	
	#impute time
	not_valid = []
	for day in days:
		not_valid.extend(np.where(np.diagonal(real_map[day])==0)[0])
	for day in days:
		real_map[day]  = np.delete(np.delete(real_map[day], not_valid, axis=0), not_valid, axis=1)
	for struc_time in struc_times:
		struc_map[struc_time] = np.delete(np.delete(struc_map[struc_time], not_valid, axis=0), not_valid, axis=1)
	for day in days:
Exemplo n.º 5
0
import matplotlib.pyplot as plt
import numpy as np
import pdb
import sys
from Utils import util as ut

struc_name = sys.argv[1]
time = int(sys.argv[2])
ref_map = sys.argv[3]
res = int(sys.argv[4])

struc = np.load(struc_name)
mat = ut.struc2contacts(struc[time])

x = np.loadtxt(ref_map)
row = x[:, 0].astype(int)
col = x[:, 1].astype(int)
ifs = x[:, 2].astype(float)
row = (row / res).astype(int)
col = (col / res).astype(int)
real_mat = ut.constraints2mats(row, col, ifs)

pdb.set_trace()
plt.imshow(np.log(real_mat), cmap="Reds")
plt.show()