def pyevenn(datasets,figurename='defaultevenn.png',outputdir=''): outputdir=os.path.abspath(outputdir) if not os.path.exists(os.path.join(outputdir,'evenn')): os.mkdir(os.path.join(outputdir,'evenn')) os.mkdir(os.path.join(outputdir,'evenn','input')) os.mkdir(os.path.join(outputdir,'evenn','output')) else: fhutils.execwrapper('rm -r '+os.path.join(outputdir,'evenn')) os.mkdir(os.path.join(outputdir,'evenn')) os.mkdir(os.path.join(outputdir,'evenn','input')) os.mkdir(os.path.join(outputdir,'evenn','output')) inputdir=os.path.join(outputdir,'evenn','input') print inputdir outputdir=os.path.join(outputdir,'evenn','output') tabnames = writesets(datasets,outputdir=inputdir,outformat='evenn') nomvector=robjects.vectors.StrVector(tabnames) robjects.r("rm(list = ls()); graphics.off()") robjects.r("""pathnames <- list.files(pattern="[.]R$", path=Sys.getenv('FHR'), full.names=TRUE)""") robjects.r("sapply(pathnames, FUN=source)") fh_evenn=robjects.r("fh_evenn") fh_evenn(inputdir,nomvector,outputdir) files=os.listdir(outputdir) for folder in files: if os.path.isdir(os.path.join(outputdir,folder)): vennout=os.listdir(os.path.join(outputdir,folder)) for fi in vennout: if fi=='venn_diagram.png': fi=os.path.join(outputdir,folder,'venn_diagram.png') os.rename(fi,figurename)
def pyevenn(datasets, figurename='defaultevenn.png', outputdir=''): outputdir = os.path.abspath(outputdir) if not os.path.exists(os.path.join(outputdir, 'evenn')): os.mkdir(os.path.join(outputdir, 'evenn')) os.mkdir(os.path.join(outputdir, 'evenn', 'input')) os.mkdir(os.path.join(outputdir, 'evenn', 'output')) else: fhutils.execwrapper('rm -r ' + os.path.join(outputdir, 'evenn')) os.mkdir(os.path.join(outputdir, 'evenn')) os.mkdir(os.path.join(outputdir, 'evenn', 'input')) os.mkdir(os.path.join(outputdir, 'evenn', 'output')) inputdir = os.path.join(outputdir, 'evenn', 'input') print inputdir outputdir = os.path.join(outputdir, 'evenn', 'output') tabnames = writesets(datasets, outputdir=inputdir, outformat='evenn') nomvector = robjects.vectors.StrVector(tabnames) robjects.r("rm(list = ls()); graphics.off()") robjects.r( """pathnames <- list.files(pattern="[.]R$", path=Sys.getenv('FHR'), full.names=TRUE)""" ) robjects.r("sapply(pathnames, FUN=source)") fh_evenn = robjects.r("fh_evenn") fh_evenn(inputdir, nomvector, outputdir) files = os.listdir(outputdir) for folder in files: if os.path.isdir(os.path.join(outputdir, folder)): vennout = os.listdir(os.path.join(outputdir, folder)) for fi in vennout: if fi == 'venn_diagram.png': fi = os.path.join(outputdir, folder, 'venn_diagram.png') os.rename(fi, figurename)
def rrunner(scriptstring,clean=False): """help function if no rpy is available - now disabled """ scriptfile=str(os.getpid())+'execute.R' out=open(scriptfile,'w') out.write(scriptstring) out.close() command ='R CMD BATCH --no-restore --slave --no-save '+scriptfile ret=fhutils.execwrapper(command) if ret == 0 and clean == True: os.remove(scriptfile) os.remove(scriptfile+'out') else: os.rename(scriptfile,scriptfile+str(fhutils.dtk())) os.rename(scriptfile+'out',scriptfile+'.out'+str(fhutils.dtk()))
def rrunner(scriptstring, clean=False): """help function if no rpy is available - now disabled """ scriptfile = str(os.getpid()) + 'execute.R' out = open(scriptfile, 'w') out.write(scriptstring) out.close() command = 'R CMD BATCH --no-restore --slave --no-save ' + scriptfile ret = fhutils.execwrapper(command) if ret == 0 and clean == True: os.remove(scriptfile) os.remove(scriptfile + 'out') else: os.rename(scriptfile, scriptfile + str(fhutils.dtk())) os.rename(scriptfile + 'out', scriptfile + '.out' + str(fhutils.dtk()))
def rrunner(scriptstring, datafile, clean=True): scriptfile = str(os.getpid()) + 'execute.R' out = open(scriptfile, 'w') out.write(scriptstring) out.close() command = 'R CMD BATCH --no-restore --slave --no-save ' + scriptfile ret = fhutils.execwrapper(command) if ret == 0: if datafile: os.remove(datafile) os.remove(scriptfile) os.remove(scriptfile + 'out') else: if datafile: os.rename(datafile, datafile + str(fhutils.dtk())) os.rename(scriptfile, scriptfile + str(fhutils.dtk())) os.rename(scriptfile + 'out', scriptfile + '.out' + str(fhutils.dtk()))