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 chd1<-CHD(data1, x = nbt, mode.patate = mode.patate, svd.method =
168 svd.method, libsvdc.path = libsvdc.path, log.file = log1)
169 """ % ffr(DicoPath['log-chd1.txt'])
171 if classif_mode == 0:
174 chd2<-CHD(data2, x = nbt, mode.patate = mode.patate, svd.method =
175 svd.method, libsvdc.path = libsvdc.path) log.file = log2)
176 """ % ffr(DicoPath['log-chd2.txt'])
180 listuce1<-read.csv2("%s")
181 """ % ffr(DicoPath['listeuce1'])
183 if classif_mode == 0:
185 listuce2<-read.csv2("%s")
186 """ % ffr(DicoPath['listeuce2'])
192 if classif_mode == 0:
200 if (classif_mode == 0) {
201 chd.result <- Rchdtxt(uceout, chd1, chd2 = chd2, mincl = mincl,classif_mode = classif_mode, nbt = nbt)
203 chd.result <- Rchdtxt(uceout, chd1, chd2 = chd1, mincl = mincl,classif_mode = classif_mode, nbt = nbt)
206 classeuce1 <- chd.result$cuce1
207 classes<-n1[,ncol(n1)]
208 write.csv2(n1, file="%s")
210 """ % (classif_mode, mincl, ffr(DicoPath['uce']), ffr(DicoPath['n1.csv']))
213 tree.tot1 <- make_tree_tot(chd1)
214 # open_file_graph("%s", widt = 600, height=400)
215 # plot(tree.tot1$tree.cl)
217 """ % ffr(DicoPath['arbre1'])
219 if classif_mode == 0:
221 classeuce2 <- chd.result$cuce2
222 tree.tot2 <- make_tree_tot(chd2)
223 # open_file_graph("%s", width = 600, height=400)
224 # plot(tree.tot2$tree.cl)
226 """ % ffr(DicoPath['arbre2'] )
229 tree.cut1 <- make_dendro_cut_tuple(tree.tot1$dendro_tuple, chd.result$coord_ok, classeuce1, 1, nbt)
230 save(tree.cut1, file="%s")
232 open_file_graph("%s", width = 600, height=400)
233 plot.dendropr(tree.cut1$tree.cl,classes, histo=TRUE)
234 open_file_graph("%s", width = 600, height=400)
235 plot(tree.cut1$dendro_tot_cl)
237 """ % (ffr(DicoPath['Rdendro']), ffr(DicoPath['dendro1']), ffr(DicoPath['arbre1']))
239 if classif_mode == 0:
241 tree.cut2 <- make_dendro_cut_tuple(tree.tot2$dendro_tuple, chd.result$coord_ok, classeuce2, 2, nbt)
242 open_file_graph("%s", width = 600, height=400)
243 plot(tree.cut2$tree.cl)
245 open_file_graph("%s", width = 600, height=400)
246 plot(tree.cut2$dendro_tot_cl)
248 """ % (ffr(DicoPath['dendro2']), ffr(DicoPath['arbre2']))
252 #save.image(file="%s")
253 """ % (ffr(DicoPath['RData']))
255 fileout = open(DicoPath['Rchdtxt'], 'w')
259 def RPamTxt(corpus, RscriptPath):
260 DicoPath = corpus.pathout
261 param = corpus.parametres
264 """ % (RscriptPath['pamtxt'])
267 """ % (RscriptPath['Rgraph'])
269 result <- pamtxt("%s", "%s", "%s", method = "%s", clust_type = "%s", clnb = %i)
271 """ % (DicoPath['TableUc1'], DicoPath['listeuce1'], DicoPath['uce'], param['method'], param['cluster_type'], param['nbcl'] )
273 open_file_graph("%s", width=400, height=400)
276 """ % (DicoPath['arbre1'])
278 save.image(file="%s")
279 """ % DicoPath['RData']
280 fileout = open(DicoPath['Rchdtxt'], 'w')
285 def RchdQuest(DicoPath, RscriptPath, nbcl = 10, mincl = 10):
291 """ % (ffr(RscriptPath['CHD']), ffr(RscriptPath['chdquest']), ffr(RscriptPath['anacor']),ffr(RscriptPath['Rgraph']))
299 chd.result<-Rchdquest("%s","%s","%s", nbt = nbt, mincl = mincl)
301 classeuce1 <- chd.result$cuce1
302 """ % (ffr(DicoPath['mat01.csv']), ffr(DicoPath['listeuce1']), ffr(DicoPath['uce']))
305 tree_tot1 <- make_tree_tot(chd.result$chd)
306 open_file_graph("%s", width = 600, height=400)
307 plot(tree_tot1$tree.cl)
309 """ % ffr(DicoPath['arbre1'])
312 tree_cut1 <- make_dendro_cut_tuple(tree_tot1$dendro_tuple, chd.result$coord_ok, classeuce1, 1, nbt)
313 tree.cut1 <- tree_cut1
314 save(tree.cut1, file="%s")
315 open_file_graph("%s", width = 600, height=400)
316 classes<-n1[,ncol(n1)]
317 plot.dendropr(tree_cut1$tree.cl,classes, histo = TRUE)
318 """ % (ffr(DicoPath['Rdendro']), ffr(DicoPath['dendro1']))
321 save.image(file="%s")
322 """ % ffr(DicoPath['RData'])
323 fileout = open(DicoPath['Rchdquest'], 'w')
327 def ReinertTxtProf(DictChdTxtOut, RscriptsPath, clnb, taillecar):
328 txt = "clnb<-%i\n" % clnb
332 n1 <- read.csv2("%s")
333 """ % (ffr(RscriptsPath['chdfunct']), ffr(DictChdTxtOut['RData']), ffr(DictChdTxtOut['n1.csv']))
335 dataact<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
336 datasup<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
337 dataet<-read.csv2("%s", header = FALSE, sep = ';',quote = '\"', row.names = 1, na.strings = 'NA')
338 """ % (ffr(DictChdTxtOut['Contout']), ffr(DictChdTxtOut['ContSupOut']), ffr(DictChdTxtOut['ContEtOut']))
340 tablesqrpact<-BuildProf(as.matrix(dataact),n1,clnb)
341 tablesqrpsup<-BuildProf(as.matrix(datasup),n1,clnb)
342 tablesqrpet<-BuildProf(as.matrix(dataet),n1,clnb)
345 PrintProfile(n1,tablesqrpact[4],tablesqrpet[4],tablesqrpact[5],tablesqrpet[5],clnb,"%s","%s",tablesqrpsup[4],tablesqrpsup[5])
346 """ % (ffr(DictChdTxtOut['PROFILE_OUT']), ffr(DictChdTxtOut['ANTIPRO_OUT']))
348 colnames(tablesqrpact[[2]])<-paste('classe',1:clnb,sep=' ')
349 colnames(tablesqrpact[[1]])<-paste('classe',1:clnb,sep=' ')
350 colnames(tablesqrpsup[[2]])<-paste('classe',1:clnb,sep=' ')
351 colnames(tablesqrpsup[[1]])<-paste('classe',1:clnb,sep=' ')
352 colnames(tablesqrpet[[2]])<-paste('classe',1:clnb,sep=' ')
353 colnames(tablesqrpet[[1]])<-paste('classe',1:clnb,sep=' ')
354 chistabletot<-rbind(tablesqrpact[2][[1]],tablesqrpsup[2][[1]])
355 chistabletot<-rbind(chistabletot,tablesqrpet[2][[1]])
356 ptabletot<-rbind(tablesqrpact[1][[1]],tablesqrpet[1][[1]])
359 write.csv2(chistabletot,file="%s")
360 write.csv2(ptabletot,file="%s")
362 write.csv2(gbcluster,file="%s")
363 """ % (ffr(DictChdTxtOut['chisqtable']), ffr(DictChdTxtOut['ptable']), ffr(DictChdTxtOut['SbyClasseOut']))
367 colnames(dataact)<-paste('classe',1:clnb,sep=' ')
368 colnames(datasup)<-paste('classe',1:clnb,sep=' ')
369 colnames(dataet)<-paste('classe',1:clnb,sep=' ')
370 rowtot<-nrow(dataact)+nrow(dataet)+nrow(datasup)
371 afctable<-rbind(as.matrix(dataact),as.matrix(datasup))
372 afctable<-rbind(afctable,as.matrix(dataet))
373 colnames(afctable)<-paste('classe',1:clnb,sep=' ')
374 afc<-ca(afctable,suprow=((nrow(dataact)+1):rowtot),nd=(ncol(afctable)-1))
375 debsup<-nrow(dataact)+1
376 debet<-nrow(dataact)+nrow(datasup)+1
378 afc<-AddCorrelationOk(afc)
380 #FIXME : split this!!!
383 """ % ffr(RscriptsPath['Rgraph'])
386 afc <- summary.ca.dm(afc)
387 afc_table <- create_afc_table(afc)
388 write.csv2(afc_table$facteur, file = "%s")
389 write.csv2(afc_table$colonne, file = "%s")
390 write.csv2(afc_table$ligne, file = "%s")
391 """ % (ffr(DictChdTxtOut['afc_facteur']), ffr(DictChdTxtOut['afc_col']), ffr(DictChdTxtOut['afc_row']))
397 xyminmax <- PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='coord', deb=1, fin=(debsup-1), xlab = xlab, ylab = ylab)
398 """ % (ffr(DictChdTxtOut['AFC2DL_OUT']))
400 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)
401 """ % (ffr(DictChdTxtOut['AFC2DSL_OUT']))
403 if ((fin - debet) > 2) {
404 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)
406 """ % (ffr(DictChdTxtOut['AFC2DEL_OUT']))
408 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)
409 """ % (ffr(DictChdTxtOut['AFC2DCL_OUT']))
411 # PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='crl', deb=1, fin=(debsup-1), xlab = xlab, ylab = ylab)
412 # PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='crl', deb=debsup, fin=(debet-1), xlab = xlab, ylab = ylab)
413 # PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", what='crl', deb=debet, fin=fin, xlab = xlab, ylab = ylab)
414 # PlotAfc2dCoul(afc, as.data.frame(chistabletot), "%s", col=TRUE, what='crl', xlab = xlab, ylab = ylab)
415 # """ % (DictChdTxtOut['AFC2DCoul'], DictChdTxtOut['AFC2DCoulSup'], DictChdTxtOut['AFC2DCoulEt'], DictChdTxtOut['AFC2DCoulCl'])
424 save.image(file="%s")
425 """ % ffr(DictChdTxtOut['RData'])
426 file = open(DictChdTxtOut['RTxtProfGraph'], 'w')
431 def write_afc_graph(self):
432 if self.param['over'] : over = 'TRUE'
433 else : over = 'FALSE'
435 if self.param['do_select_nb'] : do_select_nb = 'TRUE'
436 else : do_select_nb = 'FALSE'
438 if self.param['do_select_chi'] : do_select_chi = 'TRUE'
439 else : do_select_chi = 'FALSE'
441 if self.param['do_select_chi_classe'] : do_select_chi_classe = 'TRUE'
442 else : do_select_chi_classe = 'FALSE'
444 if self.param['cex_txt'] : cex_txt = 'TRUE'
445 else : cex_txt = 'FALSE'
447 if self.param['tchi'] : tchi = 'TRUE'
448 else : tchi = 'FALSE'
450 if self.param['svg'] : svg = 'TRUE'
453 with open(self.RscriptsPath['afc_graph'], 'r') as f:
456 # self.DictPathOut['RData'], \
457 scripts = txt % (ffr(self.RscriptsPath['Rgraph']),\
458 self.param['typegraph'], \
459 self.param['what'], \
460 self.param['facteur'][0],\
461 self.param['facteur'][1], \
462 self.param['facteur'][2], \
464 over, do_select_nb, \
465 self.param['select_nb'], \
467 self.param['select_chi'], \
468 do_select_chi_classe, \
469 self.param['nbchic'], \
471 self.param['txt_min'], \
472 self.param['txt_max'], \
474 self.param['width'], \
475 self.param['height'],\
476 self.param['taillecar'], \
477 self.param['alpha'], \
478 self.param['film'], \
480 self.param['tchi_min'],\
481 self.param['tchi_max'],\
482 ffr(os.path.dirname(self.fileout)),\
486 def print_simi3d(self):
487 simi3d = self.parent.simi3dpanel
488 txt = '#Fichier genere par Iramuteq'
489 if simi3d.movie.GetValue() :
490 movie = "'" + ffr(os.path.dirname(self.DictPathOut['RData'])) + "'"
494 #if self.corpus.parametres['type'] == 'corpus' :
500 dm<-read.csv2("%s",row.names=1,header = %s)
502 """ % (self.DictPathOut['Contout'], header, self.DictPathOut['RData'])
506 """ % self.parent.RscriptsPath['Rgraph']
510 make.simi.afc(dm,chistabletot, lim=%i, alpha = %.2f, movie = %s)
511 """ % (simi3d.spin_1.GetValue(), float(simi3d.slider_1.GetValue())/100, movie)
512 tmpfile = tempfile.mktemp(dir=self.parent.TEMPDIR)
513 tmp = open(tmpfile,'w')
518 def dendroandbarplot(table, rownames, colnames, rgraph, tmpgraph, intxt = False, dendro=False) :
520 txttable = 'c(' + ','.join([','.join(line) for line in table]) + ')'
521 rownb = len(rownames)
522 rownames = 'c("' + '","'.join(rownames) + '")'
523 colnames = 'c("' + '","'.join(colnames) + '")'
527 di <- matrix(data=%s, nrow=%i, byrow = TRUE)
530 """ % (txttable, rownb, rownames, colnames)
537 height <- (30*ncol(di)) + (15*nrow(di))
538 height <- ifelse(height <= 400, 400, height)
540 open_file_graph("%s", width=width, height=height)
541 plot.dendro.lex(tree.cut1$tree.cl, di)
542 """ % (ffr(dendro),ffr(rgraph), ffr(tmpgraph))
545 def barplot(table, parametres, intxt = False) :
547 txttable = 'c(' + ','.join([','.join(line) for line in table]) + ')'
548 #width = 100 + (15 * len(rownames)) + (100 * len(colnames))
549 #height = len(rownames) * 15
550 rownb = len(parametres['rownames'])
553 rownames = 'c("' + '","'.join(parametres['rownames']) + '")'
554 colnames = 'c("' + '","'.join(parametres['colnames']) + '")'
559 di <- matrix(data=%s, nrow=%i, byrow = TRUE)
560 toinf <- which(di == Inf)
561 tominf <- which(di == -Inf)
564 valmax <- max(di, na.rm = TRUE)
572 if (length(tominf)) {
574 valmin <- min(di, na.rm = TRUE)
584 """ % (txttable, rownb, rownames, colnames)
587 if not 'tree' in parametres :
590 color = rainbow(nrow(di))
593 open_file_graph("%s",width = width, height = height, svg = %s)
595 layout(matrix(c(1,2),1,2, byrow=TRUE),widths=c(3,lcm(7)))
597 yp = ifelse(length(toinf), 0.2, 0)
598 ym = ifelse(length(tominf), 0.2, 0)
599 ymin <- ifelse(!length(which(di < 0)), 0, min(di) - ym)
600 coord <- barplot(as.matrix(di), beside = TRUE, col = color, space = c(0.1,0.6), ylim=c(ymin, max(di) + yp), las = 2)
602 coordinf <- coord[toinf]
604 text(x=coordinf, y=valinf + 0.1, 'i')
606 if (length(tominf)) {
607 coordinf <- coord[toinf]
609 text(x=coordinf, y=valinf - 0.1, 'i')
615 lcoord <- apply(cc, 1, mean)
618 amp <- abs(max(di) - min(di))
625 d <- signif(amp%%/%%10,1)
630 if ((i/d) == (i%%/%%d)) {
635 plot(0, axes = FALSE, pch = '')
636 legend(x = 'center' , rownames(di), fill = color)
638 """ % (ffr(parametres['rgraph']), parametres['width'], parametres['height'], ffr(parametres['tmpgraph']), parametres['svg'])
646 open_file_graph("%s", width=width, height=height, svg = %s)
647 plot.dendro.lex(tree.cut1$tree.cl, di)
648 """ % (ffr(parametres['tree']), ffr(parametres['rgraph']), parametres['width'], parametres['height'], ffr(parametres['tmpgraph']), parametres['svg'])
651 #def RAfcUci(DictAfcUciOut, nd=2, RscriptsPath='', PARCEX='0.8'):
657 # dataact<-read.csv2("%s")
658 # """ % (DictAfcUciOut['TableCont'])#, encoding)
660 # datasup<-read.csv2("%s")
661 # """ % (DictAfcUciOut['TableSup'])#, encoding)
663 # dataet<-read.csv2("%s")
664 # """ % (DictAfcUciOut['TableEt'])#, encoding)
666 # datatotsup<-cbind(dataact,datasup)
667 # datatotet<-cbind(dataact,dataet)
668 # afcact<-ca(dataact,nd=nd)
669 # afcsup<-ca(datatotsup,supcol=((ncol(dataact)+1):ncol(datatotsup)),nd=nd)
670 # afcet<-ca(datatotet,supcol=((ncol(dataact)+1):ncol(datatotet)),nd=nd)
671 # afctot<-afcsup$colcoord
672 # rownames(afctot)<-afcsup$colnames
673 # colnames(afctot)<-paste('coord. facteur',1:nd,sep=' ')
674 # afctot<-cbind(afctot,mass=afcsup$colmass)
675 # afctot<-cbind(afctot,distance=afcsup$coldist)
676 # afctot<-cbind(afctot,intertie=afcsup$colinertia)
677 # rcolet<-afcet$colsup
678 # afctmp<-afcet$colcoord[rcolet,]
679 # rownames(afctmp)<-afcet$colnames[rcolet]
680 # afctmp<-cbind(afctmp,afcet$colmass[rcolet])
681 # afctmp<-cbind(afctmp,afcet$coldist[rcolet])
682 # afctmp<-cbind(afctmp,afcet$colinertia[rcolet])
683 # afctot<-rbind(afctot,afctmp)
684 # write.csv2(afctot,file = "%s")
686 # """ % (DictAfcUciOut['afc_row'], RscriptsPath['Rgraph'])
692 # PlotAfc(afcet,filename="%s",toplot=c%s, PARCEX=PARCEX)
693 # """ % (DictAfcUciOut['AfcColAct'], "('none','active')")
695 # PlotAfc(afcsup,filename="%s",toplot=c%s, PARCEX=PARCEX)
696 # """ % (DictAfcUciOut['AfcColSup'], "('none','passive')")
697 # txt += """PlotAfc(afcet,filename="%s", toplot=c%s, PARCEX=PARCEX)
698 # """ % (DictAfcUciOut['AfcColEt'], "('none','passive')")
700 # PlotAfc(afcet,filename="%s", toplot=c%s, PARCEX=PARCEX)
701 # """ % (DictAfcUciOut['AfcRow'], "('all','none')")
702 # f = open(DictAfcUciOut['Rafcuci'], 'w')
706 class PrintSimiScript(PrintRScript) :
707 def make_script(self) :
709 self.packages(['igraph', 'proxy', 'Matrix'])
710 self.sources([self.analyse.parent.RscriptsPath['simi'], self.analyse.parent.RscriptsPath['Rgraph']])
712 if not self.parametres['keep_coord'] and not (self.parametres['type'] == 'simimatrix' or self.parametres['type'] == 'simiclustermatrix') :
717 """ % (ffr(self.pathout['mat01.csv']), ffr(self.pathout['actives.csv']), ffr(self.pathout['selected.csv']))
718 if 'word' in self.parametres :
722 """ % self.parametres['word']
729 cn <- read.table(cn.path, sep='\t', quote='"')
730 colnames(dm) <- cn[,1]
731 if (file.exists(selected.col)) {
732 sel.col <- read.csv2(selected.col, header = FALSE)
733 sel.col <- sel.col[,1] + 1
735 sel.col <- 1:ncol(dm)
740 forme <- colnames(dm)[index]
741 if (!index %in% sel.col) {
742 sel.col <- append(sel.col, index)
745 index <- which(colnames(dm) == forme)
748 elif not self.parametres['keep_coord'] and (self.parametres['type'] == 'simimatrix' or self.parametres['type'] == 'simiclustermatrix'):
752 """ % (ffr(self.pathout['mat01.csv']), ffr(self.pathout['selected.csv']))
753 if 'word' in self.parametres :
757 """ % self.parametres['word']
763 dm <-read.csv2(dm.path)
765 if (file.exists(selected.col)) {
766 sel.col <- read.csv2(selected.col, header = FALSE)
767 sel.col <- sel.col[,1] + 1
769 sel.col <- 1:ncol(dm)
774 forme <- colnames(dm)[index]
775 if (!index %in% sel.col) {
776 sel.col <- append(sel.col, index)
779 index <- which(colnames(dm) == forme)
785 """ % ffr(self.pathout['RData.RData'])
787 if self.parametres['coeff'] == 0 :
789 if not self.parametres['keep_coord'] :
795 if not self.parametres['keep_coord'] :
799 if self.parametres['coeff'] == 1 :
803 mat <- simil(dm, method = 'Russel', diag = TRUE, upper = TRUE, by_rows = FALSE)
805 elif self.analyse.indices[self.parametres['coeff']] == 'binomial' :
807 if not self.parametres['keep_coord'] :
812 elif self.parametres['coeff'] != 0 :
813 method = self.analyse.indices[self.parametres['coeff']]
814 if not self.parametres['keep_coord'] :
817 mat <- simil(dm, method = method, diag = TRUE, upper = TRUE, by_rows = FALSE)
818 """ % self.analyse.indices[self.parametres['coeff']]
819 if not self.parametres['keep_coord'] :
821 mat <- as.matrix(stats::as.dist(mat,diag=TRUE,upper=TRUE))
823 if (length(which(mat == Inf))) {
824 infp <- which(mat == Inf)
826 maxmat <- max(mat, na.rm = TRUE)
834 if (length(which(mat == -Inf))) {
835 infm <- which(mat == -Inf)
837 minmat <- min(mat, na.rm = TRUE)
846 if 'word' in self.parametres and not self.parametres['keep_coord'] :
848 mat <- graph.word(mat, index)
850 if (length(cs)) mat <- mat[,-which(cs==0)]
852 if (length(rs)) mat <- mat[-which(rs==0),]
853 if (length(cs)) dm <- dm[, -which(cs==0)]
856 if self.parametres['layout'] == 0 : layout = 'random'
857 if self.parametres['layout'] == 1 : layout = 'circle'
858 if self.parametres['layout'] == 2 : layout = 'frutch'
859 if self.parametres['layout'] == 3 : layout = 'kawa'
860 if self.parametres['layout'] == 4 : layout = 'graphopt'
864 if self.parametres['type_graph'] == 0 : type = 'tkplot'
865 if self.parametres['type_graph'] == 1 :
868 dirout = os.path.dirname(self.pathout['mat01.csv'])
869 while os.path.exists(os.path.join(dirout,'graph_simi_'+str(graphnb)+'.png')):
871 self.filename = ffr(os.path.join(dirout,'graph_simi_'+str(graphnb)+'.png'))
872 if self.parametres['type_graph'] == 2 : type = 'rgl'
873 if self.parametres['type_graph'] == 3 :
876 dirout = os.path.dirname(self.pathout['mat01.csv'])
877 while os.path.exists(os.path.join(dirout,'web_'+str(graphnb))):
879 self.filename = ffr(os.path.join(dirout,'web_'+str(graphnb)))
880 os.mkdir(self.filename)
881 self.filename = os.path.join(self.filename, 'gexf.gexf')
882 if self.parametres['type_graph'] == 4 :
885 dirout = os.path.dirname(self.pathout['mat01.csv'])
886 while os.path.exists(os.path.join(dirout,'webrgl_'+str(graphnb))):
888 self.filename = ffr(os.path.join(dirout,'webrgl_'+str(graphnb)))
889 os.mkdir(self.filename)
891 if self.parametres['arbremax'] :
893 self.txtgraph += ' - arbre maximum'
894 else : arbremax = 'FALSE'
896 if self.parametres['coeff_tv'] :
897 coeff_tv = self.parametres['coeff_tv_nb']
898 tvminmax = 'c(NULL,NULL)'
899 elif not self.parametres['coeff_tv'] or self.parametres.get('sformchi', False) :
901 tvminmax = 'c(%i, %i)' %(self.parametres['tvmin'], self.parametres['tvmax'])
902 if self.parametres['coeff_te'] : coeff_te = 'c(%i,%i)' % (self.parametres['coeff_temin'], self.parametres['coeff_temax'])
903 else : coeff_te = 'NULL'
905 if self.parametres['vcex'] or self.parametres.get('cexfromchi', False) :
906 vcexminmax = 'c(%i/10,%i/10)' % (self.parametres['vcexmin'],self.parametres['vcexmax'])
908 vcexminmax = 'c(NULL,NULL)'
909 if not self.parametres['label_v'] : label_v = 'FALSE'
910 else : label_v = 'TRUE'
912 if not self.parametres['label_e'] : label_e = 'FALSE'
913 else : label_e = 'TRUE'
915 if self.parametres['seuil_ok'] : seuil = str(self.parametres['seuil'])
916 else : seuil = 'NULL'
918 if not self.parametres.get('edgecurved', False) :
927 cols = str(self.parametres['cols']).replace(')',', max=255)')
928 cola = str(self.parametres['cola']).replace(')',',max=255)')
938 """ % self.parametres['cex']
940 if self.parametres['film'] :
943 """ % ffr(self.pathout['film'])
950 if (!is.null(seuil)) {
951 if (method!='cooc') {
960 """ % (label_v, label_e)
968 """ % (self.parametres['width'], self.parametres['height'])
969 if self.parametres['keep_coord'] :
971 coords <- try(coords, TRUE)
972 if (!is.matrix(coords)) {
982 """ % self.parametres['alpha']
985 """ % self.parametres['alpha']
986 #############################################
987 if self.parametres.get('bystar',False) :
991 for i, line in enumerate(self.parametres['listet']) :
994 """ % (i+1, ','.join([`val + 1` for val in line]))
997 """ % ("','".join([val for val in self.parametres['selectedstars']]))
1001 for (i in 1:length(unetoile)) {
1004 if (length(tosum) > 1) {
1005 fsum <- cbind(fsum, colSums(dm[tosum,]))
1007 fsum <- cbind(fsum, dm[tosum,])
1011 lex <- AsLexico2(fsum, chip=TRUE)
1012 dcol <- apply(lex[[4]],1,which.max)
1013 toblack <- apply(lex[[4]],1,max)
1014 gcol <- rainbow(length(unetoile))
1015 #gcol[2] <- 'orange'
1016 vertex.label.color <- gcol[dcol]
1017 vertex.label.color[which(toblack <= 3.84)] <- 'black'
1018 leg <- list(unetoile=unetoile, gcol=gcol)
1019 cols <- vertex.label.color
1020 chivertex.size <- norm.vec(toblack, vcexminmax[1], vcexminmax[2])
1022 """ % (ffr(self.analyse.parent.RscriptsPath['chdfunct']))
1025 vertex.label.color <- 'black'
1029 #############################################
1032 # eff <- colSums(dm)
1033 # g.ori <- graph.adjacency(mat, mode='lower', weighted = TRUE)
1034 # w.ori <- E(g.ori)$weight
1036 # if (method == 'cooc') {
1037 # E(g.ori)$weight <- 1 / w.ori
1039 # E(g.ori)$weigth <- 1 - w.ori
1041 # g.max <- minimum.spanning.tree(g.ori)
1042 # if (method == 'cooc') {
1043 # E(g.max)$weight <- 1 / E(g.max)$weight
1045 # E(g.max)$weight <- 1 - E(g.max)$weight
1052 if self.parametres['com'] :
1053 com = `self.parametres['communities']`
1056 if self.parametres['halo'] :
1066 x <- list(mat = mat, eff = eff)
1067 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)
1068 """ % (method, type, layout, arbremax, coeff_tv, coeff_te)
1070 if self.parametres.get('bystar',False) :
1071 if self.parametres.get('cexfromchi', False) :
1073 label.cex<-chivertex.size
1079 if self.parametres.get('sfromchi', False) :
1081 vertex.size <- norm.vec(toblack, minmaxeff[1], minmaxeff[2])
1088 #print self.parametres
1089 if (self.parametres['type'] == 'clustersimitxt' and self.parametres.get('tmpchi', False)) or (self.parametres['type'] in ['simimatrix','simiclustermatrix'] and 'tmpchi' in self.parametres):
1091 lchi <- read.table("%s")
1093 """ % ffr(self.parametres['tmpchi'])
1095 lchi <- lchi[sel.col]
1097 if self.parametres['type'] in ['clustersimitxt', 'simimatrix', 'simiclustermatrix'] and self.parametres.get('cexfromchi', False) :
1099 label.cex <- norm.vec(lchi, vcexminmax[1], vcexminmax[2])
1103 if (is.null(vcexminmax[1])) {
1106 label.cex <- graph.simi$label.cex
1109 if (self.parametres['type'] in ['clustersimitxt', 'simimatrix', 'simiclustermatrix']) and self.parametres.get('sfromchi', False):
1111 vertex.size <- norm.vec(lchi, minmaxeff[1], minmaxeff[2])
1112 if (!length(vertex.size)) vertex.size <- 0
1116 if (is.null(minmaxeff[1])) {
1119 vertex.size <- graph.simi$eff
1122 #txt += """ vertex.size <- NULL """
1123 if self.parametres['svg'] : svg = 'TRUE'
1124 else : svg = 'FALSE'
1130 if (!is.null(graph.simi$com)) {
1131 com <- graph.simi$com
1132 colm <- rainbow(length(com))
1133 if (vertex.size != 0 || graph.simi$halo) {
1134 vertex.label.color <- 'black'
1135 vertex.col <- colm[membership(com)]
1137 vertex.label.color <- colm[membership(com)]
1140 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)
1141 save.image(file="%s")
1142 """ % (type, self.filename, ffr(self.pathout['RData']))
1147 class WordCloudRScript(PrintRScript) :
1148 def make_script(self) :
1149 self.sources([self.analyse.parent.RscriptsPath['Rgraph']])
1150 self.packages(['wordcloud'])
1151 bg_col = Rcolor(self.parametres['col_bg'])
1152 txt_col = Rcolor(self.parametres['col_text'])
1153 if self.parametres['svg'] :
1161 act <- read.csv2("%s", header = FALSE, row.names=1, sep='\t')
1162 selected.col <- read.table("%s")
1163 toprint <- as.matrix(act[selected.col[,1] + 1,])
1164 rownames(toprint) <- rownames(act)[selected.col[,1] + 1]
1166 if (nrow(toprint) > maxword) {
1167 toprint <- as.matrix(toprint[order(toprint[,1], decreasing=TRUE),])
1168 toprint <- as.matrix(toprint[1:maxword,])
1170 open_file_graph("%s", width = %i, height = %i , svg = svg)
1172 wordcloud(row.names(toprint), toprint[,1], scale=c(%f,%f), random.order=FALSE, colors=rgb%s)
1174 """ % (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)
1178 class ProtoScript(PrintRScript) :
1179 def make_script(self) :
1180 self.sources([self.analyse.parent.RscriptsPath['Rgraph'], self.analyse.parent.RscriptsPath['prototypical.R']])
1181 self.packages(['wordcloud'])
1182 if self.parametres.get('cloud', False) :
1187 errorn <- function(x) {
1188 qnorm(0.975)*sd(x)/sqrt(lenght(n))
1190 errort <- function(x) {
1191 qt(0.975,df=lenght(x)-1)*sd(x)/sqrt(lenght(x))
1193 mat <- read.csv2("%s", header = FALSE, row.names=1, sep='\t', quote='"', dec='.')
1194 open_file_graph("%s",height=800, width=1000)
1195 prototypical(mat, mfreq = %s, mrank = %s, cloud = FALSE, cexrange=c(1,2.4), cexalpha= c(0.4, 1), type = '%s')
1197 """ % (ffr(self.analyse.pathout['table.csv']), ffr(self.analyse.pathout['proto.png']), self.parametres['limfreq'], self.parametres['limrang'], self.parametres['typegraph'])
1202 class ExportAfc(PrintRScript) :
1203 def make_script(self) :
1204 self.source([self.analyse.parent.RscriptsPath['Rgraph']])
1205 self.packages(['rgexf'])
1209 class MergeGraphes(PrintRScript) :
1210 def __init__(self, analyse):
1211 self.script = u"#Script genere par IRaMuTeQ - %s\n" % datetime.now().ctime()
1212 self.pathout = PathOut()
1213 self.parametres = analyse.parametres
1214 self.scriptout = self.pathout['temp']
1215 self.analyse = analyse
1217 def make_script(self) :
1227 g <- graph.simi$graph
1228 V(g)$weight <- (graph.simi$mat.eff/nrow(dm))*100
1231 for i, graph in enumerate(self.parametres['graphs']) :
1232 path = os.path.dirname(graph)
1233 gname = ''.join(['g', `i`])
1234 RData = os.path.join(path,'RData.RData')
1235 txt += load % (ffr(RData), gname)
1237 self.sources([self.analyse.parent.RscriptsPath['simi']])
1239 ng <- merge.graph(graphs)
1240 ngraph <- list(graph=ng, layout=layout.fruchterman.reingold(ng, dim=3), labex.cex=V(ng)$weight)
1241 write.graph(ng, "%s", format = 'graphml')
1242 """ % ffr(self.parametres['grapheout'])
1245 class TgenSpecScript(PrintRScript):
1246 def make_script(self):
1247 self.packages(['textometry'])
1249 tgen <- read.csv2("%s", row.names = 1, sep = '\\t')
1250 """ % ffr(self.parametres['tgeneff'])
1252 tot <- tgen[nrow(tgen), ]
1254 tgen <- tgen[-nrow(tgen),]
1255 for (i in 1:nrow(tgen)) {
1256 mat <- rbind(tgen[i,], tot - tgen[i,])
1257 specmat <- specificities(mat)
1258 result <- rbind(result, specmat[1,])
1260 colnames(result) <- colnames(tgen)
1261 row.names(result) <- rownames(tgen)
1262 write.table(result, file = "%s", sep='\\t', col.names = NA)
1263 """ % ffr(self.pathout['tgenspec.csv'])
1266 class TgenProfScript(PrintRScript):
1267 def make_script(self):
1268 self.sources([self.analyse.ira.RscriptsPath['chdfunct']])
1270 tgen <- read.csv2("%s", row.names = 1, sep = '\\t')
1271 """ % ffr(self.parametres['tgeneff'])
1273 tgenlem <- read.csv2("%s", row.names = 1, sep = '\\t')
1274 """ % ffr(self.parametres['tgenlemeff'])
1276 res <- build.prof.tgen(tgen)
1277 write.table(res$chi2, file = "%s", sep='\\t', col.names = NA)
1278 write.table(res$pchi2, file = "%s", sep='\\t', col.names = NA)
1279 """ % (ffr(self.pathout['tgenchi2.csv']), ffr(self.pathout['tgenpchi2.csv']))
1281 reslem <- build.prof.tgen(tgenlem)
1282 write.table(reslem$chi2, file = "%s", sep='\\t', col.names = NA)
1283 write.table(reslem$pchi2, file = "%s", sep='\\t', col.names = NA)
1284 """ % (ffr(self.pathout['tgenlemchi2.csv']), ffr(self.pathout['tgenlempchi2.csv']))
1287 class FreqMultiScript(PrintRScript):
1288 def make_script(self):
1289 self.sources([self.analyse.parent.RscriptsPath['Rgraph']])
1291 freq <- read.csv2("%s", row.names=1, sep='\\t', dec='.')
1292 """ % ffr(self.pathout['frequences.csv'])
1294 toplot <- freq[order(freq[,2]) ,2]
1295 toplot.names = rownames(freq)[order(freq[,2])]
1296 h <- 80 + (20 * nrow(freq))
1297 open_file_graph("%s",height=h, width=500)
1298 par(mar=c(3,20,3,3))
1299 barplot(toplot, names = toplot.names, horiz=TRUE, las =1, col = rainbow(nrow(freq)))
1301 """ % ffr(self.pathout['barplotfreq.png'])
1303 toplot <- freq[order(freq[,4]) ,4]
1304 toplot.names = rownames(freq)[order(freq[,4])]
1305 open_file_graph("%s",height=h, width=500)
1306 par(mar=c(3,20,3,3))
1307 barplot(toplot, names = toplot.names, horiz=TRUE, las =1, col = rainbow(nrow(freq)))
1309 """ % ffr(self.pathout['barplotrow.png'])
1313 class LabbeScript(PrintRScript) :
1314 def make_script(self) :
1315 self.sources([self.analyse.parent.RscriptsPath['distance-labbe.R'],
1316 self.analyse.parent.RscriptsPath['Rgraph']])
1318 tab <- read.csv2("%s", header=TRUE, sep=';', row.names=1)
1319 """ % (self.pathout['tableafcm.csv'])
1321 dist.mat <- dist.labbe(tab)
1322 dist.mat <- as.dist(dist.mat, upper=F, diag=F)
1323 write.table(as.matrix(dist.mat), "%s", sep='\t')
1326 chd <- hclust(dist.mat, method="ward.D2")
1327 open_file_graph("%s", width=1000, height=1000, svg=F)
1329 plot.phylo(as.phylo(chd), type='unrooted', lab4ut="axial")
1331 """ % (self.pathout['distmat.csv'], self.pathout['dist-labbe.png'])
1335 class ChronoChi2Script(PrintRScript) :
1336 def make_script(self) :
1337 self.sources([self.analyse.parent.RscriptsPath['Rgraph']])
1338 print self.parametres
1344 """ % (ffr(self.pathout['RData.RData']), ffr(self.pathout['dendrogramme.RData']))
1347 """ % self.parametres['svg']
1349 tc <- which(grepl("%s",rownames(chistabletot)))
1350 rn <- rownames(chistabletot)[tc]
1352 dpt <- chistabletot[tc,]
1353 tot <- afctable[tc,]
1358 """ % self.parametres['var']
1360 classes <- n1[,ncol(n1)]
1361 tcl <- table(classes)
1362 if ('0' %in% names(tcl)) {
1363 to.vire <- which(names(tcl) == '0')
1364 tcl <- tcl[-to.vire]
1366 tclp <- tcl/sum(tcl)
1374 lcol <- c(lcol, qchisq(1-k,1))
1378 lcol <- c(3.84, lcol)
1379 lcol <- c(-Inf,lcol)
1380 lcol <- c(lcol, Inf)
1383 alphas <- seq(0,1, length.out=length(breaks))
1384 clod <- rev(as.numeric(tree.cut1$tree.cl$tip.label))
1388 open_file_graph("%s", w=%i, h=%i, svg=svg)
1389 """ % (ffr(self.parametres['tmpgraph']), self.parametres['width'], self.parametres['height'])
1392 mat.graphic <- matrix(c(rep(1,nrow(dd)),c(2:(nrow(dd)+1))), ncol=2)
1393 mat.graphic <- rbind(mat.graphic, c(max(mat.graphic) + 1 , max(mat.graphic) + 2))
1394 hauteur <- tclp[clod] * 0.9
1395 heights.graphic <- append(hauteur, 0.1)
1396 layout(mat.graphic, heights=heights.graphic, widths=c(0.15,0.85))
1398 tree.toplot <- tree.cut1$tree.cl
1399 tree.toplot$tip.label <- paste('classe ', tree.toplot$tip.label)
1400 plot.phylo(tree.toplot,label.offset=0.1, cex=1.1, no.margin=T)
1404 lcol <- cut(dd[i,], breaks, include.lowest=TRUE)
1405 ulcol <- names(table(lcol))
1406 lcol <- as.character(lcol)
1407 for (j in 1:length(ulcol)) {
1408 lcol[which(lcol==ulcol[j])] <- j
1410 lcol <- as.numeric(lcol)
1411 mcol <- rainbow(nrow(dd))[i]
1414 last.col <- c(last.col, rgb(r=col2rgb(mcol)[1]/255, g=col2rgb(mcol)[2]/255, b=col2rgb(mcol)[3]/255, a=k))
1418 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))
1420 plot(0,type='n',axes=FALSE,ann=FALSE)
1421 label.coords <- barplot(rep(1, ncol(dd)), width=ptc, names.arg = F, las=2, axes=F, ylim=c(0,1), plot=T, col='white')
1422 text(x=label.coords, y=0.5, labels=rn[order(rn)], srt=90)
1428 class ChronoPropScript(PrintRScript) :
1429 def make_script(self) :
1430 self.sources([self.analyse.parent.RscriptsPath['Rgraph']])
1431 print self.parametres
1437 """ % (ffr(self.pathout['RData.RData']), ffr(self.pathout['dendrogramme.RData']))
1440 """ % self.parametres['svg']
1442 tc <- which(grepl("%s",rownames(chistabletot)))
1443 rn <- rownames(chistabletot)[tc]
1445 dpt <- chistabletot[tc,]
1446 tot <- afctable[tc,]
1451 """ % self.parametres['var']
1453 classes <- n1[,ncol(n1)]
1454 tcl <- table(classes)
1455 if ('0' %in% names(tcl)) {
1456 to.vire <- which(names(tcl) == '0')
1457 tcl <- tcl[-to.vire]
1459 tclp <- tcl/sum(tcl)
1462 open_file_graph("%s", w=%i, h=%i, svg=svg)
1463 """ % (ffr(self.parametres['tmpgraph']), self.parametres['width'], self.parametres['height'])
1465 ptt <- prop.table(as.matrix(tot), 1)
1466 par(mar=c(10,2,2,2))
1467 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)