diff SMART/Java/Python/GetReadSizes.py @ 46:169d364ddd91

Uploaded
author m-zytnicki
date Mon, 30 Sep 2013 03:19:26 -0400
parents 2c0c0a89fad7
children
line wrap: on
line diff
--- a/SMART/Java/Python/GetReadSizes.py	Wed Sep 18 08:51:22 2013 -0400
+++ b/SMART/Java/Python/GetReadSizes.py	Mon Sep 30 03:19:26 2013 -0400
@@ -52,6 +52,7 @@
 		self.sizes      = {}
 		self.factors    = {}
 		self.regions    = None
+		self.percentage = False
 		self.tmpDatName = None
 		self.tmpRName   = None
 		self.width      = 800
@@ -66,6 +67,8 @@
 		chooser.findFormat(format)
 		for cpt, fileName in enumerate(fileNames):
 			self.parsers[self.names[cpt]] = chooser.getParser(fileName)
+		if not self.factors:
+			self.factors = dict([name, 1.0] for name in self.names)
 
 	def setOutputFileName(self, fileName):
 		self.outputFileName = fileName
@@ -82,12 +85,17 @@
 		self.colors = colors
 
 	def setFactors(self, factors):
-		self.factors = dict(zip(self.names, factors))
+		if factors:
+			self.factors = dict(zip(self.names, factors))
 
 	def setRegionsFile(self, fileName):
 		if fileName != None:
 			self._loadRegions(fileName)
 
+	def setPercentage(self, percentage):
+		self.percentage = percentage
+		self.xLab = "% reads"
+
 	def setImageSize(self, width, height):
 		if width != None:
 			self.width = width
@@ -165,6 +173,14 @@
 	def _checkQuorum(self, region):
 		return (max([sum(self.sizes[region][name].values()) for name in self.sizes[region]]) > 0)
 
+	def _computePercentage(self):
+		for region in self.sizes:
+			for name in self.sizes[region]:
+				if self.sizes[region][name]:
+					sumData = float(sum(self.sizes[region][name].values()))
+					for size in self.sizes[region][name]:
+						self.sizes[region][name][size] = self.sizes[region][name][size] / sumData * 100
+
 	def _writeData(self, region):
 		self.tmpDatName = "tmpFile%d.dat" % (self.number)
 		handle          = open(self.tmpDatName, "w")
@@ -223,6 +239,8 @@
 		self.log.info("START Get Read Sizes")
 		for name in self.names:
 			self._parse(name)
+		if self.percentage:
+			self._computePercentage()
 		self._plot()
 		self._cleanFiles()
 		self.log.info("END Get Read Sizes")
@@ -243,6 +261,7 @@
 	parser.add_option("-c", "--colors",    dest="colors",          action="store",      default=None,      type="string", help="colors of the bars, separated by commas  [format: string]")
 	parser.add_option("-a", "--factors",   dest="factors",         action="store",      default=None,      type="string", help="normalization factors, separated by commas  [format: string]")
 	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("-p", "--percent",   dest="percentage",      action="store_true", default=False,                    help="compute percentage instead [format: boolean] [default: false]")
 	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]")
@@ -252,11 +271,12 @@
 	iGetReadSizes.setNames(options.names.split(","))
 	iGetReadSizes.setInputFiles(options.inputFileNames.split(","), options.format)
 	iGetReadSizes.setOutputFileName(options.outputFileName)
-	iGetReadSizes.setLabs(options.xLab, options.yLab)
 	iGetReadSizes.setSizes(options.minSize, options.maxSize)
 	iGetReadSizes.setColors(None if options.colors == None else options.colors.split(","))
 	iGetReadSizes.setFactors(None if options.factors == None else map(float, options.factors.split(",")))
 	iGetReadSizes.setRegionsFile(options.regionsFileName)
+	iGetReadSizes.setPercentage(options.percentage)
 	iGetReadSizes.setImageSize(options.width, options.height)
+	iGetReadSizes.setLabs(options.xLab, options.yLab)
 	iGetReadSizes.setArial(options.arial)
 	iGetReadSizes.run()