diff SMART/Java/Python/GetReadSizes.py @ 18:94ab73e8a190

Uploaded
author m-zytnicki
date Mon, 29 Apr 2013 03:20:15 -0400
parents 769e306b7933
children
line wrap: on
line diff
--- a/SMART/Java/Python/GetReadSizes.py	Mon Apr 22 11:11:10 2013 -0400
+++ b/SMART/Java/Python/GetReadSizes.py	Mon Apr 29 03:20:15 2013 -0400
@@ -48,7 +48,7 @@
 		self.verbosity  = verbosity
 		self.number     = random.randint(0, 100000)
 		self.log        = LoggerFactory.createLogger("%s.%s" % (LOG_DEPTH, self.__class__.__name__), self.verbosity)
-		self.parsers      = {}
+		self.parsers    = {}
 		self.sizes      = {}
 		self.factors    = {}
 		self.regions    = None
@@ -56,6 +56,7 @@
 		self.tmpRName   = None
 		self.width      = 800
 		self.height     = 300
+		self.arial      = False
 
 	def setNames(self, names):
 		self.names = names
@@ -93,6 +94,9 @@
 		if height != None:
 			self.height = height
 
+	def setArial(self, arial):
+		self.arial = arial
+
 	def _checkOptions(self):
 		if not self.parsers:
 			self.logAndRaise("ERROR: Missing input file names")
@@ -174,22 +178,23 @@
 		self.tmpRName = "tmpFile%d.R" % (self.number)
 		fileName      = self.outputFileName if region == DEFAULT_REGION else "%s_%s.png" % (os.path.splitext(self.outputFileName)[0], region)
 		colors        = "scale_fill_brewer(palette=\"Set1\")" if self.colors == None else "scale_fill_manual(values = c(%s))" % (", ".join(["\"%s\"" % (color) for color in self.colors]))
-		title         = "" if region == DEFAULT_REGION else " of %s" % (region)
+		title         = "" if region == DEFAULT_REGION else " + labs(title = \"Sizes of %s\")" % (region)
 		handle        = open(self.tmpRName, "w")
+		arial         = ", text = element_text(family=\"Arial\", size=20)" if self.arial else ""
+		if self.arial:
+			handle.write("library(extrafont)\nloadfonts()\n")
 		handle.write("library(ggplot2)\n")
 		handle.write("data <- read.table(\"%s\", header = T)\n" % (self.tmpDatName))
 		handle.write("data$Sample <- factor(data$Sample, levels=c(%s))\n" % (", ".join(["\"%s\"" % (name) for name in self.names])))
 		handle.write("data$Size <- factor(data$Size, levels=c(%s))\n" % (", ".join(["%d" % (size) for size in range(self.minSize, self.maxSize+1)])))
 		handle.write("png(\"%s\", width = %d, height = %d)\n" % (fileName, self.width, self.height))
-		handle.write("ggplot(data, aes(x = Size, y = Count, fill = Size)) + opts(title = \"Size distribution%s\") + geom_bar(stat = \"identity\") + facet_grid(. ~ Sample, space=\"free_x\") + xlab(\"%s\") + ylab(\"%s\") + %s + opts(legend.position = \"none\", panel.grid.major = theme_blank(), panel.grid.minor = theme_blank(), panel.background = theme_blank())\n" % (title, self.xLab, self.yLab, colors))
+		handle.write("ggplot(data, aes(x = Size, y = Count, fill = Size)) %s + geom_bar(stat = \"identity\") + facet_grid(. ~ Sample, space=\"free_x\") + xlab(\"%s\") + ylab(\"%s\") + %s + theme(legend.position = \"none\", panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank()%s)\n" % (title, self.xLab, self.yLab, colors, arial))
 		handle.write("dev.off()\n")
 
 	def _runR(self):
-		rCommand = "R"
-		if "SMARTRPATH" in os.environ:
-			rCommand = os.environ["SMARTRPATH"]
-		command = "\"%s\" CMD BATCH %s" % (rCommand, self.tmpRName)
-		status = subprocess.call(command, shell=True)
+		rCommand = os.environ["SMARTRPATH"] if "SMARTRPATH" in os.environ else "R"
+		command  = "\"%s\" CMD BATCH %s" % (rCommand, self.tmpRName)
+		status   = subprocess.call(command, shell=True)
 		if status != 0:
 			raise Exception("Problem with the execution of script file %s, status is: %s" % (self.tmpRName, status))
 
@@ -240,6 +245,7 @@
 	parser.add_option("-r", "--regions",   dest="regionsFileName", action="store",      default=None,      type="string", help="regions to plot [format: transcript file in GFF format]")
 	parser.add_option("-z", "--width",     dest="width",           action="store",      default=800,       type="int",    help="width of the image [format: int] [default: 800]")
 	parser.add_option("-Z", "--height",    dest="height",          action="store",      default=300,       type="int",    help="height of the image [format: int] [default: 300]")
+	parser.add_option("-A", "--arial",     dest="arial",           action="store_true", default=False,                    help="use Arial font [format: boolean] [default: false]")
 	parser.add_option("-v", "--verbosity", dest="verbosity",       action="store",      default=1,         type="int",    help="trace level [format: int]")
 	options = parser.parse_args()[0]
 	iGetReadSizes = GetReadSizes(options.verbosity)
@@ -252,4 +258,5 @@
 	iGetReadSizes.setFactors(None if options.factors == None else map(float, options.factors.split(",")))
 	iGetReadSizes.setRegionsFile(options.regionsFileName)
 	iGetReadSizes.setImageSize(options.width, options.height)
+	iGetReadSizes.setArial(options.arial)
 	iGetReadSizes.run()