1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2011 Pierre Ratinaud
7 from chemins import ffr, PathOut
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 = ffr(self.pathout['lastRscript.R'])
22 self.scriptout = self.pathout['temp']
23 self.script = u"#Script genere par IRaMuTeQ - %s\n" % datetime.now().ctime()
26 self.script = '\n'.join([self.script, txt])
28 def defvar(self, name, value) :
29 self.add(' <- '.join([name, value]))
31 def defvars(self, lvars) :
33 self.defvar(val[0],val[1])
35 def sources(self, lsources) :
36 for source in lsources :
37 self.add('source("%s", encoding = \'utf8\')' % ffr(source))
39 def packages(self, lpks) :
41 self.add('library(%s)' % pk)
45 self.add('load("%s")' % ffr(val))
48 with open(self.scriptout, 'w') as f :
52 class chdtxt(PrintRScript) :
56 return str(color).replace(')', ', max=255)')
58 class Alceste2(PrintRScript) :
60 self.sources(['chdfunct'])
62 lvars = [['clnb', `self.analyse.clnb`],
63 ['Contout', '"%s"' % self.pathout['Contout']],
64 ['ContSupOut', '"%s"' % self.pathout['ContSupOut']],
65 ['ContEtOut', '"%s"' % self.pathout['ContEtOut']],
66 ['profileout', '"%s"' % self.pathout['profils.csv']],
67 ['antiout', '"%s"' % self.pathout['antiprofils.csv']],
68 ['chisqtable', '"%s"' % self.pathout['chisqtable.csv']],
69 ['ptable', '"%s"' % self.pathout['ptable.csv']]]
75 # txt = "clnb<-%i\n" % clnb
79 #""" % (RscriptsPath['chdfunct'], DictChdTxtOut['RData'])
81 #dataact<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
82 #datasup<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
83 #dataet<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
84 #""" % (DictChdTxtOut['Contout'], DictChdTxtOut['ContSupOut'], DictChdTxtOut['ContEtOut'])
86 #tablesqrpact<-BuildProf(as.matrix(dataact),n1,clnb)
87 #tablesqrpsup<-BuildProf(as.matrix(datasup),n1,clnb)
88 #tablesqrpet<-BuildProf(as.matrix(dataet),n1,clnb)
91 #PrintProfile(n1,tablesqrpact[4],tablesqrpet[4],tablesqrpact[5],tablesqrpet[5],clnb,"%s","%s",tablesqrpsup[4],tablesqrpsup[5])
92 #""" % (DictChdTxtOut['PROFILE_OUT'], DictChdTxtOut['ANTIPRO_OUT'])
94 #colnames(tablesqrpact[[2]])<-paste('classe',1:clnb,sep=' ')
95 #colnames(tablesqrpact[[1]])<-paste('classe',1:clnb,sep=' ')
96 #colnames(tablesqrpsup[[2]])<-paste('classe',1:clnb,sep=' ')
97 #colnames(tablesqrpsup[[1]])<-paste('classe',1:clnb,sep=' ')
98 #colnames(tablesqrpet[[2]])<-paste('classe',1:clnb,sep=' ')
99 #colnames(tablesqrpet[[1]])<-paste('classe',1:clnb,sep=' ')
100 #chistabletot<-rbind(tablesqrpact[2][[1]],tablesqrpsup[2][[1]])
101 #chistabletot<-rbind(chistabletot,tablesqrpet[2][[1]])
102 #ptabletot<-rbind(tablesqrpact[1][[1]],tablesqrpet[1][[1]])
105 #write.csv2(chistabletot,file="%s")
106 #write.csv2(ptabletot,file="%s")
108 #write.csv2(gbcluster,file="%s")
109 #""" % (DictChdTxtOut['chisqtable'], DictChdTxtOut['ptable'], DictChdTxtOut['SbyClasseOut'])
113 def RchdTxt(DicoPath, RscriptPath, mincl, classif_mode, nbt = 9, svdmethod = 'svdR', libsvdc = False, libsvdc_path = None, R_max_mem = False, mode_patate = False):
119 """ % (ffr(RscriptPath['CHD']), ffr(RscriptPath['chdtxt']), ffr(RscriptPath['anacor']), ffr(RscriptPath['Rgraph']))
128 if svdmethod == 'svdlibc' and libsvdc :
130 svd.method <- 'svdlibc'
132 """ % ffr(libsvdc_path)
133 elif svdmethod == 'irlba' :
136 svd.method <- 'irlba'
154 data1 <- readMM("%s")
155 data1 <- as(data1, "dgCMatrix")
156 row.names(data1) <- 1:nrow(data1)
157 """ % ffr(DicoPath['TableUc1'])
159 if classif_mode == 0:
161 data2 <- readMM("%s")
162 data2 <- as(data2, "dgCMatrix")
163 row.names(data2) <- 1:nrow(data2)
164 """ % ffr(DicoPath['TableUc2'])
167 #print('FIXME : source newCHD')
168 #source('/home/pierre/workspace/iramuteq/Rscripts/newCHD.R')
169 #chd1<-CHD(data1, x = nbt, mode.patate = mode.patate, svd.method = svd.method, libsvdc.path = libsvdc.path, find='matrix', sample=20, amp=500)
170 chd1<-CHD(data1, x = nbt, mode.patate = mode.patate, svd.method = svd.method, libsvdc.path = libsvdc.path)#, log.file = log1)
171 """ % ffr(DicoPath['log-chd1.txt'])
173 if classif_mode == 0:
176 chd2<-CHD(data2, x = nbt, mode.patate = mode.patate, svd.method =
177 svd.method, libsvdc.path = libsvdc.path)#, log.file = log2)
178 """ % ffr(DicoPath['log-chd2.txt'])
182 listuce1<-read.csv2("%s")
183 """ % ffr(DicoPath['listeuce1'])
185 if classif_mode == 0:
187 listuce2<-read.csv2("%s")
188 """ % ffr(DicoPath['listeuce2'])
194 if classif_mode == 0:
201 if (mincl == 0) {mincl <- round(nrow(chd1$n1)/(nbt+1))}
203 write.csv2(chd1$n1, file="%s")
204 if (classif_mode == 0) {
205 chd.result <- Rchdtxt(uceout, chd1, chd2 = chd2, mincl = mincl,classif_mode = classif_mode, nbt = nbt)
206 classeuce1 <- chd.result$cuce1
207 tree.tot1 <- make_tree_tot(chd1)
208 tree.cut1 <- make_dendro_cut_tuple(tree.tot1$dendro_tuple, chd.result$coord_ok, classeuce1, 1, nbt)
211 #chd.result <- Rchdtxt(uceout, chd1, chd2 = chd1, mincl = mincl,classif_mode = classif_mode, nbt = nbt)
212 tree.tot1 <- make_tree_tot(chd1)
213 terminales <- find.terminales(chd1$n1, chd1$list_mere, chd1$list_fille, mincl)
214 tree.cut1 <- make.classes(terminales, chd1$n1, tree.tot1$tree.cl, chd1$list_fille)
215 write.csv2(tree.cut1$n1, uceout)
216 chd.result <- tree.cut1
218 classes<-chd.result$n1[,ncol(chd.result$n1)]
219 write.csv2(chd.result$n1, file="%s")
220 """ % (classif_mode, mincl, ffr(DicoPath['uce']), ffr(DicoPath['n1-1.csv']), ffr(DicoPath['n1.csv']))
223 # tree.tot1 <- make_tree_tot(chd1)
224 # open_file_graph("%s", widt = 600, height=400)
225 # plot(tree.tot1$tree.cl)
227 """ % ffr(DicoPath['arbre1'])
229 if classif_mode == 0:
231 classeuce2 <- chd.result$cuce2
232 tree.tot2 <- make_tree_tot(chd2)
233 # open_file_graph("%s", width = 600, height=400)
234 # plot(tree.tot2$tree.cl)
236 """ % ffr(DicoPath['arbre2'] )
239 save(tree.cut1, file="%s")
241 open_file_graph("%s", width = 600, height=400)
242 plot.dendropr(tree.cut1$tree.cl,classes, histo=TRUE)
243 open_file_graph("%s", width = 600, height=400)
244 plot(tree.cut1$dendro_tot_cl)
246 """ % (ffr(DicoPath['Rdendro']), ffr(DicoPath['dendro1']), ffr(DicoPath['arbre1']))
248 if classif_mode == 0:
250 tree.cut2 <- make_dendro_cut_tuple(tree.tot2$dendro_tuple, chd.result$coord_ok, classeuce2, 2, nbt)
251 open_file_graph("%s", width = 600, height=400)
252 plot(tree.cut2$tree.cl)
254 open_file_graph("%s", width = 600, height=400)
255 plot(tree.cut2$dendro_tot_cl)
257 """ % (ffr(DicoPath['dendro2']), ffr(DicoPath['arbre2']))
261 #save.image(file="%s")
262 """ % (ffr(DicoPath['RData']))
264 fileout = open(DicoPath['Rchdtxt'], 'w')
268 def RPamTxt(corpus, RscriptPath):
269 DicoPath = corpus.pathout
270 param = corpus.parametres
273 """ % (RscriptPath['pamtxt'])
276 """ % (RscriptPath['Rgraph'])
278 result <- pamtxt("%s", "%s", "%s", method = "%s", clust_type = "%s", clnb = %i)
280 """ % (DicoPath['TableUc1'], DicoPath['listeuce1'], DicoPath['uce'], param['method'], param['cluster_type'], param['nbcl'] )
282 open_file_graph("%s", width=400, height=400)
285 """ % (DicoPath['arbre1'])
287 save.image(file="%s")
288 """ % DicoPath['RData']
289 fileout = open(DicoPath['Rchdtxt'], 'w')
294 def RchdQuest(DicoPath, RscriptPath, nbcl = 10, mincl = 10):
300 """ % (ffr(RscriptPath['CHD']), ffr(RscriptPath['chdquest']), ffr(RscriptPath['anacor']),ffr(RscriptPath['Rgraph']))
308 chd.result<-Rchdquest("%s","%s","%s", nbt = nbt, mincl = mincl)
310 classeuce1 <- chd.result$cuce1
311 """ % (ffr(DicoPath['mat01.csv']), ffr(DicoPath['listeuce1']), ffr(DicoPath['uce']))
314 tree_tot1 <- make_tree_tot(chd.result$chd)
315 open_file_graph("%s", width = 600, height=400)
316 plot(tree_tot1$tree.cl)
318 """ % ffr(DicoPath['arbre1'])
321 tree_cut1 <- make_dendro_cut_tuple(tree_tot1$dendro_tuple, chd.result$coord_ok, classeuce1, 1, nbt)
322 tree.cut1 <- tree_cut1
323 save(tree.cut1, file="%s")
324 open_file_graph("%s", width = 600, height=400)
325 classes<-n1[,ncol(n1)]
326 plot.dendropr(tree_cut1$tree.cl,classes, histo = TRUE)
327 """ % (ffr(DicoPath['Rdendro']), ffr(DicoPath['dendro1']))
330 save.image(file="%s")
331 """ % ffr(DicoPath['RData'])
332 fileout = open(DicoPath['Rchdquest'], 'w')
336 def ReinertTxtProf(DictChdTxtOut, RscriptsPath, clnb, taillecar):
337 txt = "clnb<-%i\n" % clnb
341 n1 <- read.csv2("%s")
342 """ % (ffr(RscriptsPath['chdfunct']), ffr(DictChdTxtOut['RData']), ffr(DictChdTxtOut['n1.csv']))
344 dataact<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
345 datasup<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
346 dataet<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
347 """ % (ffr(DictChdTxtOut['Contout']), ffr(DictChdTxtOut['ContSupOut']), ffr(DictChdTxtOut['ContEtOut']))
349 print('ATTENTION NEW BUILD PROF')
350 #tablesqrpact<-BuildProf(as.matrix(dataact),n1,clnb)
351 #tablesqrpsup<-BuildProf(as.matrix(datasup),n1,clnb)
352 #tablesqrpet<-BuildProf(as.matrix(dataet),n1,clnb)
353 tablesqrpact<-new.build.prof(as.matrix(dataact),n1,clnb)
354 tablesqrpsup<-new.build.prof(as.matrix(datasup),n1,clnb)
355 tablesqrpet<-new.build.prof(as.matrix(dataet),n1,clnb)
359 PrintProfile(n1,tablesqrpact[4],tablesqrpet[4],tablesqrpact[5],tablesqrpet[5],clnb,"%s","%s",tablesqrpsup[4],tablesqrpsup[5])
360 """ % (ffr(DictChdTxtOut['PROFILE_OUT']), ffr(DictChdTxtOut['ANTIPRO_OUT']))
362 colnames(tablesqrpact[[2]])<-paste('classe',1:clnb,sep=' ')
363 colnames(tablesqrpact[[1]])<-paste('classe',1:clnb,sep=' ')
364 colnames(tablesqrpsup[[2]])<-paste('classe',1:clnb,sep=' ')
365 colnames(tablesqrpsup[[1]])<-paste('classe',1:clnb,sep=' ')
366 colnames(tablesqrpet[[2]])<-paste('classe',1:clnb,sep=' ')
367 colnames(tablesqrpet[[1]])<-paste('classe',1:clnb,sep=' ')
368 chistabletot<-rbind(tablesqrpact[2][[1]],tablesqrpsup[2][[1]])
369 chistabletot<-rbind(chistabletot,tablesqrpet[2][[1]])
370 ptabletot<-rbind(tablesqrpact[1][[1]],tablesqrpet[1][[1]])
373 write.csv2(chistabletot,file="%s")
374 write.csv2(ptabletot,file="%s")
376 write.csv2(gbcluster,file="%s")
377 """ % (ffr(DictChdTxtOut['chisqtable']), ffr(DictChdTxtOut['ptable']), ffr(DictChdTxtOut['SbyClasseOut']))
381 colnames(dataact)<-paste('classe',1:clnb,sep=' ')
382 colnames(datasup)<-paste('classe',1:clnb,sep=' ')
383 colnames(dataet)<-paste('classe',1:clnb,sep=' ')
384 rowtot<-nrow(dataact)+nrow(dataet)+nrow(datasup)
385 afctable<-rbind(as.matrix(dataact),as.matrix(datasup))
386 afctable<-rbind(afctable,as.matrix(dataet))
387 colnames(afctable)<-paste('classe',1:clnb,sep=' ')
388 afc<-ca(afctable,suprow=((nrow(dataact)+1):rowtot),nd=(ncol(afctable)-1))
389 debsup<-nrow(dataact)+1
390 debet<-nrow(dataact)+nrow(datasup)+1
392 afc<-AddCorrelationOk(afc)
394 #FIXME : split this!!!
397 """ % ffr(RscriptsPath['Rgraph'])
400 afc <- summary.ca.dm(afc)
401 afc_table <- create_afc_table(afc)
402 write.csv2(afc_table$facteur, file = "%s")
403 write.csv2(afc_table$colonne, file = "%s")
404 write.csv2(afc_table$ligne, file = "%s")
405 """ % (ffr(DictChdTxtOut['afc_facteur']), ffr(DictChdTxtOut['afc_col']), ffr(DictChdTxtOut['afc_row']))
411 xyminmax <- PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='coord', deb=1, fin=(debsup-1), xlab = xlab, ylab = ylab)
412 """ % (ffr(DictChdTxtOut['AFC2DL_OUT']))
414 PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='coord', deb=debsup, fin=(debet-1), xlab = xlab, ylab = ylab, xmin = xyminmax$xminmax[1], xmax = xyminmax$xminmax[2], ymin = xyminmax$yminmax[1], ymax = xyminmax$yminmax[2], active=FALSE)
415 """ % (ffr(DictChdTxtOut['AFC2DSL_OUT']))
417 if ((fin - debet) > 2) {
418 PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='coord', deb=debet, fin=fin, xlab = xlab, ylab = ylab, xmin = xyminmax$xminmax[1], xmax = xyminmax$xminmax[2], ymin = xyminmax$yminmax[1], ymax = xyminmax$yminmax[2], active = FALSE)
420 """ % (ffr(DictChdTxtOut['AFC2DEL_OUT']))
422 PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", col=TRUE, what='coord', xlab = xlab, ylab = ylab, xmin = xyminmax$xminmax[1], xmax = xyminmax$xminmax[2], ymin = xyminmax$yminmax[1], ymax = xyminmax$yminmax[2], active=FALSE)
423 """ % (ffr(DictChdTxtOut['AFC2DCL_OUT']))
425 # PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='crl', deb=1, fin=(debsup-1), xlab = xlab, ylab = ylab)
426 # PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='crl', deb=debsup, fin=(debet-1), xlab = xlab, ylab = ylab)
427 # PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='crl', deb=debet, fin=fin, xlab = xlab, ylab = ylab)
428 # PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", col=TRUE, what='crl', xlab = xlab, ylab = ylab)
429 # """ % (DictChdTxtOut['AFC2DCoul'], DictChdTxtOut['AFC2DCoulSup'], DictChdTxtOut['AFC2DCoulEt'], DictChdTxtOut['AFC2DCoulCl'])
438 save.image(file="%s")
439 """ % ffr(DictChdTxtOut['RData'])
440 file = open(DictChdTxtOut['RTxtProfGraph'], 'w')
445 def write_afc_graph(self):
446 if self.param['over'] : over = 'TRUE'
447 else : over = 'FALSE'
449 if self.param['do_select_nb'] : do_select_nb = 'TRUE'
450 else : do_select_nb = 'FALSE'
452 if self.param['do_select_chi'] : do_select_chi = 'TRUE'
453 else : do_select_chi = 'FALSE'
455 if self.param['do_select_chi_classe'] : do_select_chi_classe = 'TRUE'
456 else : do_select_chi_classe = 'FALSE'
458 if self.param['cex_txt'] : cex_txt = 'TRUE'
459 else : cex_txt = 'FALSE'
461 if self.param['tchi'] : tchi = 'TRUE'
462 else : tchi = 'FALSE'
464 if self.param['svg'] : svg = 'TRUE'
467 with open(self.RscriptsPath['afc_graph'], 'r') as f:
470 # self.DictPathOut['RData'], \
471 scripts = txt % (ffr(self.RscriptsPath['Rgraph']),\
472 self.param['typegraph'], \
473 self.param['what'], \
474 self.param['facteur'][0],\
475 self.param['facteur'][1], \
476 self.param['facteur'][2], \
478 over, do_select_nb, \
479 self.param['select_nb'], \
481 self.param['select_chi'], \
482 do_select_chi_classe, \
483 self.param['nbchic'], \
485 self.param['txt_min'], \
486 self.param['txt_max'], \
488 self.param['width'], \
489 self.param['height'],\
490 self.param['taillecar'], \
491 self.param['alpha'], \
492 self.param['film'], \
494 self.param['tchi_min'],\
495 self.param['tchi_max'],\
496 ffr(os.path.dirname(self.fileout)),\
500 def print_simi3d(self):
501 simi3d = self.parent.simi3dpanel
502 txt = '#Fichier genere par Iramuteq'
503 if simi3d.movie.GetValue() :
504 movie = "'" + ffr(os.path.dirname(self.DictPathOut['RData'])) + "'"
508 #if self.corpus.parametres['type'] == 'corpus' :
514 dm<-read.csv2("%s",row.names=1,header = %s)
516 """ % (self.DictPathOut['Contout'], header, self.DictPathOut['RData'])
520 """ % self.parent.RscriptsPath['Rgraph']
524 make.simi.afc(dm,chistabletot, lim=%i, alpha = %.2f, movie = %s)
525 """ % (simi3d.spin_1.GetValue(), float(simi3d.slider_1.GetValue())/100, movie)
526 tmpfile = tempfile.mktemp(dir=self.parent.TEMPDIR)
527 tmp = open(tmpfile,'w')
532 def dendroandbarplot(table, rownames, colnames, rgraph, tmpgraph, intxt = False, dendro=False) :
534 txttable = 'c(' + ','.join([','.join(line) for line in table]) + ')'
535 rownb = len(rownames)
536 rownames = 'c("' + '","'.join(rownames) + '")'
537 colnames = 'c("' + '","'.join(colnames) + '")'
541 di <- matrix(data=%s, nrow=%i, byrow = TRUE)
544 """ % (txttable, rownb, rownames, colnames)
551 height <- (30*ncol(di)) + (15*nrow(di))
552 height <- ifelse(height <= 400, 400, height)
554 open_file_graph("%s", width=width, height=height)
555 plot.dendro.lex(tree.cut1$tree.cl, di)
556 """ % (ffr(dendro),ffr(rgraph), ffr(tmpgraph))
559 def barplot(table, parametres, intxt = False) :
561 txttable = 'c(' + ','.join([','.join(line) for line in table]) + ')'
562 #width = 100 + (15 * len(rownames)) + (100 * len(colnames))
563 #height = len(rownames) * 15
564 rownb = len(parametres['rownames'])
567 rownames = 'c("' + '","'.join(parametres['rownames']) + '")'
568 colnames = 'c("' + '","'.join(parametres['colnames']) + '")'
573 di <- matrix(data=%s, nrow=%i, byrow = TRUE)
574 toinf <- which(di == Inf)
575 tominf <- which(di == -Inf)
578 valmax <- max(di, na.rm = TRUE)
586 if (length(tominf)) {
588 valmin <- min(di, na.rm = TRUE)
598 """ % (txttable, rownb, rownames, colnames)
601 if not 'tree' in parametres :
604 color = rainbow(nrow(di))
607 open_file_graph("%s",width = width, height = height, svg = %s)
609 layout(matrix(c(1,2),1,2, byrow=TRUE),widths=c(3,lcm(7)))
611 yp = ifelse(length(toinf), 0.2, 0)
612 ym = ifelse(length(tominf), 0.2, 0)
613 ymin <- ifelse(!length(which(di < 0)), 0, min(di) - ym)
614 coord <- barplot(as.matrix(di), beside = TRUE, col = color, space = c(0.1,0.6), ylim=c(ymin, max(di) + yp), las = 2)
616 coordinf <- coord[toinf]
618 text(x=coordinf, y=valinf + 0.1, 'i')
620 if (length(tominf)) {
621 coordinf <- coord[toinf]
623 text(x=coordinf, y=valinf - 0.1, 'i')
629 lcoord <- apply(cc, 1, mean)
632 amp <- abs(max(di) - min(di))
639 d <- signif(amp%%/%%10,1)
644 if ((i/d) == (i%%/%%d)) {
649 plot(0, axes = FALSE, pch = '')
650 legend(x = 'center' , rownames(di), fill = color)
652 """ % (ffr(parametres['rgraph']), parametres['width'], parametres['height'], ffr(parametres['tmpgraph']), parametres['svg'])
660 open_file_graph("%s", width=width, height=height, svg = %s)
661 plot.dendro.lex(tree.cut1$tree.cl, di)
662 """ % (ffr(parametres['tree']), ffr(parametres['rgraph']), parametres['width'], parametres['height'], ffr(parametres['tmpgraph']), parametres['svg'])
665 #def RAfcUci(DictAfcUciOut, nd=2, RscriptsPath='', PARCEX='0.8'):
671 # dataact<-read.csv2("%s")
672 # """ % (DictAfcUciOut['TableCont'])#, encoding)
674 # datasup<-read.csv2("%s")
675 # """ % (DictAfcUciOut['TableSup'])#, encoding)
677 # dataet<-read.csv2("%s")
678 # """ % (DictAfcUciOut['TableEt'])#, encoding)
680 # datatotsup<-cbind(dataact,datasup)
681 # datatotet<-cbind(dataact,dataet)
682 # afcact<-ca(dataact,nd=nd)
683 # afcsup<-ca(datatotsup,supcol=((ncol(dataact)+1):ncol(datatotsup)),nd=nd)
684 # afcet<-ca(datatotet,supcol=((ncol(dataact)+1):ncol(datatotet)),nd=nd)
685 # afctot<-afcsup$colcoord
686 # rownames(afctot)<-afcsup$colnames
687 # colnames(afctot)<-paste('coord. facteur',1:nd,sep=' ')
688 # afctot<-cbind(afctot,mass=afcsup$colmass)
689 # afctot<-cbind(afctot,distance=afcsup$coldist)
690 # afctot<-cbind(afctot,intertie=afcsup$colinertia)
691 # rcolet<-afcet$colsup
692 # afctmp<-afcet$colcoord[rcolet,]
693 # rownames(afctmp)<-afcet$colnames[rcolet]
694 # afctmp<-cbind(afctmp,afcet$colmass[rcolet])
695 # afctmp<-cbind(afctmp,afcet$coldist[rcolet])
696 # afctmp<-cbind(afctmp,afcet$colinertia[rcolet])
697 # afctot<-rbind(afctot,afctmp)
698 # write.csv2(afctot,file = "%s")
700 # """ % (DictAfcUciOut['afc_row'], RscriptsPath['Rgraph'])
706 # PlotAfc(afcet,filename="%s",toplot=c%s, PARCEX=PARCEX)
707 # """ % (DictAfcUciOut['AfcColAct'], "('none','active')")
709 # PlotAfc(afcsup,filename="%s",toplot=c%s, PARCEX=PARCEX)
710 # """ % (DictAfcUciOut['AfcColSup'], "('none','passive')")
711 # txt += """PlotAfc(afcet,filename="%s", toplot=c%s, PARCEX=PARCEX)
712 # """ % (DictAfcUciOut['AfcColEt'], "('none','passive')")
714 # PlotAfc(afcet,filename="%s", toplot=c%s, PARCEX=PARCEX)
715 # """ % (DictAfcUciOut['AfcRow'], "('all','none')")
716 # f = open(DictAfcUciOut['Rafcuci'], 'w')
720 class PrintSimiScript(PrintRScript) :
721 def make_script(self) :
723 self.packages(['igraph', 'proxy', 'Matrix'])
724 self.sources([self.analyse.parent.RscriptsPath['simi'], self.analyse.parent.RscriptsPath['Rgraph']])
726 if not self.parametres['keep_coord'] and not (self.parametres['type'] == 'simimatrix' or self.parametres['type'] == 'simiclustermatrix') :
731 """ % (ffr(self.pathout['mat01.csv']), ffr(self.pathout['actives.csv']), ffr(self.pathout['selected.csv']))
732 if 'word' in self.parametres :
736 """ % self.parametres['word']
744 cn <- read.table(cn.path, sep='\t', quote='"')
745 colnames(dm) <- cn[,1]
746 if (file.exists(selected.col)) {
747 sel.col <- read.csv2(selected.col, header = FALSE)
748 sel.col <- sel.col[,1] + 1
750 sel.col <- 1:ncol(dm)
755 forme <- colnames(dm)[index]
756 if (!index %in% sel.col) {
757 sel.col <- append(sel.col, index)
760 index <- which(colnames(dm) == forme)
763 elif not self.parametres['keep_coord'] and (self.parametres['type'] == 'simimatrix' or self.parametres['type'] == 'simiclustermatrix'):
767 """ % (ffr(self.pathout['mat01.csv']), ffr(self.pathout['selected.csv']))
768 if 'word' in self.parametres :
772 """ % self.parametres['word']
778 dm <-read.csv2(dm.path)
780 if (file.exists(selected.col)) {
781 sel.col <- read.csv2(selected.col, header = FALSE)
782 sel.col <- sel.col[,1] + 1
784 sel.col <- 1:ncol(dm)
789 forme <- colnames(dm)[index]
790 if (!index %in% sel.col) {
791 sel.col <- append(sel.col, index)
794 index <- which(colnames(dm) == forme)
800 """ % ffr(self.pathout['RData.RData'])
802 if self.parametres['coeff'] == 0 :
804 if not self.parametres['keep_coord'] :
810 if not self.parametres['keep_coord'] :
814 if self.parametres['coeff'] == 1 :
818 mat <- simil(dm, method = 'Russel', diag = TRUE, upper = TRUE, by_rows = FALSE)
820 elif self.analyse.indices[self.parametres['coeff']] == 'binomial' :
822 if not self.parametres['keep_coord'] :
827 elif self.parametres['coeff'] != 0 :
828 method = self.analyse.indices[self.parametres['coeff']]
829 if not self.parametres['keep_coord'] :
832 mat <- simil(dm, method = method, diag = TRUE, upper = TRUE, by_rows = FALSE)
833 """ % self.analyse.indices[self.parametres['coeff']]
834 if not self.parametres['keep_coord'] :
836 mat <- as.matrix(stats::as.dist(mat,diag=TRUE,upper=TRUE))
838 if (length(which(mat == Inf))) {
839 infp <- which(mat == Inf)
841 maxmat <- max(mat, na.rm = TRUE)
849 if (length(which(mat == -Inf))) {
850 infm <- which(mat == -Inf)
852 minmat <- min(mat, na.rm = TRUE)
861 if 'word' in self.parametres and not self.parametres['keep_coord'] :
863 mat <- graph.word(mat, index)
865 if (length(which(cs==0))) mat <- mat[,-which(cs==0)]
867 if (length(which(rs==0))) mat <- mat[-which(rs==0),]
868 if (length(which(cs==0))) dm <- dm[,-which(cs==0)]
870 index <- which(colnames(mat)==forme)
874 if self.parametres['layout'] == 0 : layout = 'random'
875 if self.parametres['layout'] == 1 : layout = 'circle'
876 if self.parametres['layout'] == 2 : layout = 'frutch'
877 if self.parametres['layout'] == 3 : layout = 'kawa'
878 if self.parametres['layout'] == 4 : layout = 'graphopt'
879 if self.parametres['layout'] == 5 : layout = 'spirale'
880 if self.parametres['layout'] == 6 : layout = 'spirale3D'
884 if self.parametres['type_graph'] == 0 : type = 'tkplot'
885 if self.parametres['type_graph'] == 1 :
888 dirout = os.path.dirname(self.pathout['mat01.csv'])
889 while os.path.exists(os.path.join(dirout,'graph_simi_'+str(graphnb)+'.png')):
891 self.filename = ffr(os.path.join(dirout,'graph_simi_'+str(graphnb)+'.png'))
892 if self.parametres['type_graph'] == 2 : type = 'rgl'
893 if self.parametres['type_graph'] == 3 :
896 dirout = os.path.dirname(self.pathout['mat01.csv'])
897 while os.path.exists(os.path.join(dirout,'web_'+str(graphnb))):
899 self.filename = ffr(os.path.join(dirout,'web_'+str(graphnb)))
900 os.mkdir(self.filename)
901 self.filename = os.path.join(self.filename, 'gexf.gexf')
902 if self.parametres['type_graph'] == 4 :
905 dirout = os.path.dirname(self.pathout['mat01.csv'])
906 while os.path.exists(os.path.join(dirout,'webrgl_'+str(graphnb))):
908 self.filename = ffr(os.path.join(dirout,'webrgl_'+str(graphnb)))
909 os.mkdir(self.filename)
911 if self.parametres['arbremax'] :
913 self.txtgraph += ' - arbre maximum'
914 else : arbremax = 'FALSE'
916 if self.parametres['coeff_tv'] :
917 coeff_tv = self.parametres['coeff_tv_nb']
918 tvminmax = 'c(NULL,NULL)'
919 elif not self.parametres['coeff_tv'] or self.parametres.get('sformchi', False) :
921 tvminmax = 'c(%i, %i)' %(self.parametres['tvmin'], self.parametres['tvmax'])
922 if self.parametres['coeff_te'] : coeff_te = 'c(%i,%i)' % (self.parametres['coeff_temin'], self.parametres['coeff_temax'])
923 else : coeff_te = 'NULL'
925 if self.parametres['vcex'] or self.parametres.get('cexfromchi', False) :
926 vcexminmax = 'c(%i/10,%i/10)' % (self.parametres['vcexmin'],self.parametres['vcexmax'])
928 vcexminmax = 'c(NULL,NULL)'
929 if not self.parametres['label_v'] : label_v = 'FALSE'
930 else : label_v = 'TRUE'
932 if not self.parametres['label_e'] : label_e = 'FALSE'
933 else : label_e = 'TRUE'
935 if self.parametres['seuil_ok'] : seuil = str(self.parametres['seuil'])
936 else : seuil = 'NULL'
938 if not self.parametres.get('edgecurved', False) :
947 cols = str(self.parametres['cols']).replace(')',', max=255)')
948 cola = str(self.parametres['cola']).replace(')',',max=255)')
958 """ % self.parametres['cex']
960 if self.parametres['film'] :
963 """ % ffr(self.pathout['film'])
970 if (!is.null(seuil)) {
971 if (method!='cooc') {
980 """ % (label_v, label_e)
988 """ % (self.parametres['width'], self.parametres['height'])
989 if self.parametres['keep_coord'] :
991 coords <- try(coords, TRUE)
992 if (!is.matrix(coords)) {
1002 """ % self.parametres['alpha']
1005 """ % self.parametres['alpha']
1006 #############################################
1007 if self.parametres.get('bystar',False) :
1011 for i, line in enumerate(self.parametres['listet']) :
1014 """ % (i+1, ','.join([`val + 1` for val in line]))
1017 """ % ("','".join([val for val in self.parametres['selectedstars']]))
1021 for (i in 1:length(unetoile)) {
1024 if (length(tosum) > 1) {
1025 fsum <- cbind(fsum, colSums(dm[tosum,]))
1027 fsum <- cbind(fsum, dm[tosum,])
1031 lex <- AsLexico2(fsum, chip=TRUE)
1032 dcol <- apply(lex[[4]],1,which.max)
1033 toblack <- apply(lex[[4]],1,max)
1034 gcol <- rainbow(length(unetoile))
1035 #gcol[2] <- 'orange'
1036 vertex.label.color <- gcol[dcol]
1037 vertex.label.color[which(toblack <= 3.84)] <- 'black'
1038 leg <- list(unetoile=unetoile, gcol=gcol)
1039 cols <- vertex.label.color
1040 chivertex.size <- norm.vec(toblack, vcexminmax[1], vcexminmax[2])
1042 """ % (ffr(self.analyse.parent.RscriptsPath['chdfunct']))
1045 vertex.label.color <- 'black'
1049 #############################################
1052 # eff <- colSums(dm)
1053 # g.ori <- graph.adjacency(mat, mode='lower', weighted = TRUE)
1054 # w.ori <- E(g.ori)$weight
1056 # if (method == 'cooc') {
1057 # E(g.ori)$weight <- 1 / w.ori
1059 # E(g.ori)$weigth <- 1 - w.ori
1061 # g.max <- minimum.spanning.tree(g.ori)
1062 # if (method == 'cooc') {
1063 # E(g.max)$weight <- 1 / E(g.max)$weight
1065 # E(g.max)$weight <- 1 - E(g.max)$weight
1072 if self.parametres['com'] :
1073 com = `self.parametres['communities']`
1076 if self.parametres['halo'] :
1086 x <- list(mat = mat, eff = eff)
1087 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, communities = communities, halo = halo, index.word=index)
1088 """ % (method, type, layout, arbremax, coeff_tv, coeff_te)
1090 if self.parametres.get('bystar',False) :
1091 if self.parametres.get('cexfromchi', False) :
1093 label.cex<-chivertex.size
1099 if self.parametres.get('sfromchi', False) :
1101 vertex.size <- norm.vec(toblack, minmaxeff[1], minmaxeff[2])
1108 #print self.parametres
1109 if (self.parametres['type'] == 'clustersimitxt' and self.parametres.get('tmpchi', False)) or (self.parametres['type'] in ['simimatrix','simiclustermatrix'] and 'tmpchi' in self.parametres):
1111 lchi <- read.table("%s")
1113 """ % ffr(self.parametres['tmpchi'])
1115 lchi <- lchi[sel.col]
1117 if self.parametres['type'] in ['clustersimitxt', 'simimatrix', 'simiclustermatrix'] and self.parametres.get('cexfromchi', False) :
1119 label.cex <- norm.vec(lchi, vcexminmax[1], vcexminmax[2])
1123 if (is.null(vcexminmax[1])) {
1126 label.cex <- graph.simi$label.cex
1129 if (self.parametres['type'] in ['clustersimitxt', 'simimatrix', 'simiclustermatrix']) and self.parametres.get('sfromchi', False):
1131 vertex.size <- norm.vec(lchi, minmaxeff[1], minmaxeff[2])
1132 if (!length(vertex.size)) vertex.size <- 0
1136 if (is.null(minmaxeff[1])) {
1139 vertex.size <- graph.simi$eff
1142 #txt += """ vertex.size <- NULL """
1143 if self.parametres['svg'] : svg = 'TRUE'
1144 else : svg = 'FALSE'
1150 if (!is.null(graph.simi$com)) {
1151 com <- graph.simi$com
1152 colm <- rainbow(length(com))
1153 if (vertex.size != 0 || graph.simi$halo) {
1154 vertex.label.color <- 'black'
1155 vertex.col <- colm[membership(com)]
1157 vertex.label.color <- colm[membership(com)]
1160 coords <- plot.simi(graph.simi, p.type='%s',filename="%s", vertex.label = label.v, edge.label = label.e, vertex.col = vertex.col, 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, edge.curved = edge.curved, svg = svg)
1161 save.image(file="%s")
1162 """ % (type, self.filename, ffr(self.pathout['RData']))
1167 class WordCloudRScript(PrintRScript) :
1168 def make_script(self) :
1169 self.sources([self.analyse.parent.RscriptsPath['Rgraph']])
1170 self.packages(['wordcloud'])
1171 bg_col = Rcolor(self.parametres['col_bg'])
1172 txt_col = Rcolor(self.parametres['col_text'])
1173 if self.parametres['svg'] :
1181 act <- read.csv2("%s", header = FALSE, row.names=1, sep='\t')
1182 selected.col <- read.table("%s")
1183 toprint <- as.matrix(act[selected.col[,1] + 1,])
1184 rownames(toprint) <- rownames(act)[selected.col[,1] + 1]
1186 if (nrow(toprint) > maxword) {
1187 toprint <- as.matrix(toprint[order(toprint[,1], decreasing=TRUE),])
1188 toprint <- as.matrix(toprint[1:maxword,])
1190 open_file_graph("%s", width = %i, height = %i , svg = svg)
1192 wordcloud(row.names(toprint), toprint[,1], scale=c(%f,%f), random.order=FALSE, colors=rgb%s)
1194 """ % (ffr(self.analyse.pathout['actives_eff.csv']), ffr(self.analyse.pathout['selected.csv']), self.parametres['maxword'], ffr(self.parametres['graphout']), self.parametres['width'], self.parametres['height'], bg_col, self.parametres['maxcex'], self.parametres['mincex'], txt_col)
1198 class ProtoScript(PrintRScript) :
1199 def make_script(self) :
1200 self.sources([self.analyse.parent.RscriptsPath['Rgraph'], self.analyse.parent.RscriptsPath['prototypical.R']])
1201 self.packages(['wordcloud'])
1202 if self.parametres.get('cloud', False) :
1207 errorn <- function(x) {
1208 qnorm(0.975)*sd(x)/sqrt(lenght(n))
1210 errort <- function(x) {
1211 qt(0.975,df=lenght(x)-1)*sd(x)/sqrt(lenght(x))
1213 mat <- read.csv2("%s", header = FALSE, row.names=1, sep='\t', quote='"', dec='.')
1214 open_file_graph("%s",height=800, width=1000)
1215 prototypical(mat, mfreq = %s, mrank = %s, cloud = FALSE, cexrange=c(1,2.4), cexalpha= c(0.4, 1), type = '%s')
1217 """ % (ffr(self.analyse.pathout['table.csv']), ffr(self.analyse.pathout['proto.png']), self.parametres['limfreq'], self.parametres['limrang'], self.parametres['typegraph'])
1222 class ExportAfc(PrintRScript) :
1223 def make_script(self) :
1224 self.source([self.analyse.parent.RscriptsPath['Rgraph']])
1225 self.packages(['rgexf'])
1229 class MergeGraphes(PrintRScript) :
1230 def __init__(self, analyse):
1231 self.script = u"#Script genere par IRaMuTeQ - %s\n" % datetime.now().ctime()
1232 self.pathout = PathOut()
1233 self.parametres = analyse.parametres
1234 self.scriptout = self.pathout['temp']
1235 self.analyse = analyse
1237 def make_script(self) :
1247 g <- graph.simi$graph
1248 V(g)$weight <- (graph.simi$mat.eff/nrow(dm))*100
1251 for i, graph in enumerate(self.parametres['graphs']) :
1252 path = os.path.dirname(graph)
1253 gname = ''.join(['g', `i`])
1254 RData = os.path.join(path,'RData.RData')
1255 txt += load % (ffr(RData), gname)
1257 self.sources([self.analyse.parent.RscriptsPath['simi']])
1259 ng <- merge.graph(graphs)
1260 ngraph <- list(graph=ng, layout=layout.fruchterman.reingold(ng, dim=3), labex.cex=V(ng)$weight)
1261 write.graph(ng, "%s", format = 'graphml')
1262 """ % ffr(self.parametres['grapheout'])
1265 class TgenSpecScript(PrintRScript):
1266 def make_script(self):
1267 self.packages(['textometry'])
1269 tgen <- read.csv2("%s", row.names = 1, sep = '\\t')
1270 """ % ffr(self.parametres['tgeneff'])
1272 tot <- tgen[nrow(tgen), ]
1274 tgen <- tgen[-nrow(tgen),]
1275 for (i in 1:nrow(tgen)) {
1276 mat <- rbind(tgen[i,], tot - tgen[i,])
1277 specmat <- specificities(mat)
1278 result <- rbind(result, specmat[1,])
1280 colnames(result) <- colnames(tgen)
1281 row.names(result) <- rownames(tgen)
1282 write.table(result, file = "%s", sep='\\t', col.names = NA)
1283 """ % ffr(self.pathout['tgenspec.csv'])
1286 class TgenProfScript(PrintRScript):
1287 def make_script(self):
1288 self.sources([self.analyse.ira.RscriptsPath['chdfunct']])
1290 tgen <- read.csv2("%s", row.names = 1, sep = '\\t')
1291 """ % ffr(self.parametres['tgeneff'])
1293 tgenlem <- read.csv2("%s", row.names = 1, sep = '\\t')
1294 """ % ffr(self.parametres['tgenlemeff'])
1296 res <- build.prof.tgen(tgen)
1297 write.table(res$chi2, file = "%s", sep='\\t', col.names = NA)
1298 write.table(res$pchi2, file = "%s", sep='\\t', col.names = NA)
1299 """ % (ffr(self.pathout['tgenchi2.csv']), ffr(self.pathout['tgenpchi2.csv']))
1301 reslem <- build.prof.tgen(tgenlem)
1302 write.table(reslem$chi2, file = "%s", sep='\\t', col.names = NA)
1303 write.table(reslem$pchi2, file = "%s", sep='\\t', col.names = NA)
1304 """ % (ffr(self.pathout['tgenlemchi2.csv']), ffr(self.pathout['tgenlempchi2.csv']))
1307 class FreqMultiScript(PrintRScript):
1308 def make_script(self):
1309 self.sources([self.analyse.parent.RscriptsPath['Rgraph']])
1311 freq <- read.csv2("%s", row.names=1, sep='\\t', dec='.')
1312 """ % ffr(self.pathout['frequences.csv'])
1314 toplot <- freq[order(freq[,2]) ,2]
1315 toplot.names = rownames(freq)[order(freq[,2])]
1316 h <- 80 + (20 * nrow(freq))
1317 open_file_graph("%s",height=h, width=500)
1318 par(mar=c(3,20,3,3))
1319 barplot(toplot, names = toplot.names, horiz=TRUE, las =1, col = rainbow(nrow(freq)))
1321 """ % ffr(self.pathout['barplotfreq.png'])
1323 toplot <- freq[order(freq[,4]) ,4]
1324 toplot.names = rownames(freq)[order(freq[,4])]
1325 open_file_graph("%s",height=h, width=500)
1326 par(mar=c(3,20,3,3))
1327 barplot(toplot, names = toplot.names, horiz=TRUE, las =1, col = rainbow(nrow(freq)))
1329 """ % ffr(self.pathout['barplotrow.png'])
1333 class LabbeScript(PrintRScript) :
1334 def make_script(self) :
1335 self.sources([self.analyse.parent.RscriptsPath['distance-labbe.R'],
1336 self.analyse.parent.RscriptsPath['Rgraph']])
1338 tab <- read.csv2("%s", header=TRUE, sep=';', row.names=1)
1339 """ % (ffr(self.pathout['tableafcm.csv']))
1341 dist.mat <- dist.labbe(tab)
1342 dist.mat <- as.dist(dist.mat, upper=F, diag=F)
1343 write.table(as.matrix(dist.mat), "%s", sep='\t')
1346 chd <- hclust(dist.mat, method="ward.D2")
1347 open_file_graph("%s", width=1000, height=1000, svg=F)
1349 plot.phylo(as.phylo(chd), type='unrooted', lab4ut="axial")
1351 """ % (ffr(self.pathout['distmat.csv']), ffr(self.pathout['labbe-tree.png']))
1353 open_file_graph("%s", width=1000, height=1000, svg=F)
1354 par(mar=c(10,1,1,10))
1355 heatmap(as.matrix(dist.mat), symm = T, distfun=function(x) as.dist(x), margins=c(10,10))
1357 """ % ffr(self.pathout['labbe-heatmap.png'])
1359 #http://stackoverflow.com/questions/3081066/what-techniques-exists-in-r-to-visualize-a-distance-matrix
1360 dst <- data.matrix(dist.mat)
1362 rn <- row.names(as.matrix(dist.mat))
1363 open_file_graph("%s", width=1500, height=1000, svg=F)
1364 par(mar=c(10,10,3,3))
1365 image(1:dim, 1:dim, dst, axes = FALSE, xlab="", ylab="")
1366 axis(1, 1:dim, rn, cex.axis = 0.9, las=3)
1367 axis(2, 1:dim, rn, cex.axis = 0.9, las=1)
1368 text(expand.grid(1:dim, 1:dim), sprintf("%%0.2f", dst), cex=0.6)
1370 """ % ffr(self.pathout['labbe-matrix.png'])
1374 class ChronoChi2Script(PrintRScript) :
1375 def make_script(self) :
1376 self.sources([self.analyse.parent.RscriptsPath['Rgraph']])
1377 print self.parametres
1383 """ % (ffr(self.pathout['RData.RData']), ffr(self.pathout['dendrogramme.RData']))
1386 """ % self.parametres['svg']
1388 tc <- which(grepl("%s",rownames(chistabletot)))
1389 rn <- rownames(chistabletot)[tc]
1391 dpt <- chistabletot[tc,]
1392 tot <- afctable[tc,]
1397 """ % self.parametres['var'].replace(u'*', u"\\\\*")
1399 classes <- n1[,ncol(n1)]
1400 tcl <- table(classes)
1401 if ('0' %in% names(tcl)) {
1402 to.vire <- which(names(tcl) == '0')
1403 tcl <- tcl[-to.vire]
1405 tclp <- tcl/sum(tcl)
1413 lcol <- c(lcol, qchisq(1-k,1))
1417 lcol <- c(3.84, lcol)
1418 lcol <- c(-Inf,lcol)
1419 lcol <- c(lcol, Inf)
1422 alphas <- seq(0,1, length.out=length(breaks))
1423 clod <- rev(as.numeric(tree.cut1$tree.cl$tip.label))
1427 open_file_graph("%s", w=%i, h=%i, svg=svg)
1428 """ % (ffr(self.parametres['tmpgraph']), self.parametres['width'], self.parametres['height'])
1431 mat.graphic <- matrix(c(rep(1,nrow(dd)),c(2:(nrow(dd)+1))), ncol=2)
1432 mat.graphic <- rbind(mat.graphic, c(max(mat.graphic) + 1 , max(mat.graphic) + 2))
1433 hauteur <- tclp[clod] * 0.9
1434 heights.graphic <- append(hauteur, 0.1)
1435 layout(mat.graphic, heights=heights.graphic, widths=c(0.15,0.85))
1437 tree.toplot <- tree.cut1$tree.cl
1438 num.label <- as.numeric(tree.cut1$tree.cl$tip.label)
1439 col.tree <- rainbow(length(num.label))[num.label]
1440 #tree.toplot$tip.label <- paste('classe ', tree.toplot$tip.label)
1441 plot.phylo(tree.toplot,label.offset=0.1, cex=1.1, no.margin=T, tip.color = col.tree)
1445 lcol <- cut(dd[i,], breaks, include.lowest=TRUE)
1446 ulcol <- names(table(lcol))
1447 lcol <- as.character(lcol)
1448 for (j in 1:length(ulcol)) {
1449 lcol[which(lcol==ulcol[j])] <- j
1451 lcol <- as.numeric(lcol)
1452 mcol <- rainbow(nrow(dd))[i]
1455 last.col <- c(last.col, rgb(r=col2rgb(mcol)[1]/255, g=col2rgb(mcol)[2]/255, b=col2rgb(mcol)[3]/255, a=k))
1459 barplot(rep(1,ncol(dd)), width=ptc, names.arg=FALSE, axes=FALSE, col=last.col[lcol], border=rgb(r=0, g=0, b=0, a=0.3))
1461 plot(0,type='n',axes=FALSE,ann=FALSE)
1462 label.coords <- barplot(rep(1, ncol(dd)), width=ptc, names.arg = F, las=2, axes=F, ylim=c(0,1), plot=T, col='white')
1463 text(x=label.coords, y=0.5, labels=rn[order(rn)], srt=90)
1469 class ChronoPropScript(PrintRScript) :
1470 def make_script(self) :
1471 self.sources([self.analyse.parent.RscriptsPath['Rgraph']])
1472 print self.parametres
1478 """ % (ffr(self.pathout['RData.RData']), ffr(self.pathout['dendrogramme.RData']))
1481 """ % self.parametres['svg']
1483 tc <- which(grepl("%s",rownames(chistabletot)))
1484 rn <- rownames(chistabletot)[tc]
1486 dpt <- chistabletot[tc,]
1487 tot <- afctable[tc,]
1492 """ % self.parametres['var'].replace(u'*', u"\\\\*")
1494 classes <- n1[,ncol(n1)]
1495 tcl <- table(classes)
1496 if ('0' %in% names(tcl)) {
1497 to.vire <- which(names(tcl) == '0')
1498 tcl <- tcl[-to.vire]
1500 tclp <- tcl/sum(tcl)
1503 open_file_graph("%s", w=%i, h=%i, svg=svg)
1504 """ % (ffr(self.parametres['tmpgraph']), self.parametres['width'], self.parametres['height'])
1506 ptt <- prop.table(as.matrix(tot), 1)
1507 par(mar=c(10,2,2,2))
1508 barplot(t(ptt)[as.numeric(tree.cut1$tree.cl$tip.label),], col=rainbow(ncol(ptt))[as.numeric(tree.cut1$tree.cl$tip.label)], width=ptc, las=3, space=0.05, cex.axis=0.7, border=NA)
1514 class ReDoProfScript(PrintRScript) :
1515 def make_script(self) :
1516 self.sources([self.analyse.parent.RscriptsPath['chdfunct.R']])
1517 print self.parametres