-
Notifications
You must be signed in to change notification settings - Fork 0
/
Map_append_in_OneMap.py
133 lines (91 loc) · 2.59 KB
/
Map_append_in_OneMap.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
133
#Take a GBS HapMap output with only genotypes and SNP names
# Take this information and produce a OneMap genotype file
#End goal is:
#
Map_filename = 'Male_map_markers.txt'
Add_filename = 'Male_add_markers.txt'
with open(Map_filename) as f:
Map_List = [line.rstrip() for line in f]
Map_List = Map_List[1:]
Map_Data = []
Starred_removed = []
#The star bit here removes the het-hets and leaves just the core file
for SNP in Map_List:
new = SNP.split()
if new[0][-1] == '*':
Starred_removed.append(new)
else:
Map_Data.append(new)
with open(Add_filename) as f:
Add_List = [line.rstrip() for line in f]
Add_List = Add_List[1:]
Add_Data = []
for SNP in Add_List:
new = SNP.split()
Add_Data.append(new)
Starred_Out = ''
for SNP in Starred_removed:
z = ','.join(SNP)
Starred_Out += z + '\n'
#This next code bit only works if the LG names are the same in the add and the map lists so
# make sure to double check that!!!
LG_dict = {}
for SNP in Map_Data:
SNPkey = SNP[1]
value = SNP
if SNPkey in LG_dict.keys():
LG_dict[SNPkey].append(value)
else:
LG_dict[SNPkey] = [value]
for SNP in Add_Data:
SNPkey = SNP[1]
value = SNP
if SNPkey in LG_dict.keys():
LG_dict[SNPkey].append(value)
else:
LG_dict[SNPkey] = [value]
#Two lists now merged into one dictionary that is split by Keys = Linkage groups
OneMap_Codes = ''
for k in LG_dict:
name = k
values = LG_dict[k]
OneString = ''
for x in values:
z = str(x[3])
if x == values[len(values) -1]:
tempstring = z
OneString += tempstring
else:
tempstring = z+','
OneString += tempstring
add_to_output= '%s\nc=(%s)\n\n' % (k, OneString)
OneMap_Codes +=add_to_output
#something here along the lines of for list of values for K
#make a list of just the OneMap codes
#make a string with the name and the codes and add to OneMap_Order_List
#i.e. 'AC12 = c(24,56,3232,45453,2331,343)'
#then print Three files:
# one with the OneMap order strings
# one with the Markers and all info in the LG_dict
# one with just the het-hets removed from the MapList to add in later.
# making string for Markers in LG_dict
Markers_in_OneMap_Work = ''
for k in LG_dict:
name = k
values = LG_dict[k]
LGstring = ''
for x in values:
z = ','.join(x)
tempstring = k+','+ z +'\n'
LGstring += tempstring
Markers_in_OneMap_Work += LGstring
file=open('Markers_in_OneMap.txt','w')
file.write(Markers_in_OneMap_Work)
file.close()
file = open('Map_starred_markers_removed.txt','w')
file.write(Starred_Out)
file.close()
file = open('OneMap_marker_order_lists.txt','w')
file.write('\n\n')
file.write(OneMap_Codes)
file.close()