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, normpath_win32
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):
24 def doparametres(self, dlg = None) :
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)
33 self.paramsimi = parametres
35 self.paramsimi = {'coeff' : 0,
56 'cola' : (200,200,200),
68 self.indices = indices_simi
71 self.pathout = PathOut(dirout = self.dirout)
73 if not self.parametres.get('isopen', False) :
74 if self.tableau is None :
75 self.tableau = parent.tableau
76 self.tableau.parametres['mineff'] = 0
77 if not self.fromprof :
78 dialcol = FreqDialog(self.parent, self.tableau.get_colnames(), _(u"Select columns").decode('utf8'), size=(600, 250), showNA = False)
79 dialcol.CenterOnParent()
80 res = dialcol.ShowModal()
85 self.tableau.selected_col = dialcol.m_listBox1.GetSelections()
86 actives = self.tableau.getactlistfromselection(self.tableau.selected_col)
88 actives = self.actives
89 if isinstance(actives, dict) :
90 actives = [[val, actives[val][0]] for val in actives]
91 self.tableau.actives = dict(actives)
92 self.tableau.make_listactives()
93 actives = dict([[i, val] for i, val in enumerate(actives)])
94 self.dial = PrefSimi(self.parent, -1, self.paramsimi, self.indices, wordlist = actives)
95 self.dial.CenterOnParent()
96 self.val = self.dial.ShowModal()
97 if self.val == wx.ID_OK :
98 last = self.dial.listcol.GetFirstSelected()
99 lastl = [self.dial.listcol.GetFirstSelected()]
100 indexes = [self.dial.listcol.getColumnText(self.dial.listcol.GetFirstSelected(),0)]
101 while self.dial.listcol.GetNextSelected(last) != -1:
102 last = self.dial.listcol.GetNextSelected(last)
104 indexes.append(self.dial.listcol.getColumnText(last,0))
105 self.column = [self.tableau.listactives.index(val) for val in indexes]
107 self.paramsimi = self.make_param()
108 self.parametres.update(self.paramsimi)
109 #self.parametres['type'] = 'simimatrix'
110 if not self.pathout :
111 self.parametres['pathout'] = ConstructPathOut(self.parametres['pathout'], 'SimiMatrix')
112 print self.parametres['pathout']
114 self.parametres['pathout'] = self.dirout
115 self.pathout.createdir(self.parametres['pathout'])
116 self.pathout.dirout = self.parametres['pathout']
121 self.parametres = None
125 self.parametres = None
128 def doanalyse(self) :
129 self.pathout.basefiles(simipath)
130 with open(normpath_win32(self.pathout['selected.csv']), 'w') as f :
131 f.write('\n'.join([`val` for val in self.column]))
134 keepGoing = self.dlg.Update(count)
135 #----------------------------------------------------------------
138 self.Linecontent = []
139 #--------------------------------------------------------
141 #if not self.fromprof :
142 #self.pathout = ConstructPathOut(self.tableau.parametres['filename'], 'Simi')
143 #self.DictPathOut = construct_simipath(self.pathout)
144 self.tableau.dictpathout = self.pathout
145 self.dlg.Update(count, u"passage en O/1")
146 if not self.fromprof :
147 self.tableau.make_01_from_selection(self.tableau.selected_col)
148 #self.Linecontent = parent.table
151 #self.pathout = pathout
152 #self.DictPathOut = construct_simipath(self.pathout)
153 self.DictPathOut = self.pathout
154 #self.DictPathOut['mat01'] = fromprof
155 self.script = PrintSimiScript(self)
156 self.script.make_script()
159 self.dlg.Update(count, u"R...")
160 #self.DoR(script.scriptout, dlg = self.dlg, message = 'R...')
161 self.tmpfile = self.script.scriptout
164 self.tableau.save_tableau(self.pathout['db'])
167 #self.dlg.Update(count, u"")
177 def make_param(self) :
178 if self.paramsimi['first'] :
181 keep_coord = self.dial.check_coord.GetValue()
182 #self.select = self.dial.check_colch.GetValue()
184 paramsimi = {'coeff' : self.dial.choice1.GetSelection(),
185 'layout' : self.dial.choice2.GetSelection(),
186 'type_graph' : self.dial.choice3.GetSelection(),
187 'arbremax' : self.dial.check1.GetValue(),
188 'coeff_tv' : self.dial.check_s_size.GetValue(),
189 'coeff_tv_nb' : self.dial.spin_tv.GetValue(),
190 'tvprop' : self.dial.check2.GetValue(),
191 'tvmin' : self.dial.spin_tvmin.GetValue(),
192 'tvmax' : self.dial.spin_tvmax.GetValue(),
193 'coeff_te' : self.dial.check3.GetValue(),
194 'coeff_temin' : self.dial.spin_temin.GetValue(),
195 'coeff_temax' : self.dial.spin_temax.GetValue(),
196 'label_e' : self.dial.check_elab.GetValue(),
197 'label_v' : self.dial.check_vlab.GetValue(),
198 'vcex' : self.dial.check_vcex.GetValue(),
199 'vcexmin' : self.dial.spin_vcexmin.GetValue(),
200 'vcexmax' : self.dial.spin_vcexmax.GetValue(),
201 'cex' : self.dial.spin_cex.GetValue(),
202 'seuil_ok' : self.dial.check_seuil.GetValue(),
203 'seuil' : self.dial.spin_seuil.GetValue(),
204 'cols' : self.dial.cols.GetColour(),
205 'cola' : self.dial.cola.GetColour(),
206 'width' : self.dial.spin_width.GetValue(),
207 'height' : self.dial.spin_height.GetValue(),
209 'keep_coord' : keep_coord,
210 'alpha' : self.dial.slider_sphere.GetValue(),
211 'film' : self.dial.film.GetValue(),
212 'svg' : self.dial.choix_format.GetSelection(),
213 'halo' : self.dial.halo.GetValue(),
214 'com' : self.dial.comcheck.GetValue(),
215 'communities' :self.dial.choix_com.GetSelection(),
217 if 'cexfromchi' in self.paramsimi :
218 paramsimi['cexfromchi'] = self.dial.checkit.GetValue()
219 if 'sfromchi' in self.paramsimi :
220 paramsimi['sfromchi'] = self.dial.checki.GetValue()
221 if 'vlabcolor' in self.paramsimi :
222 paramsimi['vlabcolor'] = self.paramsimi['vlabcolor']
223 if 'check_bystar' in dir(self.dial) :
224 paramsimi['bystar'] = self.dial.check_bystar.GetValue()
225 paramsimi['stars'] = self.paramsimi['stars']
226 if 'tmpchi' in self.paramsimi :
227 paramsimi['tmpchi'] = self.paramsimi['tmpchi']
232 if self.parametres['type_graph'] == 1:
233 if self.parametres['svg'] :
234 filename, ext = os.path.splitext(self.script.filename)
235 fileout = filename + '.svg'
237 fileout = self.script.filename
238 if os.path.exists(self.DictPathOut['liste_graph']):
239 graph_simi = read_list_file(self.DictPathOut['liste_graph'])
240 graph_simi.append([os.path.basename(fileout), self.script.txtgraph])
242 graph_simi = [[os.path.basename(fileout), self.script.txtgraph]]
243 print_liste(self.DictPathOut['liste_graph'], graph_simi)
246 if self.paramsimi['type_graph'] == 1 :
252 pid = exec_rcode(self.ira.RPath, self.tmpfile, wait = wait, graph = graph)
253 if self.paramsimi['type_graph'] == 1 :
254 while pid.poll() == None :
260 check_Rresult(self.parent, pid)