2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2009-2010 Pierre Ratinaud
7 from chemins import ConstructPathOut, simipath, ffr, PathOut
8 from functions import print_liste, exec_rcode, read_list_file, check_Rresult, indices_simi, treat_var_mod
9 from dialog import SelectColDial, FreqDialog
10 from guifunct import PrefSimi
11 from analysematrix import AnalyseMatrix
12 from PrintRScript import PrintSimiScript
18 from ConfigParser import RawConfigParser
19 from time import sleep
20 from uuid import uuid4
23 class DoSimi(AnalyseMatrix):
25 self.fromprof = self.parametres.get('fromprof', False)
26 self.wordgraph = self.parametres.get('wordgraph', False)
27 self.listactives = self.parametres.get('listactives', False)
28 self.actives = self.parametres.get('actives', False)
29 self.openfromprof = self.parametres.get('openfromprof', False)
30 self.cmd = self.parametres.get('cmd', False)
31 self.dirout = self.parametres.get('pathout', False)
32 #parent, matrix = None, parametres = None, isopen = False, fromprof = False, pathout = False, filename ='', gparent = False, wordgraph = False, listactives = False, actives = False, cmd = False, openfromprof=False, tableau = None):
33 #-------------------------------------------------------------------
34 # self.fromprof = fromprof
35 # self.wordgraph = wordgraph
36 # self.listactives = listactives
37 # self.actives = actives
38 # self.openfromprof = openfromprof
40 # self.dirout = pathout
41 # if parametres is not None and fromprof:
43 self.paramsimi = parametres
45 self.paramsimi = {'coeff' : 0,
66 'cola' : (200,200,200),
78 self.indices = indices_simi
80 # self.parent = parent.parent
81 # self.Source = parent
85 self.pathout = PathOut(dirout = self.dirout)
87 #self.RPath = self.parent.PathPath.get('PATHS', 'rpath')
88 if not self.parametres.get('isopen', False) :
90 # self.tableau = self.parent.tableau
92 # self.tableau = parent.tableau
93 if self.tableau is None :
94 self.tableau = parent.tableau
95 self.tableau.parametres['mineff'] = 0
96 if not self.fromprof :
97 dialcol = FreqDialog(self.parent, self.tableau.get_colnames(), _(u"Select columns").decode('utf8'), size=(600, 250), showNA = False)
98 dialcol.CenterOnParent()
99 res = dialcol.ShowModal()
103 if not self.actives :
104 self.tableau.selected_col = dialcol.m_listBox1.GetSelections()
105 actives = self.tableau.getactlistfromselection(self.tableau.selected_col)
107 actives = self.actives
108 if isinstance(actives, dict) :
109 actives = [[val, actives[val][0]] for val in actives]
110 self.tableau.actives = dict(actives)
111 self.tableau.make_listactives()
112 actives = dict([[i, val] for i, val in enumerate(actives)])
113 self.dial = PrefSimi(self.parent, -1, self.paramsimi, self.indices, wordlist = actives)
114 self.dial.CenterOnParent()
115 self.val = self.dial.ShowModal()
116 if self.val == wx.ID_OK :
117 last = self.dial.listcol.GetFirstSelected()
118 lastl = [self.dial.listcol.GetFirstSelected()]
119 indexes = [self.dial.listcol.getColumnText(self.dial.listcol.GetFirstSelected(),0)]
120 while self.dial.listcol.GetNextSelected(last) != -1:
121 last = self.dial.listcol.GetNextSelected(last)
123 indexes.append(self.dial.listcol.getColumnText(last,0))
124 self.column = [self.tableau.listactives.index(val) for val in indexes]
126 self.paramsimi = self.make_param()
127 self.parametres.update(self.paramsimi)
128 #self.parametres['type'] = 'simimatrix'
129 if not self.pathout :
130 self.parametres['pathout'] = ConstructPathOut(self.parametres['pathout'], 'SimiMatrix')
131 print self.parametres['pathout']
133 self.parametres['pathout'] = self.dirout
134 self.pathout.createdir(self.parametres['pathout'])
135 self.pathout.dirout = self.parametres['pathout']
136 #self.parametres['filename'] = self.tableau.parametres['filename']
139 #dlg = wx.ProgressDialog("Traitements",
140 # "Veuillez patienter...",
142 # parent=self.parent,
143 # style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME
146 #AnalyseMatrix.__init__(self, parent, self.tableau, self.paramsimi, dlg = dlg)
149 self.parametres = None
153 self.parametres = None
156 def doanalyse2(self) :
157 self.pathout.basefiles(simipath)
158 with open(self.pathout['selected.csv'], 'w') as f :
159 f.write('\n'.join([`val` for val in self.column]))
162 keepGoing = self.dlg.Update(count)
163 #----------------------------------------------------------------
166 self.Linecontent = []
167 #--------------------------------------------------------
169 #if not self.fromprof :
170 #self.pathout = ConstructPathOut(self.tableau.parametres['filename'], 'Simi')
171 #self.DictPathOut = construct_simipath(self.pathout)
172 self.tableau.dictpathout = self.pathout
173 self.dlg.Update(count, u"passage en O/1")
174 if not self.fromprof :
175 self.tableau.make_01_from_selection(self.tableau.selected_col)
176 #self.Linecontent = parent.table
179 #self.pathout = pathout
180 #self.DictPathOut = construct_simipath(self.pathout)
181 self.DictPathOut = self.pathout
182 #self.DictPathOut['mat01'] = fromprof
183 self.script = PrintSimiScript(self)
184 self.script.make_script()
187 self.dlg.Update(count, u"R...")
188 #self.DoR(script.scriptout, dlg = self.dlg, message = 'R...')
189 self.tmpfile = self.script.scriptout
192 self.tableau.save_tableau(self.pathout['db'])
195 self.dlg.Update(count, u"")
205 def make_param(self) :
206 if self.paramsimi['first'] :
209 keep_coord = self.dial.check_coord.GetValue()
210 #self.select = self.dial.check_colch.GetValue()
212 paramsimi = {'coeff' : self.dial.choice1.GetSelection(),
213 'layout' : self.dial.choice2.GetSelection(),
214 'type_graph' : self.dial.choice3.GetSelection(),
215 'arbremax' : self.dial.check1.GetValue(),
216 'coeff_tv' : self.dial.check_s_size.GetValue(),
217 'coeff_tv_nb' : self.dial.spin_tv.GetValue(),
218 'tvprop' : self.dial.check2.GetValue(),
219 'tvmin' : self.dial.spin_tvmin.GetValue(),
220 'tvmax' : self.dial.spin_tvmax.GetValue(),
221 'coeff_te' : self.dial.check3.GetValue(),
222 'coeff_temin' : self.dial.spin_temin.GetValue(),
223 'coeff_temax' : self.dial.spin_temax.GetValue(),
224 'label_e' : self.dial.check_elab.GetValue(),
225 'label_v' : self.dial.check_vlab.GetValue(),
226 'vcex' : self.dial.check_vcex.GetValue(),
227 'vcexmin' : self.dial.spin_vcexmin.GetValue(),
228 'vcexmax' : self.dial.spin_vcexmax.GetValue(),
229 'cex' : self.dial.spin_cex.GetValue(),
230 'seuil_ok' : self.dial.check_seuil.GetValue(),
231 'seuil' : self.dial.spin_seuil.GetValue(),
232 'cols' : self.dial.cols.GetColour(),
233 'cola' : self.dial.cola.GetColour(),
234 'width' : self.dial.spin_width.GetValue(),
235 'height' : self.dial.spin_height.GetValue(),
237 'keep_coord' : keep_coord,
238 'alpha' : self.dial.slider_sphere.GetValue(),
239 'film' : self.dial.film.GetValue(),
240 'svg' : self.dial.choix_format.GetSelection(),
241 'halo' : self.dial.halo.GetValue(),
242 'com' : self.dial.comcheck.GetValue(),
243 'communities' :self.dial.choix_com.GetSelection(),
245 if 'cexfromchi' in self.paramsimi :
246 paramsimi['cexfromchi'] = self.dial.checkit.GetValue()
247 if 'sfromchi' in self.paramsimi :
248 paramsimi['sfromchi'] = self.dial.checki.GetValue()
249 if 'vlabcolor' in self.paramsimi :
250 paramsimi['vlabcolor'] = self.paramsimi['vlabcolor']
251 if 'check_bystar' in dir(self.dial) :
252 paramsimi['bystar'] = self.dial.check_bystar.GetValue()
253 paramsimi['stars'] = self.paramsimi['stars']
254 if 'tmpchi' in self.paramsimi :
255 paramsimi['tmpchi'] = self.paramsimi['tmpchi']
260 if self.parametres['type_graph'] == 1:
261 if self.parametres['svg'] :
262 filename, ext = os.path.splitext(self.script.filename)
263 fileout = filename + '.svg'
265 fileout = self.script.filename
266 if os.path.exists(self.DictPathOut['liste_graph']):
267 graph_simi = read_list_file(self.DictPathOut['liste_graph'])
268 graph_simi.append([os.path.basename(fileout), self.script.txtgraph])
270 graph_simi = [[os.path.basename(fileout), self.script.txtgraph]]
271 print_liste(self.DictPathOut['liste_graph'], graph_simi)
274 if self.paramsimi['type_graph'] == 1 :
280 pid = exec_rcode(self.ira.RPath, self.tmpfile, wait = wait, graph = graph)
281 if self.paramsimi['type_graph'] == 1 :
282 while pid.poll() == None :
288 check_Rresult(self.parent, pid)