-
Notifications
You must be signed in to change notification settings - Fork 0
/
dotModule.py
33 lines (28 loc) · 1.04 KB
/
dotModule.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
from writeOnFiles import writeFile
from misc import sanitize
import numpy as np
#@graph is the graph (matrix) to be displayed
#@graph[i][j] = (name of sample i, name of sample j, delta, distance between i and j)
#and delta = 1 if there is an edge between i and j, otherwise 0.
#All these functions write a DOT code in file
def sanitizeDot(name):
newName = ""
for letter in name:
if not letter == "-":
newName += letter
return newName
#For non-oriented graphs
def graphNO(graph):
seen = dict.fromkeys([])
data = "graph g { \n"
n,m = np.shape(graph)
for i in range(n):
for j in range(i+1,m):
if graph[i][j]:
namei,namej,delta,distance = graph[i][j]
if delta and not seen.get((namei,namej)) :
data += "%s -- %s [label=%s]; \n"%(sanitizeDot(namei),sanitizeDot(namej),str(distance))
seen.setdefault((namei,namej),1)
seen.setdefault((namej,namej),1)
data += " } \n"
writeFile(data,"","dot")