-
Notifications
You must be signed in to change notification settings - Fork 0
/
findmodule.py
132 lines (105 loc) · 4.98 KB
/
findmodule.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import pandas as pd
import networkx as nx
cancer=pd.read_csv("cancer+1.csv",index_col=0,header=0)
normal=pd.read_csv("normal+1.csv",index_col=0,header=0)
cancernetwork=cancer.iloc[:,0:2]
normalnetwork=normal.iloc[:,0:2]
def node():
cancernode=cancernetwork.iloc[:,0].append(cancernetwork.iloc[:,1])
cancernode=cancernode.drop_duplicates( keep='first')
print(len(cancernode))
normalnode=normalnetwork.iloc[:,0].append(normalnetwork.iloc[:,1])
normalnode=normalnode.drop_duplicates( keep='first')
print(len(normalnode))
allnode=cancernode.append(normalnode)
print(len(allnode))
index=allnode.duplicated()
commonnode=allnode[index]
print(len(commonnode))
return commonnode
def cancer_normal_unique_edge():
#cancerdifferentnetwork = pd.read_csv("cancerdifferentnetwork.csv", index_col=0, header=0)
#normaldifferentnetwork = pd.read_csv("normaldifferentnetwork.csv", index_col=0, header=0)
cancerdifferentnetwork = pd.read_csv("cancerdifferentnetwork+1.csv", index_col=0, header=0)
normaldifferentnetwork = pd.read_csv("normaldifferentnetwork+1.csv", index_col=0, header=0)
differentnetwork = pd.read_csv("edge509.csv", index_col=0, header=0)
cancerdifferentnetwork = cancerdifferentnetwork.values.tolist()
normaldifferentnetwork = normaldifferentnetwork.values.tolist()
commonnetwork = differentnetwork.values.tolist()
cancerleftunique = []
normalleftunique = []
for index,i in enumerate(commonnetwork):
if i not in cancerdifferentnetwork:
print(i)
normalleftunique.append(i)
commonnetwork[index].append(1)
else:
print(index)
commonnetwork[index].append(2)
print(len(normalleftunique))
normalleftunique = pd.DataFrame(normalleftunique)
#normalleftunique.to_csv("normalleftuniquel.csv")
commonnetwork=pd.DataFrame(commonnetwork)
commonnetwork.to_csv("commonnetworkwithmark1.csv")
commonnetwork = differentnetwork.values.tolist()
for index,i in enumerate(commonnetwork):
if i not in normaldifferentnetwork:
cancerleftunique.append(i)
commonnetwork[index].append(0)
else:
commonnetwork[index].append(2)
print(len(cancerleftunique))
cancerleftunique = pd.DataFrame(cancerleftunique)
#cancerleftunique.to_csv("cancerleftuniquel.csv")
commonnetwork=pd.DataFrame(commonnetwork)
commonnetwork.to_csv("commonnetworkwithmark2.csv")
def mergeORdifferentnetwork(commonnode): #全网络或者共同的网络或者同节点不同的网络
mrel=cancernetwork.append(normalnetwork)
print("mrel",mrel.head(),len(mrel))
index=mrel.duplicated()
common=mrel[index]
#print(common)
newrelunique = mrel.drop_duplicates( keep='first')
newrelunique.to_csv("mergenetwork.csv")
differentnetwork=pd.DataFrame()
for i in range(0,len(newrelunique.iloc[:,0])):
if newrelunique.iloc[i,0] in list(commonnode):
if newrelunique.iloc[i,1] in list(commonnode):
differentnetwork=differentnetwork.append(newrelunique.iloc[i,:])
print(differentnetwork,len(differentnetwork))
differentnetwork.to_csv("differentnetwork.csv")
def cancerunique(cancernetwork, normalnetwork,common):
cancerunique = []
cancernetwork = cancernetwork.values.tolist()
normalnetwork = normalnetwork.values.tolist()
commonnetwork = common.values.tolist()
for i in cancernetwork:
if i not in commonnetwork:
cancerunique.append(i)
print(len(cancerunique))
df = pd.DataFrame(cancerunique)
df.to_csv("cancerunique.csv")
if __name__=='__main__':
commonnode=node()
# cancerdifferentnetwork = pd.DataFrame()
# for i in range(0, len(cancernetwork.iloc[:, 0])):
# if cancernetwork.iloc[i, 0] in list(commonnode) or cancernetwork.iloc[i, 1] in list(commonnode):
# cancerdifferentnetwork = cancerdifferentnetwork.append(cancernetwork.iloc[i, :])
# cancerdifferentnetwork=cancerdifferentnetwork.drop_duplicates()
# print(cancerdifferentnetwork, len(cancerdifferentnetwork))
# cancerdifferentnetwork.to_csv("cancerdifferentnetwork+1.csv")
# normaldifferentnetwork = pd.DataFrame()
# for i in range(0, len(normalnetwork.iloc[:, 0])):
# if normalnetwork.iloc[i, 0] in list(commonnode) or normalnetwork.iloc[i, 1] in list(commonnode):
# normaldifferentnetwork = normaldifferentnetwork.append(normalnetwork.iloc[i, :])
#
# normaldifferentnetwork=normaldifferentnetwork.drop_duplicates()
# print(normaldifferentnetwork, len(normaldifferentnetwork))
# normaldifferentnetwork.to_csv("normaldifferentnetwork+1.csv")
#
# edge509=cancerdifferentnetwork.append(normaldifferentnetwork)
# edge509=edge509.drop_duplicates()
# print(edge509, len(edge509))
# edge509.to_csv("edge509.csv")
#
cancer_normal_unique_edge()