forked from thmib/vertex-centrality-DILW
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.py
More file actions
78 lines (72 loc) · 2.21 KB
/
Functions.py
File metadata and controls
78 lines (72 loc) · 2.21 KB
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
def degree_function(graph):
degree = {}
for dise, gene in graph.items():
degree[dise] = len(gene)
degree_distribution = {}
for d, deg in degree.items():
count = 0
if deg in degree_distribution:
continue
for k, v in degree.items():
if deg == v:
count += 1
degree_distribution[deg] = count
return degree, degree_distribution
def degree_of_node_weighted(file, weights):
weight_degree = {}
for node, neighbours in file.items():
sumi = 0
for neighbour in neighbours:
if (node, neighbour) in weights:
sumi += float(weights[(node, neighbour)])
else:
sumi += float(weights[(neighbour, node)])
weight_degree[node] = sumi
return weight_degree
import pdb
def read_bipartite(file_name):
genes = {}
diseas = {}
lst_diseas = []
lst_genes = []
with open(file_name, 'r') as f:
for line in f:
(g, d) = line.strip().split('\t')[0:2]
if d not in diseas:
diseas[d] = [g]
lst_diseas.append(d)
else:
diseas[d].append(g)
if g not in genes:
genes[g] = [d]
lst_genes.append(g)
else:
genes[g].append(d)
return diseas, genes, lst_diseas, lst_genes
def read_models(data):
file=[]
graph={}
dataset={}
with open(data, 'r') as f:
for line in f:
src, des, weight= line.strip().split('\t')
if src not in graph:
graph[src] = [des]
else:
graph[src].append(des)
if des not in graph:
graph[des]=[src]
else:
graph[des].append(src)
node=graph.keys()
key=(src, des)
if key not in dataset:
dataset[key]=float(weight)
file.append(float(weight))
return dataset, graph, file, node
#to normalize values between 0 and 1
def normalization(file):
normalized_file = []
for i in range(0, len(file)):
normalized_file.append((file[i] - min(file)) / (max(file) - min(file)))
return normalized_file