def rconnect( self, creator = None ): '''open connection within R to database.''' if not self.rdb: R.library( 'RSQLite' ) if creator: self.rdb = creator() else: if self.backend.startswith( 'sqlite' ): self.rdb = R.dbConnect(R.SQLite(), dbname=re.sub( "sqlite:///./", "", self.backend ) ) else: raise NotImplementedError("can not connect to %s in R" % self.backend )
#This bit connects to R and gets the information itself. from rpy2 import * from rpy2.robjects import r 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)):