-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcoloredEdges.py
63 lines (42 loc) · 1.04 KB
/
coloredEdges.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
import sys
def cycle(chrom):
cycle = [0]*(len(chrom)*2)
for j in range(0,len(chrom)):
element = chrom[j]
if element > 0 :
cycle[2*j-1] = 2*element -1
cycle[2*j] = 2*element
else:
cycle[2*j-1] = -2*element
cycle[2*j] = -2*element -1
print cycle
newCycle = [cycle[len(cycle)-1]]
for i in range(len(cycle)-1):
newCycle.append(cycle[i])
print newCycle
return newCycle
def colored(P):
edges = dict()
for element in P:
print element
nodes = cycle(element)
for j in range(0,len(element)):
edges[nodes[2*j-1]] = nodes[2*j]
return edges
filename = sys.argv[1]
file = open(filename, 'r')
data = file.read()
data = data.strip(')')
data = data.strip('(')
data = data.strip('\n')
data = data.strip(')')
array = []
array = data.split(')(')
print array
array = map(lambda x: x.split(' '), array)
array = [list(map(int,row)) for row in array]
result = colored(array)
newResult = []
for key, value in result.iteritems():
newResult.append('(' + str(key) + ', ' + str(value) + ')')
print (", ".join(str(x) for x in newResult))