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 = self.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')
113 self.parametres['pathout'] = self.dirout
114 self.pathout.createdir(self.parametres['pathout'])
115 self.pathout.dirout = self.parametres['pathout']
120 self.parametres = None
124 self.parametres = None
127 def doanalyse(self) :
128 self.pathout.basefiles(simipath)
129 with open(normpath_win32(self.pathout['selected.csv']), 'w') as f :
130 f.write('\n'.join([`val` for val in self.column]))
133 keepGoing = self.dlg.Update(count)
134 #----------------------------------------------------------------
137 self.Linecontent = []
138 #--------------------------------------------------------
140 #if not self.fromprof :
141 #self.pathout = ConstructPathOut(self.tableau.parametres['filename'], 'Simi')
142 #self.DictPathOut = construct_simipath(self.pathout)
143 self.tableau.dictpathout = self.pathout
144 self.dlg.Update(count, u"passage en O/1")
145 if not self.fromprof :
146 self.tableau.make_01_from_selection(self.tableau.selected_col)
147 #self.Linecontent = parent.table
150 #self.pathout = pathout
151 #self.DictPathOut = construct_simipath(self.pathout)
152 self.DictPathOut = self.pathout
153 #self.DictPathOut['mat01'] = fromprof
154 self.script = PrintSimiScript(self)
155 self.script.make_script()
158 self.dlg.Update(count, u"R...")
159 #self.DoR(script.scriptout, dlg = self.dlg, message = 'R...')
160 self.tmpfile = self.script.scriptout
163 self.tableau.save_tableau(self.pathout['db'])
166 #self.dlg.Update(count, u"")
176 def make_param(self) :
177 if self.paramsimi['first'] :
180 keep_coord = self.dial.check_coord.GetValue()
181 #self.select = self.dial.check_colch.GetValue()
183 paramsimi = {'coeff' : self.dial.choice1.GetSelection(),
184 'layout' : self.dial.choice2.GetSelection(),
185 'type_graph' : self.dial.choice3.GetSelection(),
186 'arbremax' : self.dial.check1.GetValue(),
187 'coeff_tv' : self.dial.check_s_size.GetValue(),
188 'coeff_tv_nb' : self.dial.spin_tv.GetValue(),
189 'tvprop' : self.dial.check2.GetValue(),
190 'tvmin' : self.dial.spin_tvmin.GetValue(),
191 'tvmax' : self.dial.spin_tvmax.GetValue(),
192 'coeff_te' : self.dial.check3.GetValue(),
193 'coeff_temin' : self.dial.spin_temin.GetValue(),
194 'coeff_temax' : self.dial.spin_temax.GetValue(),
195 'label_e' : self.dial.check_elab.GetValue(),
196 'label_v' : self.dial.check_vlab.GetValue(),
197 'vcex' : self.dial.check_vcex.GetValue(),
198 'vcexmin' : self.dial.spin_vcexmin.GetValue(),
199 'vcexmax' : self.dial.spin_vcexmax.GetValue(),
200 'cex' : self.dial.spin_cex.GetValue(),
201 'seuil_ok' : self.dial.check_seuil.GetValue(),
202 'seuil' : self.dial.spin_seuil.GetValue(),
203 'cols' : self.dial.cols.GetColour(),
204 'cola' : self.dial.cola.GetColour(),
205 'width' : self.dial.spin_width.GetValue(),
206 'height' : self.dial.spin_height.GetValue(),
208 'keep_coord' : keep_coord,
209 'alpha' : self.dial.slider_sphere.GetValue(),
210 'film' : self.dial.film.GetValue(),
211 'svg' : self.dial.choix_format.GetSelection(),
212 'halo' : self.dial.halo.GetValue(),
213 'com' : self.dial.comcheck.GetValue(),
214 'communities' :self.dial.choix_com.GetSelection(),
216 if 'cexfromchi' in self.paramsimi :
217 paramsimi['cexfromchi'] = self.dial.checkit.GetValue()
218 if 'sfromchi' in self.paramsimi :
219 paramsimi['sfromchi'] = self.dial.checki.GetValue()
220 if 'vlabcolor' in self.paramsimi :
221 paramsimi['vlabcolor'] = self.paramsimi['vlabcolor']
222 if 'check_bystar' in dir(self.dial) :
223 paramsimi['bystar'] = self.dial.check_bystar.GetValue()
224 paramsimi['stars'] = self.paramsimi['stars']
225 if 'tmpchi' in self.paramsimi :
226 paramsimi['tmpchi'] = self.paramsimi['tmpchi']
231 if self.parametres['type_graph'] == 1:
232 if self.parametres['svg'] :
233 filename, ext = os.path.splitext(self.script.filename)
234 fileout = filename + '.svg'
236 fileout = self.script.filename
237 if os.path.exists(self.DictPathOut['liste_graph']):
238 graph_simi = read_list_file(self.DictPathOut['liste_graph'])
239 graph_simi.append([os.path.basename(fileout), self.script.txtgraph])
241 graph_simi = [[os.path.basename(fileout), self.script.txtgraph]]
242 print_liste(self.DictPathOut['liste_graph'], graph_simi)
245 if self.paramsimi['type_graph'] == 1 :
251 pid = exec_rcode(self.ira.RPath, self.tmpfile, wait = wait, graph = graph)
252 if self.paramsimi['type_graph'] == 1 :
253 while pid.poll() == None :
259 check_Rresult(self.parent, pid)