1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2011 Pierre Ratinaud
7 from chemins import ffr
10 from datetime import datetime
13 log = logging.getLogger('iramuteq.printRscript')
16 def __init__ (self, analyse):
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()
25 self.script = '\n'.join([self.script, txt])
27 def defvar(self, name, value) :
28 self.add(' <- '.join([name, value]))
30 def defvars(self, lvars) :
32 self.defvar(val[0],val[1])
34 def sources(self, lsources) :
35 for source in lsources :
36 self.add('source("%s")' % source)
38 def packages(self, lpks) :
40 self.add('library(%s)' % pk)
44 self.add('load("%s")' % val)
47 with open(self.scriptout, 'w') as f :
51 class chdtxt(PrintRScript) :
55 class Alceste2(PrintRScript) :
57 self.sources(['chdfunct'])
59 lvars = [['clnb', `self.analyse.clnb`],
60 ['Contout', '"%s"' % self.pathout['Contout']],
61 ['ContSupOut', '"%s"' % self.pathout['ContSupOut']],
62 ['ContEtOut', '"%s"' % self.pathout['ContEtOut']],
63 ['profileout', '"%s"' % self.pathout['profils.csv']],
64 ['antiout', '"%s"' % self.pathout['antiprofils.csv']],
65 ['chisqtable', '"%s"' % self.pathout['chisqtable.csv']],
66 ['ptable', '"%s"' % self.pathout['ptable.csv']]]
72 # txt = "clnb<-%i\n" % clnb
76 #""" % (RscriptsPath['chdfunct'], DictChdTxtOut['RData'])
78 #dataact<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
79 #datasup<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
80 #dataet<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
81 #""" % (DictChdTxtOut['Contout'], DictChdTxtOut['ContSupOut'], DictChdTxtOut['ContEtOut'])
83 #tablesqrpact<-BuildProf(as.matrix(dataact),n1,clnb)
84 #tablesqrpsup<-BuildProf(as.matrix(datasup),n1,clnb)
85 #tablesqrpet<-BuildProf(as.matrix(dataet),n1,clnb)
88 #PrintProfile(n1,tablesqrpact[4],tablesqrpet[4],tablesqrpact[5],tablesqrpet[5],clnb,"%s","%s",tablesqrpsup[4],tablesqrpsup[5])
89 #""" % (DictChdTxtOut['PROFILE_OUT'], DictChdTxtOut['ANTIPRO_OUT'])
91 #colnames(tablesqrpact[[2]])<-paste('classe',1:clnb,sep=' ')
92 #colnames(tablesqrpact[[1]])<-paste('classe',1:clnb,sep=' ')
93 #colnames(tablesqrpsup[[2]])<-paste('classe',1:clnb,sep=' ')
94 #colnames(tablesqrpsup[[1]])<-paste('classe',1:clnb,sep=' ')
95 #colnames(tablesqrpet[[2]])<-paste('classe',1:clnb,sep=' ')
96 #colnames(tablesqrpet[[1]])<-paste('classe',1:clnb,sep=' ')
97 #chistabletot<-rbind(tablesqrpact[2][[1]],tablesqrpsup[2][[1]])
98 #chistabletot<-rbind(chistabletot,tablesqrpet[2][[1]])
99 #ptabletot<-rbind(tablesqrpact[1][[1]],tablesqrpet[1][[1]])
102 #write.csv2(chistabletot,file="%s")
103 #write.csv2(ptabletot,file="%s")
105 #write.csv2(gbcluster,file="%s")
106 #""" % (DictChdTxtOut['chisqtable'], DictChdTxtOut['ptable'], DictChdTxtOut['SbyClasseOut'])
110 def RchdTxt(DicoPath, RscriptPath, mincl, classif_mode, nbt = 9, libsvdc = False, libsvdc_path = None, R_max_mem = False):
116 """ % (RscriptPath['CHD'], RscriptPath['chdtxt'], RscriptPath['anacor'], RscriptPath['Rgraph'])
129 """ % ffr(libsvdc_path)
138 data1 <- readMM("%s")
139 data1 <- as(data1, "dgCMatrix")
140 row.names(data1) <- 1:nrow(data1)
141 """ % DicoPath['TableUc1']
143 if classif_mode == 0:
145 data2 <- readMM("%s")
146 data2 <- as(data2, "dgCMatrix")
147 row.names(data2) <- 1:nrow(data2)
148 """ % DicoPath['TableUc2']
150 chd1<-CHD(data1, x = nbt, libsvdc = libsvdc, libsvdc.path = libsvdc.path)
153 if classif_mode == 0:
155 chd2<-CHD(data2, x = nbt, libsvdc = libsvdc, libsvdc.path = libsvdc.path)
164 listuce1<-read.csv2("%s")
165 """ % DicoPath['listeuce1']
167 if classif_mode == 0:
169 listuce2<-read.csv2("%s")
170 """ % DicoPath['listeuce2']
176 if classif_mode == 0:
181 chd.result <- Rchdtxt("%s",mincl=%i,classif_mode=%i, nbt = nbt)
183 classeuce1 <- chd.result$cuce1
184 classeuce2 <- chd.result$cuce2
185 """ % (DicoPath['uce'], mincl, classif_mode)
188 tree.tot1 <- make_tree_tot(chd1)
189 # open_file_graph("%s", widt = 600, height=400)
190 # plot(tree.tot1$tree.cl)
192 """%DicoPath['arbre1']
194 if classif_mode == 0:
196 tree.tot2 <- make_tree_tot(chd2)
197 # open_file_graph("%s", width = 600, height=400)
198 # plot(tree.tot2$tree.cl)
200 """ % DicoPath['arbre2']
203 tree.cut1 <- make_dendro_cut_tuple(tree.tot1$dendro_tuple, chd.result$coord_ok, classeuce1, 1, nbt)
204 save(tree.cut1, file="%s")
205 classes<-n1[,ncol(n1)]
206 open_file_graph("%s", width = 600, height=400)
207 plot.dendropr(tree.cut1$tree.cl,classes)
208 open_file_graph("%s", width = 600, height=400)
209 plot(tree.cut1$dendro_tot_cl)
211 """ % (DicoPath['Rdendro'], DicoPath['dendro1'], DicoPath['arbre1'])
213 if classif_mode == 0:
215 tree.cut2 <- make_dendro_cut_tuple(tree.tot2$dendro_tuple, chd.result$coord_ok, classeuce2, 2, nbt)
216 open_file_graph("%s", width = 600, height=400)
217 plot(tree.cut2$tree.cl)
219 open_file_graph("%s", width = 600, height=400)
220 plot(tree.cut1$dendro_tot_cl)
222 """ % (DicoPath['dendro2'], DicoPath['arbre2'])
225 save.image(file="%s")
226 """ % DicoPath['RData']
227 fileout = open(DicoPath['Rchdtxt'], 'w')
231 def RPamTxt(corpus, RscriptPath):
232 DicoPath = corpus.dictpathout
233 param = corpus.parametre
237 """ % (RscriptPath['pamtxt'])
240 """ % (RscriptPath['Rgraph'])
242 result <- pamtxt("%s", "%s", "%s", method = "%s", clust_type = "%s", clnb = %i)
244 """ % (DicoPath['TableUc1'], DicoPath['listeuce1'], DicoPath['uce'], param['method'], param['cluster_type'], param['nbcl'] )
246 open_file_graph("%s", width=400, height=400)
249 """ % (DicoPath['arbre1'])
251 save.image(file="%s")
252 """ % DicoPath['RData']
253 fileout = open(DicoPath['Rchdtxt'], 'w')
258 def RchdQuest(DicoPath, RscriptPath, nbcl = 10, mincl = 10):
264 """ % (RscriptPath['CHD'], RscriptPath['chdquest'], RscriptPath['anacor'],RscriptPath['Rgraph'])
272 chd.result<-Rchdquest("%s","%s","%s", nbt = nbt, mincl = mincl)
274 classeuce1 <- chd.result$cuce1
275 """ % (DicoPath['Act01'], DicoPath['listeuce1'], DicoPath['uce'])
278 tree_tot1 <- make_tree_tot(chd.result$chd)
279 open_file_graph("%s", width = 600, height=400)
280 plot(tree_tot1$tree.cl)
282 """%DicoPath['arbre1']
285 tree_cut1 <- make_dendro_cut_tuple(tree_tot1$dendro_tuple, chd.result$coord_ok, classeuce1, 1, nbt)
286 tree.cut1 <- tree_cut1
287 save(tree.cut1, file="%s")
288 open_file_graph("%s", width = 600, height=400)
289 classes<-n1[,ncol(n1)]
290 plot.dendropr(tree_cut1$tree.cl,classes)
291 """ % (DicoPath['Rdendro'],DicoPath['dendro1'])
294 save.image(file="%s")
295 """ % DicoPath['RData']
296 fileout = open(DicoPath['Rchdquest'], 'w')
300 def AlcesteTxtProf(DictChdTxtOut, RscriptsPath, clnb, taillecar):
301 txt = "clnb<-%i\n" % clnb
305 """ % (RscriptsPath['chdfunct'], DictChdTxtOut['RData'])
307 dataact<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
308 datasup<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
309 dataet<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
310 """ % (DictChdTxtOut['Contout'], DictChdTxtOut['ContSupOut'], DictChdTxtOut['ContEtOut'])
312 tablesqrpact<-BuildProf(as.matrix(dataact),n1,clnb)
313 tablesqrpsup<-BuildProf(as.matrix(datasup),n1,clnb)
314 tablesqrpet<-BuildProf(as.matrix(dataet),n1,clnb)
317 PrintProfile(n1,tablesqrpact[4],tablesqrpet[4],tablesqrpact[5],tablesqrpet[5],clnb,"%s","%s",tablesqrpsup[4],tablesqrpsup[5])
318 """ % (DictChdTxtOut['PROFILE_OUT'], DictChdTxtOut['ANTIPRO_OUT'])
320 colnames(tablesqrpact[[2]])<-paste('classe',1:clnb,sep=' ')
321 colnames(tablesqrpact[[1]])<-paste('classe',1:clnb,sep=' ')
322 colnames(tablesqrpsup[[2]])<-paste('classe',1:clnb,sep=' ')
323 colnames(tablesqrpsup[[1]])<-paste('classe',1:clnb,sep=' ')
324 colnames(tablesqrpet[[2]])<-paste('classe',1:clnb,sep=' ')
325 colnames(tablesqrpet[[1]])<-paste('classe',1:clnb,sep=' ')
326 chistabletot<-rbind(tablesqrpact[2][[1]],tablesqrpsup[2][[1]])
327 chistabletot<-rbind(chistabletot,tablesqrpet[2][[1]])
328 ptabletot<-rbind(tablesqrpact[1][[1]],tablesqrpet[1][[1]])
331 write.csv2(chistabletot,file="%s")
332 write.csv2(ptabletot,file="%s")
334 write.csv2(gbcluster,file="%s")
335 """ % (DictChdTxtOut['chisqtable'], DictChdTxtOut['ptable'], DictChdTxtOut['SbyClasseOut'])
339 colnames(dataact)<-paste('classe',1:clnb,sep=' ')
340 colnames(datasup)<-paste('classe',1:clnb,sep=' ')
341 colnames(dataet)<-paste('classe',1:clnb,sep=' ')
342 rowtot<-nrow(dataact)+nrow(dataet)+nrow(datasup)
343 afctable<-rbind(as.matrix(dataact),as.matrix(datasup))
344 afctable<-rbind(afctable,as.matrix(dataet))
345 colnames(afctable)<-paste('classe',1:clnb,sep=' ')
346 afc<-ca(afctable,suprow=((nrow(dataact)+1):rowtot),nd=(ncol(afctable)-1))
347 debsup<-nrow(dataact)+1
348 debet<-nrow(dataact)+nrow(datasup)+1
350 afc<-AddCorrelationOk(afc)
352 #FIXME : split this!!!
355 """ % RscriptsPath['Rgraph']
358 afc <- summary.ca.dm(afc)
359 afc_table <- create_afc_table(afc)
360 write.csv2(afc_table$facteur, file = "%s")
361 write.csv2(afc_table$colonne, file = "%s")
362 write.csv2(afc_table$ligne, file = "%s")
363 """ % (DictChdTxtOut['afc_facteur'], DictChdTxtOut['afc_col'], DictChdTxtOut['afc_row'])
366 xlab <- paste('facteur 1 - ', round(afc$facteur[1,2],2), sep = '')
367 ylab <- paste('facteur 2 - ', round(afc$facteur[2,2],2), sep = '')
368 xlab <- paste(xlab, ' %', sep = '')
369 ylab <- paste(ylab, ' %', sep = '')
376 PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='coord', deb=1, fin=(debsup-1), xlab = xlab, ylab = ylab)
377 """ % (DictChdTxtOut['AFC2DL_OUT'])
379 PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='coord', deb=debsup, fin=(debet-1), xlab = xlab, ylab = ylab)
380 """ % (DictChdTxtOut['AFC2DSL_OUT'])
382 PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='coord', deb=debet, fin=fin, xlab = xlab, ylab = ylab)
383 """ % (DictChdTxtOut['AFC2DEL_OUT'])
385 PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", col=TRUE, what='coord', xlab = xlab, ylab = ylab)
386 """ % (DictChdTxtOut['AFC2DCL_OUT'])
388 PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='crl', deb=1, fin=(debsup-1), xlab = xlab, ylab = ylab)
389 PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='crl', deb=debsup, fin=(debet-1), xlab = xlab, ylab = ylab)
390 PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='crl', deb=debet, fin=fin, xlab = xlab, ylab = ylab)
391 PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", col=TRUE, what='crl', xlab = xlab, ylab = ylab)
392 """ % (DictChdTxtOut['AFC2DCoul'], DictChdTxtOut['AFC2DCoulSup'], DictChdTxtOut['AFC2DCoulEt'], DictChdTxtOut['AFC2DCoulCl'])
401 save.image(file="%s")
402 """ % DictChdTxtOut['RData']
403 file = open(DictChdTxtOut['RTxtProfGraph'], 'w')
408 def write_afc_graph(self):
409 if self.param['over'] : over = 'TRUE'
410 else : over = 'FALSE'
412 if self.param['do_select_nb'] : do_select_nb = 'TRUE'
413 else : do_select_nb = 'FALSE'
415 if self.param['do_select_chi'] : do_select_chi = 'TRUE'
416 else : do_select_chi = 'FALSE'
418 if self.param['cex_txt'] : cex_txt = 'TRUE'
419 else : cex_txt = 'FALSE'
421 if self.param['tchi'] : tchi = 'TRUE'
422 else : tchi = 'FALSE'
424 with open(self.RscriptsPath['afc_graph'], 'r') as f:
427 # self.DictPathOut['RData'], \
428 scripts = txt % (self.RscriptsPath['Rgraph'],\
429 self.param['typegraph'], \
430 self.param['what'], \
431 self.param['facteur'][0],\
432 self.param['facteur'][1], \
433 self.param['facteur'][2], \
435 over, do_select_nb, \
436 self.param['select_nb'], \
438 self.param['select_chi'], \
440 self.param['txt_min'], \
441 self.param['txt_max'], \
443 self.param['width'], \
444 self.param['height'],\
445 self.param['taillecar'], \
446 self.param['alpha'], \
447 self.param['film'], \
449 self.param['tchi_min'],\
450 self.param['tchi_max'],\
451 ffr(os.path.dirname(self.fileout)))
454 def print_simi3d(self):
455 simi3d = self.parent.simi3dpanel
456 txt = '#Fichier genere par Iramuteq'
457 if simi3d.movie.GetValue() :
458 movie = "'" + ffr(os.path.dirname(self.DictPathOut['RData'])) + "'"
461 if self.section == 'chd_dist_quest' :
466 dm<-read.csv2("%s",row.names=1,header = %s)
468 """ % (self.DictPathOut['Contout'], header, self.DictPathOut['RData'])
472 """ % self.parent.RscriptsPath['Rgraph']
476 make.simi.afc(dm,chistabletot, lim=%i, alpha = %.2f, movie = %s)
477 """ % (simi3d.spin_1.GetValue(), float(simi3d.slider_1.GetValue())/100, movie)
478 tmpfile = tempfile.mktemp(dir=self.parent.TEMPDIR)
479 tmp = open(tmpfile,'w')
484 def dendroandbarplot(table, rownames, colnames, rgraph, tmpgraph, intxt = False, dendro=False) :
486 txttable = 'c(' + ','.join([','.join(line) for line in table]) + ')'
487 rownb = len(rownames)
488 rownames = 'c("' + '","'.join(rownames) + '")'
489 colnames = 'c("' + '","'.join(colnames) + '")'
493 di <- matrix(data=%s, nrow=%i, byrow = TRUE)
496 """ % (txttable, rownb, rownames, colnames)
503 height <- (30*ncol(di)) + (15*nrow(di))
504 height <- ifelse(height <= 400, 400, height)
506 open_file_graph("%s", width=width, height=height)
507 plot.dendro.lex(tree.cut1$tree.cl, di)
508 """ % (ffr(dendro),ffr(rgraph), ffr(tmpgraph))
511 def barplot(table, rownames, colnames, rgraph, tmpgraph, intxt = False) :
513 txttable = 'c(' + ','.join([','.join(line) for line in table]) + ')'
514 #width = 100 + (15 * len(rownames)) + (100 * len(colnames))
515 #height = len(rownames) * 15
516 rownb = len(rownames)
519 rownames = 'c("' + '","'.join(rownames) + '")'
520 colnames = 'c("' + '","'.join(colnames) + '")'
525 di <- matrix(data=%s, nrow=%i, byrow = TRUE)
526 di[is.na(di)] <- max(di, na.rm=TRUE) + 2
529 """ % (txttable, rownb, rownames, colnames)
534 color = rainbow(nrow(di))
535 width <- 100 + (20*length(rownames(di))) + (100 * length(colnames(di)))
536 height <- nrow(di) * 15
537 if (height < 400) { height <- 400}
538 open_file_graph("%s",width = width, height = height)
540 layout(matrix(c(1,2),1,2, byrow=TRUE),widths=c(3,lcm(7)))
542 coord <- barplot(as.matrix(di), beside = TRUE, col = color, space = c(0.1,0.6))
547 lcoord <- apply(cc, 1, mean)
550 amp <- abs(max(di) - min(di))
557 d <- signif(amp%%/%%10,1)
562 if ((i/d) == (i%%/%%d)) {
567 plot(0, axes = FALSE, pch = '')
568 legend(x = 'center' , rownames(di), fill = color)
570 """ % (rgraph, ffr(tmpgraph))
573 #def RAfcUci(DictAfcUciOut, nd=2, RscriptsPath='', PARCEX='0.8'):
579 # dataact<-read.csv2("%s")
580 # """ % (DictAfcUciOut['TableCont'])#, encoding)
582 # datasup<-read.csv2("%s")
583 # """ % (DictAfcUciOut['TableSup'])#, encoding)
585 # dataet<-read.csv2("%s")
586 # """ % (DictAfcUciOut['TableEt'])#, encoding)
588 # datatotsup<-cbind(dataact,datasup)
589 # datatotet<-cbind(dataact,dataet)
590 # afcact<-ca(dataact,nd=nd)
591 # afcsup<-ca(datatotsup,supcol=((ncol(dataact)+1):ncol(datatotsup)),nd=nd)
592 # afcet<-ca(datatotet,supcol=((ncol(dataact)+1):ncol(datatotet)),nd=nd)
593 # afctot<-afcsup$colcoord
594 # rownames(afctot)<-afcsup$colnames
595 # colnames(afctot)<-paste('coord. facteur',1:nd,sep=' ')
596 # afctot<-cbind(afctot,mass=afcsup$colmass)
597 # afctot<-cbind(afctot,distance=afcsup$coldist)
598 # afctot<-cbind(afctot,intertie=afcsup$colinertia)
599 # rcolet<-afcet$colsup
600 # afctmp<-afcet$colcoord[rcolet,]
601 # rownames(afctmp)<-afcet$colnames[rcolet]
602 # afctmp<-cbind(afctmp,afcet$colmass[rcolet])
603 # afctmp<-cbind(afctmp,afcet$coldist[rcolet])
604 # afctmp<-cbind(afctmp,afcet$colinertia[rcolet])
605 # afctot<-rbind(afctot,afctmp)
606 # write.csv2(afctot,file = "%s")
608 # """ % (DictAfcUciOut['afc_row'], RscriptsPath['Rgraph'])
614 # PlotAfc(afcet,filename="%s",toplot=c%s, PARCEX=PARCEX)
615 # """ % (DictAfcUciOut['AfcColAct'], "('none','active')")
617 # PlotAfc(afcsup,filename="%s",toplot=c%s, PARCEX=PARCEX)
618 # """ % (DictAfcUciOut['AfcColSup'], "('none','passive')")
619 # txt += """PlotAfc(afcet,filename="%s", toplot=c%s, PARCEX=PARCEX)
620 # """ % (DictAfcUciOut['AfcColEt'], "('none','passive')")
622 # PlotAfc(afcet,filename="%s", toplot=c%s, PARCEX=PARCEX)
623 # """ % (DictAfcUciOut['AfcRow'], "('all','none')")
624 # f = open(DictAfcUciOut['Rafcuci'], 'w')
628 class PrintSimiScript(PrintRScript) :
629 def make_script(self) :
631 self.packages(['igraph', 'proxy', 'Matrix'])
632 self.sources([self.analyse.parent.RscriptsPath['simi'], self.analyse.parent.RscriptsPath['Rgraph']])
637 """ % (self.pathout['mat01.csv'], self.pathout['actives.csv'], self.pathout['selected.csv'])
640 cn <- read.table(cn.path, sep=';', quote='"')
641 colnames(dm) <- cn[,1]
642 sel.col <- read.csv2(selected.col)
643 dm <- dm[, sel.col[,1] + 1]
646 if self.parametres['coeff'] == 0 :
656 if self.parametres['coeff'] == 1 :
660 mat <- simil(dm, method = 'Russel', diag = TRUE, upper = TRUE, by_rows = FALSE)
662 elif self.analyse.indices[self.parametres['coeff']] == 'binomial' :
668 elif self.parametres['coeff'] != 0 :
669 method = self.analyse.indices[self.parametres['coeff']]
672 mat <- simil(dm, method = method, diag = TRUE, upper = TRUE, by_rows = FALSE)
673 """ % self.analyse.indices[self.parametres['coeff']]
675 mat <- as.matrix(stats::as.dist(mat,diag=TRUE,upper=TRUE))
677 mat[is.infinite(mat)] <- 0
679 if self.parametres['layout'] == 0 : layout = 'random'
680 if self.parametres['layout'] == 1 : layout = 'circle'
681 if self.parametres['layout'] == 2 : layout = 'frutch'
682 if self.parametres['layout'] == 3 : layout = 'kawa'
683 if self.parametres['layout'] == 4 : layout = 'graphopt'
686 if self.parametres['type_graph'] == 0 : type = 'tkplot'
687 if self.parametres['type_graph'] == 1 :
690 dirout = os.path.dirname(self.pathout['mat01'])
691 while os.path.exists(os.path.join(dirout,'graph_simi_'+str(graphnb)+'.png')):
693 self.filename = ffr(os.path.join(dirout,'graph_simi_'+str(graphnb)+'.png'))
694 if self.parametres['type_graph'] == 2 : type = 'rgl'
696 if self.parametres['arbremax'] :
698 self.txtgraph += ' - arbre maximum'
699 else : arbremax = 'FALSE'
701 if self.parametres['coeff_tv'] :
702 coeff_tv = self.parametres['coeff_tv_nb']
703 tvminmax = 'c(NULL,NULL)'
704 elif not self.parametres['coeff_tv'] or self.parametres.get('sformchi', False) :
706 tvminmax = 'c(%i, %i)' %(self.parametres['tvmin'], self.parametres['tvmax'])
707 if self.parametres['coeff_te'] : coeff_te = 'c(%i,%i)' % (self.parametres['coeff_temin'], self.parametres['coeff_temax'])
708 else : coeff_te = 'NULL'
710 if self.parametres['vcex'] or self.parametres.get('cexfromchi', False) :
711 vcexminmax = 'c(%i/10,%i/10)' % (self.parametres['vcexmin'],self.parametres['vcexmax'])
713 vcexminmax = 'c(NULL,NULL)'
714 if not self.parametres['label_v'] : label_v = 'FALSE'
715 else : label_v = 'TRUE'
717 if not self.parametres['label_e'] : label_e = 'FALSE'
718 else : label_e = 'TRUE'
720 if self.parametres['seuil_ok'] : seuil = str(self.parametres['seuil'])
721 else : seuil = 'NULL'
723 cols = str(self.parametres['cols']).replace(')',', max=255)')
724 cola = str(self.parametres['cola']).replace(')',',max=255)')
734 """ % self.parametres['cex']
736 if self.parametres['film'] :
739 """ % self.pathout['film']
751 """ % (label_v, label_e)
759 """ % (self.parametres['width'], self.parametres['height'])
760 if self.parametres['keep_coord'] :
762 coords <- try(coords, TRUE)
763 if (!is.matrix(coords)) {
773 """ % self.parametres['alpha']
776 """ % self.parametres['alpha']
777 #############################################
778 if self.parametres.get('bystar',False) :
782 for i,et in enumerate(self.tableau.etline) :
785 """ % (i+1, ','.join(et[1:]))
788 """ % ("','".join([val[0] for val in self.tableau.etline]))
792 for (i in 1:length(unetoile)) {
795 if (length(tosum) > 1) {
796 fsum <- cbind(fsum, colSums(dm[tosum,]))
798 fsum <- cbind(fsum, dm[tosum,])
802 lex <- AsLexico2(fsum, chip=TRUE)
803 dcol <- apply(lex[[4]],1,which.max)
804 toblack <- apply(lex[[4]],1,max)
805 gcol <- rainbow(length(unetoile))
807 vertex.label.color <- gcol[dcol]
808 vertex.label.color[which(toblack <= 3.84)] <- 'black'
809 leg <- list(unetoile=unetoile, gcol=gcol)
810 cols <- vertex.label.color
811 chivertex.size <- norm.vec(toblack, vcexminmax[1], vcexminmax[2])
813 """ % (self.parent.RscriptsPath['chdfunct'])
816 vertex.label.color <- 'black'
820 #############################################
824 # g.ori <- graph.adjacency(mat, mode='lower', weighted = TRUE)
825 # w.ori <- E(g.ori)$weight
827 # if (method == 'cooc') {
828 # E(g.ori)$weight <- 1 / w.ori
830 # E(g.ori)$weigth <- 1 - w.ori
832 # g.max <- minimum.spanning.tree(g.ori)
833 # if (method == 'cooc') {
834 # E(g.max)$weight <- 1 / E(g.max)$weight
836 # E(g.max)$weight <- 1 - E(g.max)$weight
845 x <- list(mat = mat, eff = eff)
846 graph.simi <- do.simi(x, method='%s', seuil = seuil, p.type = '%s', layout.type = '%s', max.tree = %s, coeff.vertex=%s, coeff.edge = %s, minmaxeff = minmaxeff, vcexminmax = vcexminmax, cex = cex, coords = coords)
847 """ % (method, type, layout, arbremax, coeff_tv, coeff_te)
849 if self.parametres.get('bystar',False) :
850 if self.parametres.get('cexfromchi', False) :
852 label.cex<-chivertex.size
858 if self.parametres.get('sfromchi', False) :
860 vertex.size <- norm.vec(toblack, minmaxeff[1], minmaxeff[2])
871 lchi <- read.table("%s")
874 if 'selected_col' in dir(self.tableau) :
878 if tmpchi and self.parametres.get('cexfromchi', False) :
880 label.cex <- norm.vec(lchi, vcexminmax[1], vcexminmax[2])
884 if (is.null(vcexminmax[1])) {
887 label.cex <- graph.simi$label.cex
890 if tmpchi and self.parametres.get('sfromchi', False) :
892 vertex.size <- norm.vec(lchi, minmaxeff[1], minmaxeff[2])
896 if (is.null(minmaxeff[1])) {
899 vertex.size <- graph.simi$eff
902 txt += """ vertex.size <- NULL """
904 coords <- plot.simi(graph.simi, p.type='%s',filename="%s", vertex.label = label.v, edge.label = label.e, vertex.col = cols, vertex.label.color = vertex.label.color, vertex.label.cex=label.cex, vertex.size = vertex.size, edge.col = cola, leg=leg, width = width, height = height, alpha = alpha, movie = film)
905 save.image(file="%s")
906 """ % (type, self.filename, self.pathout['RData'])