annotate scaffhunter/reorderient.py @ 2:ec31e4883c99 draft default tip

Uploaded
author gdroc
date Mon, 14 Nov 2016 08:04:53 -0500
parents 9c61692acd7b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
1
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
2 #
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
3 # Copyright 2014 CIRAD
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
4 #
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
5 # This program is free software; you can redistribute it and/or modify
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
6 # it under the terms of the GNU General Public License as published by
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
7 # the Free Software Foundation; either version 3 of the License, or
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
8 # (at your option) any later version.
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
9 #
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
10 # This program is distributed in the hope that it will be useful,
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
13 # GNU General Public License for more details.
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
14 #
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
15 # You should have received a copy of the GNU General Public License
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
16 # along with this program; if not, see <http://www.gnu.org/licenses/> or
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
17 # write to the Free Software Foundation, Inc.,
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
18 # 51 Franklin Street, Fifth Floor, Boston,
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
19 # MA 02110-1301, USA.
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
20 #
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
21 #
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
22
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
23
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
24 import optparse, os, shutil, subprocess, sys, tempfile, fileinput, ConfigParser, operator, time, random
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
25
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
26 def factorielle(x):
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
27 if x < 2:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
28 return 1
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
29 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
30 return x * factorielle(x-1)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
31
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
32 def calcul_score_id(MAT, ORDRE, MARK, ORIENT, DIC_INDEX, NB):
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
33 #on cree l'ordre des markers
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
34 scaff_ordre = list(ORDRE)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
35 ordre = []
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
36 for n in scaff_ordre:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
37 liste = list(MARK[n])
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
38 if ORIENT[n] == 'REV':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
39 liste.reverse()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
40 ordre = ordre + liste
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
41 #on enregistre les positions relative des markers dans cet ordre
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
42 liste_ordre = {}
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
43 i = 0
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
44 for n in ordre:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
45 liste_ordre[n] = i
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
46 i += 1
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
47 #on calcule le score
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
48 score = 0
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
49 while len(scaff_ordre) > 1:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
50 scaff_fait = scaff_ordre[0]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
51 del scaff_ordre[0]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
52 # print scaff_fait, MARK[scaff_fait]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
53 for n in MARK[scaff_fait]:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
54 mark = DIC_INDEX[n]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
55 for j in scaff_ordre:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
56 for k in MARK[j]:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
57 val = MAT[mark][k]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
58 if val != 999999999:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
59 score = score + ((1-(abs(liste_ordre[n]-liste_ordre[k])/NB))*val)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
60 return score
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
61
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
62 def calcul_score_dif(MAT, ORDRE, MARK, ORIENT, DIC_INDEX, NB):
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
63 #on cree l'ordre des markers
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
64 scaff_ordre = list(ORDRE)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
65 ordre = []
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
66 for n in scaff_ordre:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
67 liste = list(MARK[n])
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
68 if ORIENT[n] == 'REV':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
69 liste.reverse()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
70 ordre = ordre + liste
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
71 #on enregistre les positions relative des markers dans cet ordre
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
72 liste_ordre = {}
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
73 i = 0
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
74 for n in ordre:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
75 liste_ordre[n] = i
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
76 i += 1
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
77 #on calcule le score
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
78 score = 0
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
79 while len(scaff_ordre) > 1:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
80 scaff_fait = scaff_ordre[0]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
81 del scaff_ordre[0]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
82 # print scaff_fait, MARK[scaff_fait]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
83 for n in MARK[scaff_fait]:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
84 mark = DIC_INDEX[n]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
85 for j in scaff_ordre:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
86 for k in MARK[j]:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
87 val = MAT[mark][k]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
88 if val != 999999999:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
89 score = score + ((abs(liste_ordre[n]-liste_ordre[k])/NB)*val)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
90 return score
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
91
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
92 def rear_fait(ORD, ORIENT):
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
93 mot = ''.join(ORD)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
94 for n in ORD:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
95 mot = mot+ORIENT[n]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
96 return mot
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
97
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
98 def reorderient(ORDRE, ORIENT):
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
99 NEW_ORDRE = list(ORDRE)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
100 NEW_ORIENT = {}
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
101 for n in ORIENT:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
102 NEW_ORIENT[n] = ORIENT[n]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
103 if random.randint(0,1) == 0:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
104 #On travail sur 1 scaffold
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
105 pos = random.randint(0, (len(ORDRE)-1))
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
106 scaffold = NEW_ORDRE[pos]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
107 if random.randint(0,1) == 0:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
108 #On fait un deplacement de scaffold
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
109 pos_new = pos
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
110 while pos_new == pos:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
111 pos_new = random.randint(0, (len(ORDRE)-1))
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
112 del NEW_ORDRE[pos]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
113 if scaffold in NEW_ORDRE:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
114 sys.exit('bug')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
115 NEW_ORDRE.insert(pos_new, scaffold)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
116 if random.randint(0,1) == 0:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
117 #On fait en plus une reorientation
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
118 if NEW_ORIENT[scaffold] == 'FWD':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
119 NEW_ORIENT[scaffold] = 'REV'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
120 elif NEW_ORIENT[scaffold] == 'REV':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
121 NEW_ORIENT[scaffold] = 'FWD'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
122 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
123 sys.exit('bug')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
124 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
125 #On fait juste une reorientation
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
126 if NEW_ORIENT[scaffold] == 'FWD':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
127 NEW_ORIENT[scaffold] = 'REV'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
128 elif NEW_ORIENT[scaffold] == 'REV':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
129 NEW_ORIENT[scaffold] = 'FWD'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
130 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
131 sys.exit('bug')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
132 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
133 pos_debut = random.randint(0, (len(ORDRE)-2))
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
134 pos_fin = pos_debut
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
135 while (pos_debut + 1) >= pos_fin and len(NEW_ORDRE[pos_debut:pos_fin]) == len(NEW_ORDRE):
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
136 pos_fin = random.randint(1, len(ORDRE))
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
137 scaffold = NEW_ORDRE[pos_debut:pos_fin]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
138 del NEW_ORDRE[pos_debut:pos_fin]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
139 if random.randint(0,1) == 0:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
140 #On fait un deplacement de scaffold
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
141 pos_new = pos_debut
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
142 while pos_new == pos_debut:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
143 pos_new = random.randint(0, len(NEW_ORDRE))
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
144 if random.randint(0,1) == 0:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
145 #On fait en plus une reorientation
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
146 for n in scaffold:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
147 NEW_ORDRE.insert(pos_new, n)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
148 if NEW_ORIENT[n] == 'FWD':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
149 NEW_ORIENT[n] = 'REV'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
150 elif NEW_ORIENT[n] == 'REV':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
151 NEW_ORIENT[n] = 'FWD'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
152 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
153 sys.exit('bug')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
154 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
155 #On fait juste un deplacement
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
156 for n in scaffold:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
157 NEW_ORDRE.insert(pos_new, n)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
158 pos_new += 1
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
159 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
160 #On fait juste une reorientation
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
161 for n in scaffold:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
162 NEW_ORDRE.insert(pos_debut, n)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
163 if NEW_ORIENT[n] == 'FWD':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
164 NEW_ORIENT[n] = 'REV'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
165 elif NEW_ORIENT[n] == 'REV':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
166 NEW_ORIENT[n] = 'FWD'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
167 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
168 sys.exit('bug')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
169 if len(NEW_ORDRE) != len(ORDRE):
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
170 sys.exit('bug')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
171 return [NEW_ORDRE, NEW_ORIENT]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
172
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
173 def __main__():
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
174 #Parse Command Line
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
175 parser = optparse.OptionParser(usage="python %prog [options]\n\nProgram designed by Guillaume MARTIN : guillaume.martin@cirad.fr\n\n"
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
176 "This program take in input a matrix containing maker linkage or divergence and the two output files of UPGMA.py and try to optimize the "
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
177 "scaffold order and orientation proposed by UPGMA.py.\n"
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
178 "The optimization is performed by calculating a score for the scaffold order, trying rearrangements (scaffold or scaffold group permutations "
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
179 "and/or inversion) followed by score re-calculation. If the new score is better than the previous, the new order is conserved; else, the previous "
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
180 "order is conserved. The program stops when more than a defined number of consecutive rearrangement (passed in --iter argument) do not improve the ordering.\n"
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
181 "This program output a file containing ordered scaffolds in a table format and a table file containing ordered markers relative to the scaffold order.\n"
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
182 )
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
183 # Wrapper options.
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
184 parser.add_option( '', '--mat', dest='mat', default=None, help='Matrix file with pairwise statistics between markers.')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
185 parser.add_option( '', '--scaff', dest='scaff', default=None, help='The output file passed in --out1 argument of UPGMA.py. This file contains ordered and orientated scaffolds ate the end of UPGMA.py program.')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
186 parser.add_option( '', '--mark', dest='mark', default=None, help='A table file containing in column 1: markers name, column2: scaffold name. This is the file generated by UPGMA.py in --out2 argument')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
187 parser.add_option( '', '--iter', dest='iter', default='auto', help='Number of consecutive rearrangement tried without improvement to stop the improvement of the ordering and orientation (integer or auto). [default: %default]')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
188 parser.add_option( '', '--type', dest='type', default='IDENT', help='Data type : IDENT (marker linkage) or DIF (recombination rate). [default: %default]')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
189 parser.add_option( '', '--out1', dest='out1', default='UPGMA_ordered_opt_scaf.txt', help='Output file name of ordered scaffold. [default: %default]')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
190 parser.add_option( '', '--out2', dest='out2', default='UPGMA_ordered_opt_mark.txt', help='Output file name of ordered markers. [default: %default]')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
191 (options, args) = parser.parse_args()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
192
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
193 if options.scaff == None:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
194 sys.exit('--scaff argument is missing')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
195 if options.mark == None:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
196 sys.exit('--mark argument is missing')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
197 if options.mat == None:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
198 sys.exit('--mat argument is missing')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
199
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
200
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
201 #on enregistre dans une liste les markers dans l'ordre dans la matrice
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
202 os.system('echo "Registering scaffold order"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
203 file = open(options.mat)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
204 index_mat = file.readline().split()[1:]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
205 file.close()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
206
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
207 # On enregistre l'orientation des scaffolds
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
208 os.system('echo "Registering scaffold orientation"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
209 dico_orient = {}
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
210 file = open(options.scaff)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
211 for line in file:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
212 data = line.split()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
213 if data:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
214 dico_orient[data[0]] = data[1]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
215 file.close()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
216
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
217 #on enregistre dans un dico les scaffolds et l'ordre des positions (dans la matrice) des marqueurs dans le scaffold. Dans une liste on enregistre l'ordre des scaffolds
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
218 os.system('echo "Registering scaffold order and markers order"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
219 file = open(options.mark)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
220 dico_mark = {}#pour chaque cle = scaffold, on enregistre l'ordre des markers dans ce scaffold
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
221 liste_ordre = []#Ordre des scaffolds
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
222 dico_index = {}#position du markers dans la matrice
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
223 # dico_orient = {}#######
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
224 nb_mark = 0
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
225 for line in file:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
226 data = line.split()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
227 if data:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
228 nb_mark += 1
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
229 if data[1] in dico_mark:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
230 dico_index[index_mat.index(data[0])] = data[0]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
231 if dico_orient[data[1]] == 'FWD':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
232 dico_mark[data[1]].append(index_mat.index(data[0]))
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
233 elif dico_orient[data[1]] == 'REV':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
234 dico_mark[data[1]].insert(0, index_mat.index(data[0]))
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
235 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
236 sys.exit('bugggggg')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
237 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
238 dico_mark[data[1]] = []
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
239 dico_mark[data[1]].append(index_mat.index(data[0]))
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
240 dico_index[index_mat.index(data[0])] = data[0]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
241 liste_ordre.append(data[1])
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
242 # dico_orient[data[1]] = 'FWD'################
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
243 file.close()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
244 nb_mark = float(nb_mark)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
245
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
246 #On verifie le nombre d'iteration
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
247 total_possible = ((float(len(liste_ordre)-1)**2)*2)+(len(liste_ordre))
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
248 if options.iter == 'auto':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
249 iteration = total_possible
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
250 os.system('echo "The number of iteration is automatically estimated to the number of possible iterations in case of one scaffold repositioned : '+str(total_possible)+'"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
251 elif options.iter == 'all':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
252 os.system('echo "All possible rearrangments are tested"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
253 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
254 iteration = int(options.iter)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
255 if iteration > total_possible:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
256 os.system('echo "The number of iteration is over the number of possible iterations in case of one scaffold repositioned. It has been ajusted to : '+str(total_possible)+' if not the script can be in a infinite loop"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
257 iteration = total_possible
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
258 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
259 os.system('echo "The number of iteration is under the number of possible iterations in case of one scaffold repositioned ('+str(total_possible)+'). You choose : '+str(iteration)+'"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
260
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
261 #on charge la matrice dans un dico
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
262 os.system('echo "Recording pairwise information"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
263 matrix = {}
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
264 info_scaff = {}
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
265 file = open(options.mat)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
266 file.readline()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
267 for line in file:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
268 data = line.split()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
269 if data:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
270 if data[0] in matrix:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
271 sys.exit("Warning there is redundancy in markers names, verify your data")
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
272 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
273 matrix[data[0]] = map(float, data[1:])
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
274 file.close()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
275
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
276 if options.type == 'IDENT':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
277 #On essaye toutes les orientations possibles de cet ordre
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
278 os.system('echo "Looking for best orientation in this order"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
279 t0 = time.clock()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
280 score = calcul_score_id(matrix, liste_ordre, dico_mark, dico_orient, dico_index, nb_mark)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
281 os.system('echo "Reference score : '+str(score)+'; time spent in calculation : '+str(time.clock()-t0)+'"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
282 for n in liste_ordre:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
283 t0 = time.clock()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
284 dico_reor = {}
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
285 for j in dico_orient:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
286 if j == n:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
287 if dico_orient[j] == 'FWD':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
288 dico_reor[j] = 'REV'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
289 elif dico_orient[j] == 'REV':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
290 dico_reor[j] = 'FWD'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
291 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
292 sys.exit('bug')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
293 # print n, dico_reor[j], dico_orient[n]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
294 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
295 dico_reor[j] = str(dico_orient[j])
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
296 score_reor = calcul_score_id(matrix, liste_ordre, dico_mark, dico_reor, dico_index, nb_mark)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
297 os.system('echo "Reorient score : '+str(score_reor)+'; time spent in calculation : '+str(time.clock()-t0)+'"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
298 if score < score_reor:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
299 dico_orient = {}
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
300 for k in dico_reor:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
301 dico_orient[k] = str(dico_reor[k])
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
302 score = score_reor
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
303 #On fait des rearrangements
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
304 os.system('echo "Performing rearrangements"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
305 iter = 0
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
306 fait = set()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
307 fait.add(rear_fait(liste_ordre, dico_orient))
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
308 while iter < iteration:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
309 t0 = time.clock()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
310 iter += 1
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
311 REOR = reorderient(liste_ordre,dico_orient)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
312 j = 0
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
313 while rear_fait(REOR[0], REOR[1]) in fait:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
314 j += 1
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
315 REOR = reorderient(liste_ordre,dico_orient)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
316 fait.add(rear_fait(REOR[0], REOR[1]))
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
317 score_reor = calcul_score_id(matrix, REOR[0], dico_mark, REOR[1], dico_index, nb_mark)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
318 os.system('echo "iteration : '+str(iter)+'; Reoriented score : '+str(score_reor)+', best score : '+str(score)+'; time spent in calculation : '+str(time.clock()-t0)+'"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
319 if score < score_reor:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
320 dico_orient = {}
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
321 for n in REOR[1]:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
322 dico_orient[n] = REOR[1][n]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
323 score = score_reor
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
324 liste_ordre = list(REOR[0])
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
325 iter = 0
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
326 fait = set()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
327 fait.add(rear_fait(liste_ordre, dico_orient))
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
328 #On fait une derniere etape pour voir ce qui est oriente et ce qui ne l'est pas
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
329 os.system('echo "Looking for orientated scaffolds and those who are not"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
330 os.system('echo "Reference score : '+str(score)+'; time spent in calculation : '+str(time.clock()-t0)+'"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
331 dico_ordre_final = {}
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
332 for n in liste_ordre:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
333 t0 = time.clock()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
334 dico_reor = {}
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
335 nom_ord = n
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
336 for j in dico_orient:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
337 if j == n:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
338 if dico_orient[j] == 'FWD':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
339 dico_reor[j] = 'REV'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
340 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
341 dico_reor[j] = 'FWD'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
342 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
343 dico_reor[j] = dico_orient[j]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
344 score_reor = calcul_score_id(matrix, liste_ordre, dico_mark, dico_reor, dico_index, nb_mark)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
345 os.system('echo "Reorient score : '+str(score_reor)+'; time spent in calculation : '+str(time.clock()-t0)+'"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
346 if score < score_reor:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
347 dico_orient = {}
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
348 for k in dico_reor:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
349 dico_orient[k] = dico_reor[k]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
350 score = score_reor
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
351 dico_ordre_final[n] = 'Ord'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
352 elif score == score_reor:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
353 dico_ordre_final[n] = 'NoOrd'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
354 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
355 dico_ordre_final[n] = 'Ord'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
356
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
357
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
358 elif options.type == 'DIF':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
359 #On essaye toutes les orientations possibles de cet ordre
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
360 os.system('echo "Looking for best orientation in this order"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
361 t0 = time.clock()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
362 score = calcul_score_dif(matrix, liste_ordre, dico_mark, dico_orient, dico_index, nb_mark)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
363 os.system('echo "Reference score : '+str(score)+'; time spent in calculation : '+str(time.clock()-t0)+'"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
364 for n in liste_ordre:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
365 t0 = time.clock()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
366 dico_reor = {}
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
367 for j in dico_orient:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
368 if j == n:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
369 if dico_orient[j] == 'FWD':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
370 dico_reor[j] = 'REV'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
371 elif dico_orient[j] == 'REV':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
372 dico_reor[j] = 'FWD'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
373 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
374 sys.exit('bug')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
375 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
376 dico_reor[j] = dico_orient[j]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
377 score_reor = calcul_score_dif(matrix, liste_ordre, dico_mark, dico_reor, dico_index, nb_mark)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
378 os.system('echo "Reorient score : '+str(score_reor)+'; time spent in calculation : '+str(time.clock()-t0)+'"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
379 if score < score_reor:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
380 dico_orient = {}
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
381 for k in dico_reor:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
382 dico_orient[k] = dico_reor[k]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
383 score = score_reor
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
384 #On fait des rearrangements
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
385 os.system('echo "Performing rearrangements"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
386 iter = 0
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
387 fait = set()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
388 fait.add(rear_fait(liste_ordre, dico_orient))
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
389 while iter < iteration:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
390 t0 = time.clock()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
391 iter += 1
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
392 REOR = reorderient(liste_ordre,dico_orient)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
393 while rear_fait(REOR[0], REOR[1]) in fait:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
394 REOR = reorderient(liste_ordre,dico_orient)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
395 fait.add(rear_fait(REOR[0], REOR[1]))
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
396 score_reor = calcul_score_dif(matrix, REOR[0], dico_mark, REOR[1], dico_index, nb_mark)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
397 os.system('echo "iteration : '+str(iter)+'; Reoriented score : '+str(score_reor)+', best score : '+str(score)+'; time spent in calculation : '+str(time.clock()-t0)+'"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
398 if score < score_reor:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
399 dico_orient = {}
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
400 for n in REOR[1]:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
401 dico_orient[n] = REOR[1][n]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
402 score = score_reor
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
403 liste_ordre = list(REOR[0])
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
404 iter = 0
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
405 fait = set()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
406 fait.add(rear_fait(liste_ordre, dico_orient))
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
407 #On fait une derniere etape pour voir ce qui est oriente et ce qui ne l'est pas
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
408 os.system('echo "Looking for orientated scaffolds and those who are not"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
409 os.system('echo "Reference score : '+str(score)+'; time spent in calculation : '+str(time.clock()-t0)+'"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
410 dico_ordre_final = {}
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
411 for n in liste_ordre:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
412 t0 = time.clock()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
413 dico_reor = {}
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
414 nom_ord = n
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
415 for j in dico_orient:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
416 if j == n:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
417 if dico_orient[j] == 'FWD':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
418 dico_reor[j] = 'REV'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
419 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
420 dico_reor[j] = 'FWD'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
421 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
422 dico_reor[j] = dico_orient[j]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
423 score_reor = calcul_score_dif(matrix, liste_ordre, dico_mark, dico_reor, dico_index, nb_mark)
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
424 os.system('echo "Reorient score : '+str(score_reor)+'; time spent in calculation : '+str(time.clock()-t0)+'"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
425 if score < score_reor:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
426 dico_orient = {}
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
427 for k in dico_reor:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
428 dico_orient[k] = dico_reor[k]
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
429 score = score_reor
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
430 dico_ordre_final[n] = 'Ord'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
431 elif score == score_reor:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
432 dico_ordre_final[n] = 'NoOrd'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
433 if dico_orient[n] == 'REV': #
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
434 dico_orient = {} #
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
435 for k in dico_reor: #
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
436 dico_orient[k] = dico_reor[k] #
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
437 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
438 dico_ordre_final[n] = 'Ord'
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
439 else:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
440 sys.exit('Wrong argument passed in --type')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
441
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
442 #On genere le fichier pour matrix to orthodother
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
443 os.system('echo "Outputing ordonned markers"')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
444 outfile1 = open(options.out1,'w')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
445 outfile = open(options.out2,'w')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
446 for n in liste_ordre:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
447 outfile1.write(n+'\t'+dico_orient[n]+'\t'+dico_ordre_final[n]+'\n')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
448 liste = list(dico_mark[n])
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
449 if dico_orient[n] == 'REV':
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
450 liste.reverse()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
451 for j in liste:
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
452 outfile.write(dico_index[j]+'\t'+n+'\n')
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
453 outfile.close()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
454 outfile1.close()
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
455
9c61692acd7b Uploaded
gdroc
parents:
diff changeset
456 if __name__ == "__main__": __main__()