import os
os.mkdir(r'C:\Users\zzz\Desktop\双聚类结果\matlab\col')
os.mkdir(r'C:\Users\zzz\Desktop\双聚类结果\matlab\row')
os.mkdir(r'C:\Users\zzz\Desktop\双聚类结果\matlab\result')
os.mkdir(r'C:\Users\zzz\Desktop\双聚类结果\matlab\result_replace')
os.mkdir(r'C:\Users\zzz\Desktop\双聚类结果\matlab\result_group')
nc1 = input("输入矩阵数量:")
nc2 = int(nc1) + 1
#读取行数据
i = 1
j = 1
fw = open('C:/Users/zzz/Desktop/双聚类结果/matlab/row/' + str(j) + '.txt', 'w')
for line in open('C:/Users/zzz/Desktop/双聚类结果/matlab/out_rows.txt', 'r'):
b = line.replace('[','x').replace(']','x')
c = b.replace(' ',' ')
d = c.replace(' ',' ')
e = d.replace(' ',' ')
f = e.replace(' ',' ')
g = f.replace(' ','x;x')
fw.write(g)
i += 1
if i > 1 and i % 3 == 1 :
fw.close()
lines = open('C:/Users/zzz/Desktop/双聚类结果/matlab/row/' + str(j) + '.txt').readlines()
del lines[0]
open('C:/Users/zzz/Desktop/双聚类结果/matlab/row/' + str(j) + '.txt','w').writelines(lines)
fw.close()
j += 1
fw = open('C:/Users/zzz/Desktop/双聚类结果/matlab/row/' + str(j) + '.txt', 'w')
fw.close()
#读取列数据
i = 1
j = 1
fw = open('C:/Users/zzz/Desktop/双聚类结果/matlab/col/' + str(j) + '.txt', 'w')
for line in open('C:/Users/zzz/Desktop/双聚类结果/matlab/out_cols.txt', 'r'):
b = line.replace('[','v').replace(']','v')
c = b.replace(' ',' ')
d = c.replace(' ',' ')
e = d.replace(' ',' ')
f = e.replace(' ',' ')
g = f.replace(' ','v;v')
fw.write(g)
i += 1
if i > 1 and i % 3 == 1 :
fw.close()
lines = open('C:/Users/zzz/Desktop/双聚类结果/matlab/col/' + str(j) + '.txt').readlines()
del lines[0]
open('C:/Users/zzz/Desktop/双聚类结果/matlab/col/' + str(j) + '.txt','w').writelines(lines)
fw.close()
j += 1
fw = open('C:/Users/zzz/Desktop/双聚类结果/matlab/col/' + str(j) + '.txt', 'w')
fw.close()
#行列数据整合
j = 1
for m in range(1,nc2):
i = 0
f = open('C:/Users/zzz/Desktop/双聚类结果/matlab/result/' + str(j) + '.txt','w')
row = open('C:/Users/zzz/Desktop/双聚类结果/matlab/row/' + str(j) + '.txt','r')
col = open('C:/Users/zzz/Desktop/双聚类结果/matlab/col/' + str(j) + '.txt','r')
while i < 2:
if i == 0 :
m = row.readline()
n = col.readline()
oz1 = m.strip('\n') + ' ' + n
f.write(oz1)
i += 1
if i == 1:
m = row.readline()
n = col.readline()
oz2 = m + n
f.write(oz2)
i += 1
j += 1
f.flush()
f.close()
for j in range(1,nc2):
zdian_row = open('C:/Users/zzz/Desktop/D编号.txt')
zdian_col = open('C:/Users/zzz/Desktop/A编号.txt')
result = open('C:/Users/zzz/Desktop/双聚类结果/matlab/result_replace/' + str(j) + '.txt', 'w+')
ol = open('C:/Users/zzz/Desktop/双聚类结果/matlab/result/' + str(j) + '.txt')
txt = ol.readlines()
num = txt[0]
b = row = txt[1]
c = col = txt[2]
for text1 in zdian_row:
zf_o1 = text1.split()
zf_z1 = zf_o1[0].strip('"')
zf_r1 = 'x' + zf_o1[1] + 'x'
b = b.replace(zf_r1,zf_z1)
for text2 in zdian_col:
zf_o2 = text2.split()
zf_z2 = zf_o2[0].strip('"')
zf_r2 = 'v' + zf_o2[1] + 'v'
c = c.replace(zf_r2,zf_z2)
result.write(num)
result.write(b)
result.write(c)
result.close()
#组合生成
i = 1
for m in range(1,nc2):
fw = open('C:/Users/zzz/Desktop/双聚类结果/matlab/result_group/' + str(i) + '.txt', 'w')
with open('C:/Users/zzz/Desktop/双聚类结果/matlab/result_replace/' + str(i) + '.txt') as info:
text = info.readlines()
num = text[0]
fw.write(num)
drug = text[1].strip('\n')
adr = text[2].strip('\n')
for each in drug.split(';'):
for other in adr.split(';'):
a = (str(each) + '@'+ str(other))
b = a.strip('\n')
fw.write(b + '\n')
i += 1
fw.close()
————————————分割线——————————————