forked from d-vora/CRISP-RCNN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_img_from_seq.py
54 lines (43 loc) · 1.36 KB
/
generate_img_from_seq.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import numpy as np
from matplotlib import pyplot as plt
import pandas as pd
from tqdm import tqdm
def custom_onehot(arr):
img = np.zeros((len(arr),4))
for index, value in enumerate(arr):
if value=='-':
pass
elif value=='A':
img[index][0] = 1
elif value=='C':
img[index][1] = 1
elif value=='G':
img[index][2] = 1
elif value=='T':
img[index][3] = 1
else:
img[index][0:4] = 0.25
return img.T
#return img
def save_img(img,loc,i):
fig, ax = plt.subplots(figsize=(7,1))
ax.imshow(img, interpolation='none', cmap='Blues', aspect='auto')
plt.axis('off')
#plt.savefig('data/'+str(loc)+'_'+str(i+1)+'.png',bbox_inches = 'tight',pad_inches=0)
plt.savefig('moredata/'+str(loc)+'/'+str(loc)+'_'+str(i)+'.png',bbox_inches = 'tight',pad_inches=0)
plt.close(fig)
def make_images(df):
#start =
n,m = df.shape
off_list = df['N-padded off-target'].values
tar_list = df['N-padded target'].values
for i in tqdm(range(n)):
off = custom_onehot(np.array(list(off_list[i])))
save_img(off,'off',i)
tar = custom_onehot(np.array(list(tar_list[i])))
save_img(tar,'target',i)
#print (off,tar)
return None
data = pd.read_excel('dataset-SY.xlsx')
#small = data.head()
make_images(data)