-
Notifications
You must be signed in to change notification settings - Fork 0
/
getUniqueUniversalMarker.py
72 lines (61 loc) · 1.96 KB
/
getUniqueUniversalMarker.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
__author__ = 'Nina'
import sys
markerFile = sys.argv[1]
def removeMarker(markerFile):
markerDict = {}
speciesDict = {}
speciesOrder = []
species = ""
file = open(markerFile)
for line in file:
if line.startswith(">"):
if not species == "":
speciesDict[species] = chromosomes
species = line
speciesOrder.append(species)
chromosomes = {}
elif line.startswith("#"):
chrom = line
elif not line == "\n":
order = line[:-2].split(" ")
chromosomes[chrom] = order
for elem in order:
if "-" in elem:
elem = elem[1:]
if elem in markerDict:
markerDict[elem].append(species)
else:
markerDict[elem] = [species]
speciesDict[species] = chromosomes
file.close()
newspeciesDict = {}
for speci in speciesDict:
chroms = speciesDict[speci]
newchroms = {}
for chro in chroms:
markorder = chroms[chro]
newmarkorder = []
for mark in markorder:
minus = False
if "-" in mark:
mark = mark[1:]
minus = True
if len(markerDict[mark]) == 8:
if minus:
newmarkorder.append("-"+mark)
else:
newmarkorder.append(mark)
newchroms[chro] = newmarkorder
newspeciesDict[speci] = newchroms
return newspeciesDict,speciesOrder
def outputMarker(speciesdict,speciesOrder):
out = open("universal.txt","w")
for speci in speciesOrder:
out.write(speci)
chroms = speciesdict[speci]
for chro in chroms:
out.write(chro)
out.write(" ".join(chroms[chro])+" $\n")
out.close()
newDicts,order = removeMarker(markerFile)
outputMarker(newDicts,order)