60898470831c9c9bf1da7a7da394e9dedde11cfa
[iramuteq] / PrintRScript.py
1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2011 Pierre Ratinaud
4 #Lisense: GNU/GPL
5
6 import tempfile
7 from chemins import ffr
8 import os
9 import locale
10 from datetime import datetime
11 import logging
12
13 log = logging.getLogger('iramuteq.printRscript')
14
15 class PrintRScript :
16     def __init__ (self, analyse):
17         log.info('Rscript')
18         self.pathout = analyse.pathout
19         self.analyse = analyse
20         self.parametres = analyse.parametres
21         self.scriptout = self.pathout['temp']
22         self.script =  u"#Script genere par IRaMuTeQ - %s" % datetime.now().ctime()
23     
24     def add(self, txt) :
25         self.script = '\n'.join([self.script, txt])
26     
27     def defvar(self, name, value) :
28         self.add(' <- '.join([name, value]))
29
30     def defvars(self, lvars) :
31         for val in lvars :
32             self.defvar(val[0],val[1])
33
34     def sources(self, lsources) :
35         for source in lsources :
36             self.add('source("%s")' % source)
37
38     def load(self, l) :
39         for val in l :
40             self.add('load("%s")' % val)
41
42     def write(self) :
43         with open(self.scriptout, 'w') as f :
44             f.write(self.script)
45
46
47 class chdtxt(PrintRScript) :
48     pass
49
50
51 class Alceste2(PrintRScript) :
52     def doscript(self) :
53         self.sources(['chdfunct'])
54         self.load(['Rdata'])
55         lvars = [['clnb', `self.analyse.clnb`], 
56                 ['Contout', '"%s"' % self.pathout['Contout']],
57                 ['ContSupOut', '"%s"' % self.pathout['ContSupOut']],
58                 ['ContEtOut', '"%s"' % self.pathout['ContEtOut']],
59                 ['profileout', '"%s"' % self.pathout['profils.csv']],
60                 ['antiout', '"%s"' % self.pathout['antiprofils.csv']],
61                 ['chisqtable', '"%s"' % self.pathout['chisqtable.csv']],
62                 ['ptable', '"%s"' % self.pathout['ptable.csv']]]
63        
64         self.defvars(lvars) 
65
66
67
68 #    txt = "clnb<-%i\n" % clnb
69 #    txt += """
70 #source("%s")
71 #load("%s")
72 #""" % (RscriptsPath['chdfunct'], DictChdTxtOut['RData'])
73 #    txt += """
74 #dataact<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
75 #datasup<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
76 #dataet<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
77 #""" % (DictChdTxtOut['Contout'], DictChdTxtOut['ContSupOut'], DictChdTxtOut['ContEtOut'])
78 #    txt += """
79 #tablesqrpact<-BuildProf(as.matrix(dataact),n1,clnb)
80 #tablesqrpsup<-BuildProf(as.matrix(datasup),n1,clnb)
81 #tablesqrpet<-BuildProf(as.matrix(dataet),n1,clnb)
82 #"""
83 #    txt += """
84 #PrintProfile(n1,tablesqrpact[4],tablesqrpet[4],tablesqrpact[5],tablesqrpet[5],clnb,"%s","%s",tablesqrpsup[4],tablesqrpsup[5])
85 #""" % (DictChdTxtOut['PROFILE_OUT'], DictChdTxtOut['ANTIPRO_OUT'])
86 #    txt += """
87 #colnames(tablesqrpact[[2]])<-paste('classe',1:clnb,sep=' ')
88 #colnames(tablesqrpact[[1]])<-paste('classe',1:clnb,sep=' ')
89 #colnames(tablesqrpsup[[2]])<-paste('classe',1:clnb,sep=' ')
90 #colnames(tablesqrpsup[[1]])<-paste('classe',1:clnb,sep=' ')
91 #colnames(tablesqrpet[[2]])<-paste('classe',1:clnb,sep=' ')
92 #colnames(tablesqrpet[[1]])<-paste('classe',1:clnb,sep=' ')
93 #chistabletot<-rbind(tablesqrpact[2][[1]],tablesqrpsup[2][[1]])
94 #chistabletot<-rbind(chistabletot,tablesqrpet[2][[1]])
95 #ptabletot<-rbind(tablesqrpact[1][[1]],tablesqrpet[1][[1]])
96 #"""
97 #    txt += """
98 #write.csv2(chistabletot,file="%s")
99 #write.csv2(ptabletot,file="%s")
100 #gbcluster<-n1
101 #write.csv2(gbcluster,file="%s")
102 #""" % (DictChdTxtOut['chisqtable'], DictChdTxtOut['ptable'], DictChdTxtOut['SbyClasseOut'])
103 #
104
105
106 def RchdTxt(DicoPath, RscriptPath, mincl, classif_mode, nbt = 9, libsvdc = False, libsvdc_path = None, R_max_mem = False):
107     txt = """
108     source("%s")
109     source("%s")
110     source("%s")
111     source("%s")
112     """ % (RscriptPath['CHD'], RscriptPath['chdtxt'], RscriptPath['anacor'], RscriptPath['Rgraph'])
113     if R_max_mem :
114         txt += """
115     memory.limit(%i)
116         """ % R_max_mem
117
118     txt += """
119     nbt <- %i
120     """ % nbt
121     if libsvdc :
122         txt += """
123         libsvdc <- TRUE
124         libsvdc.path <- "%s"
125         """ % ffr(libsvdc_path)
126     else :
127         txt += """
128         libsvdc <- FALSE
129         libsvdc.path <- NULL
130         """
131
132     txt +="""
133     library(Matrix)
134     data1 <- readMM("%s")
135     data1 <- as(data1, "dgCMatrix")
136     row.names(data1) <- 1:nrow(data1)
137     """ % DicoPath['TableUc1']
138     
139     if classif_mode == 0:
140         txt += """
141         data2 <- readMM("%s")
142         data2 <- as(data2, "dgCMatrix")
143         row.names(data2) <- 1:nrow(data2)
144         """ % DicoPath['TableUc2']
145     txt += """
146     chd1<-CHD(data1, x = nbt, libsvdc = libsvdc, libsvdc.path = libsvdc.path)
147     """
148     
149     if classif_mode == 0:
150         txt += """
151     chd2<-CHD(data2, x = nbt, libsvdc = libsvdc, libsvdc.path = libsvdc.path)
152     """
153     else:
154         txt += """
155     chd2<-chd1
156     """    
157     
158     txt += """
159     #lecture des uce
160     listuce1<-read.csv2("%s")
161     """ % DicoPath['listeuce1']
162     
163     if classif_mode == 0:
164         txt += """
165         listuce2<-read.csv2("%s")
166         """ % DicoPath['listeuce2']
167         
168     txt += """
169 #    rm(data1)
170     """
171     
172     if classif_mode == 0:
173         txt += """
174 #        rm(data2)
175         """
176     txt += """
177     chd.result <- Rchdtxt("%s",mincl=%i,classif_mode=%i, nbt = nbt)
178     n1 <- chd.result$n1
179     classeuce1 <- chd.result$cuce1
180     classeuce2 <- chd.result$cuce2
181     """ % (DicoPath['uce'], mincl, classif_mode)
182     
183     txt += """
184     tree.tot1 <- make_tree_tot(chd1)
185 #    open_file_graph("%s", widt = 600, height=400)
186 #    plot(tree.tot1$tree.cl)
187 #    dev.off()
188     """%DicoPath['arbre1']
189     
190     if classif_mode == 0:
191         txt += """
192         tree.tot2 <- make_tree_tot(chd2)
193 #        open_file_graph("%s", width = 600, height=400)
194 #        plot(tree.tot2$tree.cl)
195 #        dev.off()
196         """ % DicoPath['arbre2']  
197               
198     txt += """
199     tree.cut1 <- make_dendro_cut_tuple(tree.tot1$dendro_tuple, chd.result$coord_ok, classeuce1, 1, nbt)
200     save(tree.cut1, file="%s")
201     classes<-n1[,ncol(n1)]
202     open_file_graph("%s", width = 600, height=400)
203     plot.dendropr(tree.cut1$tree.cl,classes)
204     open_file_graph("%s", width = 600, height=400)
205     plot(tree.cut1$dendro_tot_cl)
206     dev.off()
207     """ % (DicoPath['Rdendro'], DicoPath['dendro1'], DicoPath['arbre1'])
208     
209     if classif_mode == 0:
210         txt += """
211         tree.cut2 <- make_dendro_cut_tuple(tree.tot2$dendro_tuple, chd.result$coord_ok, classeuce2, 2, nbt)
212         open_file_graph("%s", width = 600, height=400)
213         plot(tree.cut2$tree.cl)
214         dev.off()
215         open_file_graph("%s", width = 600, height=400)
216         plot(tree.cut1$dendro_tot_cl)
217         dev.off()
218         """ % (DicoPath['dendro2'], DicoPath['arbre2'])
219         
220     txt += """
221     save.image(file="%s")
222     """ % DicoPath['RData']
223     fileout = open(DicoPath['Rchdtxt'], 'w')
224     fileout.write(txt)
225     fileout.close()
226
227 def RPamTxt(corpus, RscriptPath):
228     DicoPath = corpus.dictpathout
229     param = corpus.parametre
230     print param
231     txt = """
232     source("%s")
233     """ % (RscriptPath['pamtxt'])
234     txt += """
235     source("%s")
236     """ % (RscriptPath['Rgraph'])
237     txt += """
238     result <- pamtxt("%s", "%s", "%s", method = "%s", clust_type = "%s", clnb = %i)
239     n1 <- result$uce
240     """ % (DicoPath['TableUc1'], DicoPath['listeuce1'], DicoPath['uce'], param['method'], param['cluster_type'], param['nbcl'] )
241     txt += """
242     open_file_graph("%s", width=400, height=400)
243     plot(result$cl)
244     dev.off()
245     """ % (DicoPath['arbre1'])
246     txt += """
247     save.image(file="%s")
248     """ % DicoPath['RData']
249     fileout = open(DicoPath['Rchdtxt'], 'w')
250     fileout.write(txt)
251     fileout.close()
252     
253
254 def RchdQuest(DicoPath, RscriptPath, nbcl = 10, mincl = 10):
255     txt = """
256     source("%s")
257     source("%s")
258     source("%s")
259     source("%s")
260     """ % (RscriptPath['CHD'], RscriptPath['chdquest'], RscriptPath['anacor'],RscriptPath['Rgraph'])
261
262     txt += """
263     nbt <- %i - 1
264     mincl <- %i
265     """ % (nbcl, mincl)
266
267     txt += """
268     chd.result<-Rchdquest("%s","%s","%s", nbt = nbt, mincl = mincl)
269     n1 <- chd.result$n1
270     classeuce1 <- chd.result$cuce1
271     """ % (DicoPath['Act01'], DicoPath['listeuce1'], DicoPath['uce'])
272     
273     txt += """
274     tree_tot1 <- make_tree_tot(chd.result$chd)
275     open_file_graph("%s", width = 600, height=400)
276     plot(tree_tot1$tree.cl)
277     dev.off()
278     """%DicoPath['arbre1']
279     
280     txt += """
281     tree_cut1 <- make_dendro_cut_tuple(tree_tot1$dendro_tuple, chd.result$coord_ok, classeuce1, 1, nbt)
282     tree.cut1 <- tree_cut1
283     save(tree.cut1, file="%s")
284     open_file_graph("%s", width = 600, height=400)
285     classes<-n1[,ncol(n1)]
286     plot.dendropr(tree_cut1$tree.cl,classes)
287     """ % (DicoPath['Rdendro'],DicoPath['dendro1'])
288     
289     txt += """
290     save.image(file="%s")
291     """ % DicoPath['RData']
292     fileout = open(DicoPath['Rchdquest'], 'w')
293     fileout.write(txt)
294     fileout.close()
295     
296 def AlcesteTxtProf(DictChdTxtOut, RscriptsPath, clnb, taillecar):
297     txt = "clnb<-%i\n" % clnb
298     txt += """
299 source("%s")
300 load("%s")
301 """ % (RscriptsPath['chdfunct'], DictChdTxtOut['RData'])
302     txt += """
303 dataact<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
304 datasup<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
305 dataet<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
306 """ % (DictChdTxtOut['Contout'], DictChdTxtOut['ContSupOut'], DictChdTxtOut['ContEtOut'])
307     txt += """
308 tablesqrpact<-BuildProf(as.matrix(dataact),n1,clnb)
309 tablesqrpsup<-BuildProf(as.matrix(datasup),n1,clnb)
310 tablesqrpet<-BuildProf(as.matrix(dataet),n1,clnb)
311 """
312     txt += """
313 PrintProfile(n1,tablesqrpact[4],tablesqrpet[4],tablesqrpact[5],tablesqrpet[5],clnb,"%s","%s",tablesqrpsup[4],tablesqrpsup[5])
314 """ % (DictChdTxtOut['PROFILE_OUT'], DictChdTxtOut['ANTIPRO_OUT'])
315     txt += """
316 colnames(tablesqrpact[[2]])<-paste('classe',1:clnb,sep=' ')
317 colnames(tablesqrpact[[1]])<-paste('classe',1:clnb,sep=' ')
318 colnames(tablesqrpsup[[2]])<-paste('classe',1:clnb,sep=' ')
319 colnames(tablesqrpsup[[1]])<-paste('classe',1:clnb,sep=' ')
320 colnames(tablesqrpet[[2]])<-paste('classe',1:clnb,sep=' ')
321 colnames(tablesqrpet[[1]])<-paste('classe',1:clnb,sep=' ')
322 chistabletot<-rbind(tablesqrpact[2][[1]],tablesqrpsup[2][[1]])
323 chistabletot<-rbind(chistabletot,tablesqrpet[2][[1]])
324 ptabletot<-rbind(tablesqrpact[1][[1]],tablesqrpet[1][[1]])
325 """
326     txt += """
327 write.csv2(chistabletot,file="%s")
328 write.csv2(ptabletot,file="%s")
329 gbcluster<-n1
330 write.csv2(gbcluster,file="%s")
331 """ % (DictChdTxtOut['chisqtable'], DictChdTxtOut['ptable'], DictChdTxtOut['SbyClasseOut'])
332     if clnb > 2 :
333         txt += """
334     library(ca)
335     colnames(dataact)<-paste('classe',1:clnb,sep=' ')
336     colnames(datasup)<-paste('classe',1:clnb,sep=' ')
337     colnames(dataet)<-paste('classe',1:clnb,sep=' ')
338     rowtot<-nrow(dataact)+nrow(dataet)+nrow(datasup)
339     afctable<-rbind(as.matrix(dataact),as.matrix(datasup))
340     afctable<-rbind(afctable,as.matrix(dataet))
341     colnames(afctable)<-paste('classe',1:clnb,sep=' ')
342     afc<-ca(afctable,suprow=((nrow(dataact)+1):rowtot),nd=(ncol(afctable)-1))
343     debsup<-nrow(dataact)+1
344     debet<-nrow(dataact)+nrow(datasup)+1
345     fin<-rowtot
346     afc<-AddCorrelationOk(afc)
347     """
348     #FIXME : split this!!!
349         txt += """
350     source("%s")
351     """ % RscriptsPath['Rgraph']
352     
353         txt += """
354         afc <- summary.ca.dm(afc)
355         afc_table <- create_afc_table(afc)
356         write.csv2(afc_table$facteur, file = "%s")
357         write.csv2(afc_table$colonne, file = "%s")
358         write.csv2(afc_table$ligne, file = "%s")
359         """ % (DictChdTxtOut['afc_facteur'], DictChdTxtOut['afc_col'], DictChdTxtOut['afc_row'])
360     
361         txt += """
362         xlab <- paste('facteur 1 - ', round(afc$facteur[1,2],2), sep = '')
363         ylab <- paste('facteur 2 - ', round(afc$facteur[2,2],2), sep = '')
364         xlab <- paste(xlab, ' %', sep = '')
365         ylab <- paste(ylab, ' %', sep = '')
366         """
367     
368         txt += """
369     PARCEX<-%s
370     """ % taillecar
371         txt += """
372     PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='coord', deb=1, fin=(debsup-1), xlab = xlab, ylab = ylab)
373     """ % (DictChdTxtOut['AFC2DL_OUT'])
374         txt += """
375     PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='coord', deb=debsup, fin=(debet-1), xlab = xlab, ylab = ylab)
376     """ % (DictChdTxtOut['AFC2DSL_OUT'])
377         txt += """
378     PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='coord', deb=debet, fin=fin, xlab = xlab, ylab = ylab)
379     """ % (DictChdTxtOut['AFC2DEL_OUT'])
380         txt += """
381     PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", col=TRUE, what='coord', xlab = xlab, ylab = ylab)
382     """ % (DictChdTxtOut['AFC2DCL_OUT'])
383         txt += """
384     PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='crl', deb=1, fin=(debsup-1), xlab = xlab, ylab = ylab)
385     PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='crl', deb=debsup, fin=(debet-1), xlab = xlab, ylab = ylab)
386     PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='crl', deb=debet, fin=fin, xlab = xlab, ylab = ylab)
387     PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", col=TRUE, what='crl', xlab = xlab, ylab = ylab)
388     """ % (DictChdTxtOut['AFC2DCoul'], DictChdTxtOut['AFC2DCoulSup'], DictChdTxtOut['AFC2DCoulEt'], DictChdTxtOut['AFC2DCoulCl'])
389        
390     txt += """
391 #rm(dataact)
392 #rm(datasup)
393 #rm(dataet)
394 rm(tablesqrpact)
395 rm(tablesqrpsup)
396 rm(tablesqrpet)
397 save.image(file="%s")
398 """ % DictChdTxtOut['RData']
399     file = open(DictChdTxtOut['RTxtProfGraph'], 'w')
400     file.write(txt)
401     file.close()
402
403
404 def write_afc_graph(self):
405     if self.param['over'] : over = 'TRUE'
406     else : over = 'FALSE'
407
408     if self.param['do_select_nb'] : do_select_nb = 'TRUE'
409     else : do_select_nb = 'FALSE'
410
411     if self.param['do_select_chi'] : do_select_chi = 'TRUE'
412     else : do_select_chi = 'FALSE'
413
414     if self.param['cex_txt'] : cex_txt = 'TRUE'
415     else : cex_txt = 'FALSE'
416
417     if self.param['tchi'] : tchi = 'TRUE'
418     else : tchi = 'FALSE'
419
420     with open(self.RscriptsPath['afc_graph'], 'r') as f:
421         txt = f.read()
422
423 #    self.DictPathOut['RData'], \
424     scripts = txt % (self.RscriptsPath['Rgraph'],\
425     self.param['typegraph'], \
426     self.param['what'], \
427     self.param['facteur'][0],\
428     self.param['facteur'][1], \
429     self.param['facteur'][2], \
430     self.param['qui'], \
431     over,  do_select_nb, \
432     self.param['select_nb'],  \
433     do_select_chi, \
434     self.param['select_chi'], \
435     cex_txt, \
436     self.param['txt_min'], \
437     self.param['txt_max'], \
438     self.fileout, \
439     self.param['width'], \
440     self.param['height'],\
441     self.param['taillecar'], \
442     self.param['alpha'], \
443     self.param['film'], \
444     tchi,\
445     self.param['tchi_min'],\
446     self.param['tchi_max'],\
447     ffr(os.path.dirname(self.fileout)))
448     return scripts
449         
450 def print_simi3d(self):
451     simi3d = self.parent.simi3dpanel
452     txt = '#Fichier genere par Iramuteq'
453     if simi3d.movie.GetValue() :
454         movie = "'" + ffr(os.path.dirname(self.DictPathOut['RData'])) + "'"
455     else :
456         movie = 'NULL'
457     if self.section == 'chd_dist_quest' :
458         header = 'TRUE'
459     else :
460         header = 'FALSE'
461     txt += """
462     dm<-read.csv2("%s",row.names=1,header = %s)
463     load("%s")
464     """ % (self.DictPathOut['Contout'], header, self.DictPathOut['RData'])
465     
466     txt += """
467     source("%s")
468     """ % self.parent.RscriptsPath['Rgraph']
469
470
471     txt += """
472     make.simi.afc(dm,chistabletot, lim=%i, alpha = %.2f, movie = %s)
473     """ % (simi3d.spin_1.GetValue(), float(simi3d.slider_1.GetValue())/100, movie)
474     tmpfile = tempfile.mktemp(dir=self.parent.TEMPDIR)
475     tmp = open(tmpfile,'w')
476     tmp.write(txt)
477     tmp.close()
478     return tmpfile
479
480 def dendroandbarplot(table, rownames, colnames, rgraph, tmpgraph, intxt = False, dendro=False) :
481     if not intxt :
482         txttable = 'c(' + ','.join([','.join(line) for line in table]) + ')'
483     rownb = len(rownames)
484     rownames = 'c("' + '","'.join(rownames) + '")'
485     colnames = 'c("' + '","'.join(colnames) + '")'
486     if not intxt :
487         #FIXME
488         txt = """
489             di <- matrix(data=%s, nrow=%i, byrow = TRUE)
490             rownames(di)<- %s
491             colnames(di) <- %s
492         """ % (txttable, rownb, rownames, colnames)
493     else :
494         txt = intxt
495     txt += """
496         load("%s")
497         library(ape)
498         source("%s")
499         height <- (30*ncol(di)) + (15*nrow(di))
500         height <- ifelse(height <= 400, 400, height)
501         width <- 500
502         open_file_graph("%s", width=width, height=height)
503         plot.dendro.lex(tree.cut1$tree.cl, di)
504         """ % (ffr(dendro),ffr(rgraph),  ffr(tmpgraph))
505     return txt
506
507 def barplot(table, rownames, colnames, rgraph, tmpgraph, intxt = False) :
508     if not intxt :
509         txttable = 'c(' + ','.join([','.join(line) for line in table]) + ')'
510     #width = 100 + (15 * len(rownames)) + (100 * len(colnames))
511     #height =  len(rownames) * 15
512     rownb = len(rownames)
513     #if height < 400 :
514     #    height = 400
515     rownames = 'c("' + '","'.join(rownames) + '")'
516     colnames = 'c("' + '","'.join(colnames) + '")'
517     if not intxt :
518         #FIXME
519         txt = """
520             inf <- NA
521             di <- matrix(data=%s, nrow=%i, byrow = TRUE)
522             di[is.na(di)] <- max(di, na.rm=TRUE) + 2
523             rownames(di)<- %s
524             colnames(di) <- %s
525         """ % (txttable, rownb, rownames, colnames)
526     else :
527         txt = intxt
528     txt += """
529         source("%s")
530         color = rainbow(nrow(di))
531         width <- 100 + (20*length(rownames(di))) + (100 * length(colnames(di)))
532         height <- nrow(di) * 15
533         if (height < 400) { height <- 400}
534         open_file_graph("%s",width = width, height = height)
535         par(mar=c(0,0,0,0))
536             layout(matrix(c(1,2),1,2, byrow=TRUE),widths=c(3,lcm(7)))
537         par(mar=c(2,2,1,0))
538         coord <- barplot(as.matrix(di), beside = TRUE, col = color, space = c(0.1,0.6))
539         c <- colMeans(coord)
540         c1 <- c[-1]
541         c2 <- c[-length(c)]
542         cc <- cbind(c1,c2)
543         lcoord <- apply(cc, 1, mean)
544         abline(v=lcoord)
545         if (min(di) < 0) {
546             amp <- abs(max(di) - min(di))
547         } else {
548             amp <- max(di)
549         }
550         if (amp < 10) {
551             d <- 2
552         } else {
553             d <- signif(amp%%/%%10,1)
554         }
555         mn <- round(min(di))
556         mx <- round(max(di))
557         for (i in mn:mx) {
558             if ((i/d) == (i%%/%%d)) { 
559                 abline(h=i,lty=3)
560             }
561         }
562         par(mar=c(0,0,0,0))
563         plot(0, axes = FALSE, pch = '')
564         legend(x = 'center' , rownames(di), fill = color)
565         dev.off()
566         """ % (rgraph, ffr(tmpgraph))    
567     return txt
568
569 #def RAfcUci(DictAfcUciOut, nd=2, RscriptsPath='', PARCEX='0.8'):
570 #    txt = """
571 #    library(ca)
572 #    nd<-%i
573 #    """ % nd
574 #    txt += """
575 #    dataact<-read.csv2("%s")
576 #    """ % (DictAfcUciOut['TableCont'])#, encoding)
577 #    txt += """
578 #    datasup<-read.csv2("%s")
579 #    """ % (DictAfcUciOut['TableSup'])#, encoding)
580 #    txt += """
581 #    dataet<-read.csv2("%s")
582 #    """ % (DictAfcUciOut['TableEt'])#, encoding)
583 #    txt += """
584 #    datatotsup<-cbind(dataact,datasup)
585 #    datatotet<-cbind(dataact,dataet)
586 #    afcact<-ca(dataact,nd=nd)
587 #    afcsup<-ca(datatotsup,supcol=((ncol(dataact)+1):ncol(datatotsup)),nd=nd)
588 #    afcet<-ca(datatotet,supcol=((ncol(dataact)+1):ncol(datatotet)),nd=nd)
589 #    afctot<-afcsup$colcoord
590 #    rownames(afctot)<-afcsup$colnames
591 #    colnames(afctot)<-paste('coord. facteur',1:nd,sep=' ')
592 #    afctot<-cbind(afctot,mass=afcsup$colmass)
593 #    afctot<-cbind(afctot,distance=afcsup$coldist)
594 #    afctot<-cbind(afctot,intertie=afcsup$colinertia)
595 #    rcolet<-afcet$colsup
596 #    afctmp<-afcet$colcoord[rcolet,]
597 #    rownames(afctmp)<-afcet$colnames[rcolet]
598 #    afctmp<-cbind(afctmp,afcet$colmass[rcolet])
599 #    afctmp<-cbind(afctmp,afcet$coldist[rcolet])
600 #    afctmp<-cbind(afctmp,afcet$colinertia[rcolet])
601 #    afctot<-rbind(afctot,afctmp)
602 #    write.csv2(afctot,file = "%s")
603 #    source("%s")
604 #    """ % (DictAfcUciOut['afc_row'], RscriptsPath['Rgraph'])
605 #    txt += """
606 #    PARCEX=%s
607 #    """ % PARCEX
608 #    #FIXME
609 #    txt += """
610 #    PlotAfc(afcet,filename="%s",toplot=c%s, PARCEX=PARCEX)
611 #    """ % (DictAfcUciOut['AfcColAct'], "('none','active')")
612 #    txt += """
613 #    PlotAfc(afcsup,filename="%s",toplot=c%s, PARCEX=PARCEX)
614 #    """ % (DictAfcUciOut['AfcColSup'], "('none','passive')")
615 #    txt += """PlotAfc(afcet,filename="%s", toplot=c%s, PARCEX=PARCEX)
616 #    """ % (DictAfcUciOut['AfcColEt'], "('none','passive')")
617 #    txt += """
618 #    PlotAfc(afcet,filename="%s", toplot=c%s, PARCEX=PARCEX)
619 #    """ % (DictAfcUciOut['AfcRow'], "('all','none')")
620 #    f = open(DictAfcUciOut['Rafcuci'], 'w')
621 #    f.write(txt)
622 #    f.close()
623