X-Git-Url: http://iramuteq.org/git?p=iramuteq;a=blobdiff_plain;f=PrintRScript.py;h=d81d070ca0531ca0eaa12b50462e1adec3d83051;hp=6c102a07c4d3a68301965de72d0c30f3f723ff11;hb=ff602f724b8fc80f4fa067dbbc830343c0b4bed4;hpb=8d94ffe1d9f4b9d1dcb4214fb7b58bbe9efa1814 diff --git a/PrintRScript.py b/PrintRScript.py index 6c102a0..d81d070 100644 --- a/PrintRScript.py +++ b/PrintRScript.py @@ -33,7 +33,7 @@ class PrintRScript : def sources(self, lsources) : for source in lsources : - self.add('source("%s")' % source) + self.add('source("%s", encoding = \'utf8\')' % source) def packages(self, lpks) : for pk in lpks : @@ -711,8 +711,12 @@ class PrintSimiScript(PrintRScript) : dm <-readMM(dm.path) cn <- read.table(cn.path, sep='\t', quote='"') colnames(dm) <- cn[,1] - sel.col <- read.csv2(selected.col, header = FALSE) - sel.col <- sel.col[,1] + 1 + if (file.exists(selected.col)) { + sel.col <- read.csv2(selected.col, header = FALSE) + sel.col <- sel.col[,1] + 1 + } else { + sel.col <- 1:ncol(dm) + } if (!word) { dm <- dm[, sel.col] } else { @@ -741,8 +745,12 @@ class PrintSimiScript(PrintRScript) : txt += """ dm <-read.csv2(dm.path) dm <- as.matrix(dm) - sel.col <- read.csv2(selected.col, header = FALSE) - sel.col <- sel.col[,1] + 1 + if (file.exists(selected.col)) { + sel.col <- read.csv2(selected.col, header = FALSE) + sel.col <- sel.col[,1] + 1 + } else { + sel.col <- 1:ncol(dm) + } if (!word) { dm <- dm[, sel.col] } else { @@ -845,6 +853,14 @@ class PrintSimiScript(PrintRScript) : graphnb +=1 self.filename = ffr(os.path.join(dirout,'graph_simi_'+str(graphnb)+'.png')) if self.parametres['type_graph'] == 2 : type = 'rgl' + if self.parametres['type_graph'] == 3 : + graphnb = 1 + type = 'rglweb' + dirout = os.path.dirname(self.pathout['mat01']) + while os.path.exists(os.path.join(dirout,'webrgl_'+str(graphnb))): + graphnb +=1 + self.filename = ffr(os.path.join(dirout,'webrgl_'+str(graphnb))) + os.mkdir(self.filename) if self.parametres['arbremax'] : arbremax = 'TRUE' @@ -1018,7 +1034,7 @@ class PrintSimiScript(PrintRScript) : """ else : txt+=""" - label.cex <- NULL + label.cex <- cex """ if self.parametres.get('sfromchi', False) : txt += """ @@ -1029,7 +1045,8 @@ class PrintSimiScript(PrintRScript) : vertex.size <- NULL """ else : - if self.parametres['type'] == 'clustersimitxt' : + print self.parametres + if (self.parametres['type'] == 'clustersimitxt' and self.parametres.get('tmpchi', False)) or (self.parametres['type'] == 'simimatrix' and 'tmpchi' in self.parametres): txt += """ lchi <- read.table("%s") lchi <- lchi[,1] @@ -1044,12 +1061,12 @@ class PrintSimiScript(PrintRScript) : else : txt += """ if (is.null(vcexminmax[1])) { - label.cex <- NULL + label.cex <- cex } else { label.cex <- graph.simi$label.cex } """ - if self.parametres['type'] == 'clustersimitxt' and self.parametres.get('sfromchi', False) : + if (self.parametres['type'] == 'clustersimitxt' or self.parametres['type'] == 'simimatrix') and self.parametres.get('sfromchi', False): txt += """ vertex.size <- norm.vec(lchi, minmaxeff[1], minmaxeff[2]) if (!length(vertex.size)) vertex.size <- 0 @@ -1117,3 +1134,25 @@ class WordCloudRScript(PrintRScript) : """ % (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) self.add(txt) self.write() + +class ProtoScript(PrintRScript) : + def make_script(self) : + self.sources([self.analyse.parent.RscriptsPath['Rgraph'], self.analyse.parent.RscriptsPath['prototypical.R']]) + self.packages(['wordcloud']) + txt = """ + mat <- read.csv2("%s", header = FALSE, row.names=1, sep='\t', quote='"', dec='.') + open_file_graph("%s",height=800, width=1000) + prototypical(mat, mfreq = %s, mrank = %s, cloud = FALSE, cexrange=c(1,2.4), cexalpha= c(0.4, 1)) + dev.off() + """ % (self.analyse.pathout['table.csv'], self.analyse.pathout['proto.png'], self.parametres['limfreq'], self.parametres['limrang']) + self.add(txt) + self.write() + + +class ExportAfc(PrintRScript) : + def make_script(self) : + self.source([self.analyse.parent.RscriptsPath['Rgraph']]) + self.packages(['rgexf']) + txt = """ + """ +