X-Git-Url: http://iramuteq.org/git?a=blobdiff_plain;ds=sidebyside;f=PrintRScript.py;h=f8aaa961ee6bd3eefe99570aee34014c6ef82a7c;hb=refs%2Fheads%2F3.0;hp=0699b3fdf8f40528f08acbc7f9e79b87ec0e5ad3;hpb=1301403740fe3e9487f67a07870796f9e3dfb1f9;p=iramuteq diff --git a/PrintRScript.py b/PrintRScript.py index 0699b3f..0ce0bfc 100755 --- a/PrintRScript.py +++ b/PrintRScript.py @@ -58,7 +58,7 @@ class PrintRScript: self.add('load("%s")' % ffr(val)) def write(self): - with open(self.scriptout, 'w') as f: + with open(self.scriptout, 'w', encoding='utf8') as f: f.write(self.script) @@ -125,7 +125,7 @@ class Alceste2(PrintRScript): # -def RchdTxt(DicoPath, RscriptPath, mincl, classif_mode, nbt = 9, svdmethod = 'svdR', libsvdc = False, libsvdc_path = None, R_max_mem = False, mode_patate = False, nbproc=1): +def RchdTxt(DicoPath, RscriptPath, mincl, classif_mode, nbt = 9, svdmethod = 'svdR', libsvdc = False, libsvdc_path = None, R_max_mem = False, mode_patate = False, nbproc=10): txt = """ source("%s") source("%s") @@ -176,7 +176,7 @@ def RchdTxt(DicoPath, RscriptPath, mincl, classif_mode, nbt = 9, svdmethod = 'sv row.names(data2) <- 1:nrow(data2) """ % ffr(DicoPath['TableUc2']) txt += """ - log1 <- "%s" + #log1 <- "%s" #print('FIXME : source newCHD') #source('/home/pierre/workspace/iramuteq/Rscripts/newCHD.R') #nbproc <- %s @@ -262,7 +262,7 @@ def RchdTxt(DicoPath, RscriptPath, mincl, classif_mode, nbt = 9, svdmethod = 'sv txt += """ #save.image(file="%s") """ % (ffr(DicoPath['RData'])) - fileout = open(DicoPath['Rchdtxt'], 'w') + fileout = open(DicoPath['Rchdtxt'], 'w', encoding='utf8') fileout.write(txt) fileout.close() @@ -287,7 +287,7 @@ def RPamTxt(corpus, RscriptPath): txt += """ save.image(file="%s") """ % DicoPath['RData'] - fileout = open(DicoPath['Rchdtxt'], 'w') + fileout = open(DicoPath['Rchdtxt'], 'w', encoding='utf8') fileout.write(txt) fileout.close() @@ -324,7 +324,7 @@ def RchdQuest(DicoPath, RscriptPath, nbcl = 10, mincl = 10): txt += """ save.image(file="%s") """ % ffr(DicoPath['RData']) - fileout = open(DicoPath['Rchdquest'], 'w') + fileout = open(DicoPath['Rchdquest'], 'w', encoding='utf8') fileout.write(txt) fileout.close() @@ -428,7 +428,7 @@ rm(tablesqrpsup) rm(tablesqrpet) save.image(file="%s") """ % ffr(DictChdTxtOut['RData']) - file = open(DictChdTxtOut['RTxtProfGraph'], 'w') + file = open(DictChdTxtOut['RTxtProfGraph'], 'w', encoding='utf8') file.write(txt) file.close() @@ -467,7 +467,7 @@ def write_afc_graph(self): else: nodesfile = 'NULL' edgesfile = 'NULL' - with open(self.RscriptsPath['afc_graph'], 'r') as f: + with open(self.RscriptsPath['afc_graph'], 'r', encoding='utf8') as f: txt = f.read() # self.DictPathOut['RData'], \ scripts = txt % (ffr(self.RscriptsPath['Rgraph']),\ @@ -523,7 +523,7 @@ def print_simi3d(self): make.simi.afc(dm,chistabletot, lim=%i, alpha = %.2f, movie = %s) """ % (simi3d.spin_1.GetValue(), float(simi3d.slider_1.GetValue())/100, movie) tmpfile = tempfile.mktemp(dir=self.parent.TEMPDIR) - tmp = open(tmpfile,'w') + tmp = open(tmpfile,'w', encoding='utf8') tmp.write(txt) tmp.close() return tmpfile @@ -619,7 +619,7 @@ def barplot(table, parametres, intxt = False): coordinf <- coord[toinf] valinf <- di[toinf] text(x=coordinf, y=valinf - 0.1, 'i') - } + } c <- colMeans(coord) c1 <- c[-1] c2 <- c[-length(c)] @@ -639,15 +639,15 @@ def barplot(table, parametres, intxt = False): mn <- round(min(di)) mx <- round(max(di)) for (i in mn:mx) { - if ((i/d) == (i%%/%%d)) { + if ((i/d) == (i%%/%%d)) { abline(h=i,lty=3) } } par(mar=c(0,0,0,0)) plot(0, axes = FALSE, pch = '') - legend(x = 'center' , rownames(di), fill = color) + legend(x = 'center' , rownames(di) , fill = color) dev.off() - """ % (ffr(parametres['rgraph']), parametres['width'], parametres['height'], ffr(parametres['tmpgraph']), parametres['svg']) + """ % (ffr(parametres['rgraph']), parametres['width'], parametres['height'], ffr(parametres['tmpgraph']), parametres['svg']) else: txt += """ load("%s") @@ -741,7 +741,7 @@ class PrintSimiScript(PrintRScript): """ txt += """ dm <-readMM(dm.path) - cn <- read.table(cn.path, sep="\t", quote='"') + cn <- read.table(cn.path, sep="\t", quote='"', comment.char="") colnames(dm) <- cn[,1] if (file.exists(selected.col)) { sel.col <- read.csv2(selected.col, header = FALSE) @@ -1172,7 +1172,7 @@ class PrintSimiScript(PrintRScript): if (!is.null(graph.simi$com)) { com <- graph.simi$com colm <- rainbow(length(com)) - if (vertex.size != 0 || graph.simi$halo) { + if (sum(vertex.size) != 0 || graph.simi$halo) { vertex.label.color <- 'black' vertex.col <- colm[membership(com)] } else { @@ -1243,7 +1243,7 @@ class ProtoScript(PrintRScript): } 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), type = '%s', mat.col.path='/tmp/matcol.csv') + prototypical(mat, mfreq = %s, mrank = %s, cloud = FALSE, cexrange=c(1,2.4), cexalpha= c(0.4, 1), type = '%s')#, mat.col.path='/tmp/matcol.csv') dev.off() """ % (ffr(self.analyse.pathout['table.csv']), ffr(self.analyse.pathout['proto.png']), self.parametres['limfreq'], self.parametres['limrang'], self.parametres['typegraph']) self.add(txt) @@ -1343,7 +1343,7 @@ class TgenProfScript(PrintRScript): reslem <- build.prof.tgen(tgenlem) write.table(reslem$chi2, file = "%s", sep='\\t', col.names = NA) write.table(reslem$pchi2, file = "%s", sep='\\t', col.names = NA) - """ % (ffr(self.pathout['tgenlemchi2.csv']), ffr(self.pathout['tgenlempchi2.csv'])) + """ % (ffr(self.pathout['tgenlemchi2.csv']), ffr(self.pathout['tgenlempchi2.csv'])) self.add(txt)