f = open('rdata.dat', 'r') r.library("RMySQL") #This is how you shouldn't ever code. database = "select " database += sys.argv[4] database += " from " database += sys.argv[2] print database #Connect to the database. Note, this requires Sequel Pro, probably. con=r.dbConnect(r.MySQL(),user="******",password="******",dbname="myExperiment",host="127.0.0.1",port=8889) data=r.dbGetQuery(con, database) #All it is used for is to get the length, because that's a common problem. row = r.length(data[0]) #This is the first hardcoded graph, with all of the tags combined. It needs some work, I think. def printfirst(): print("#"+sys.argv[2] + " " + sys.argv[3] + " (All) by "+sys.argv[4]+"\n data=dbGetQuery(con,\"select "+sys.argv[3]+", "+sys.argv[4]+" from " + sys.argv[2] + "\")\n ggplot(data,aes("+sys.argv[3]+", "+sys.argv[4]+")) + geom_boxplot() +xlab(\"All "+sys.argv[3]+"\") +ylab(\""+sys.argv[4]+"\")\n file = ggplot(data,aes("+sys.argv[3]+", "+sys.argv[4]+")) + geom_boxplot() +xlab(\"All "+sys.argv[3]+"\") +ylab(\""+sys.argv[4]+"\")\n ggsave(file, file=\""+sys.argv[2]+"_"+sys.argv[3]+"_all_"+sys.argv[4]+".png\")\n \n") output.write("#"+sys.argv[2] + " " + sys.argv[3] + " (All) by "+sys.argv[4]+"\n data=dbGetQuery(con,\"select "+sys.argv[3]+", "+sys.argv[4]+" from " + sys.argv[2] + "\")\n ggplot(data,aes("+sys.argv[3]+", "+sys.argv[4]+")) + geom_boxplot() +xlab(\"All "+sys.argv[3]+"\") +ylab(\""+sys.argv[4]+"\")\n file = ggplot(data,aes("+sys.argv[3]+", "+sys.argv[4]+")) + geom_boxplot() +xlab(\"All "+sys.argv[3]+"\") +ylab(\""+sys.argv[4]+"\")\n ggsave(file, file=\""+sys.argv[2]+"_"+sys.argv[3]+"_all_"+sys.argv[4]+".png\")\n \n") #Print it. printfirst() #This is the hardcode that actually results in the R code. #I wouldn't suggest looking too hard at it, argv isn't pretty. for x in range(len(graph)): graph[x] = graph[x].replace("'","").replace(",","") print("#"+sys.argv[2] + " " + sys.argv[3] + " " + graph[x] + " by "+sys.argv[4]+"\n data=dbGetQuery(con,\"select "+sys.argv[3]+", "+sys.argv[4]+" from " + sys.argv[2] + "\")\n regex=which(grepl(\"" + graph[x] + "\",data$"+sys.argv[3]+", ignore.case=T))\n data$"+graph[x]+"_flag <- rep(NA, "+str(row[0])+")\n data$"+graph[x]+"_flag[regex]=\"Yes\"\n data$"+graph[x]+"_flag[-(regex)]=\"No\"\n ggplot(data,aes("+graph[x]+"_flag,"+sys.argv[4]+")) + geom_boxplot() +xlab(\""+graph[x]+" - "+sys.argv[3]+"\") +ylab(\""+sys.argv[4]+"\")\n file = ggplot(data,aes("+graph[x]+"_flag,"+sys.argv[4]+")) + geom_boxplot() +xlab(\"" + graph[x] + " - "+sys.argv[3]+"\") +ylab(\""+sys.argv[4]+"\")\n ggsave(file, file=\""+sys.argv[2]+"_"+sys.argv[3]+"_"+graph[x]+"_"+sys.argv[4]+".png\")\n \n")
def enableInteractivity(): while(r.length(r('dev.list()'))[0]>0): rinterface.process_revents() time.sleep(0.1)