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

Uploaded
author m-zytnicki
date Mon, 30 Sep 2013 03:19:26 -0400
parents 2c0c0a89fad7
children
comparison
equal deleted inserted replaced
45:e454402ba9d9 46:169d364ddd91
50 self.log = LoggerFactory.createLogger("%s.%s" % (LOG_DEPTH, self.__class__.__name__), self.verbosity) 50 self.log = LoggerFactory.createLogger("%s.%s" % (LOG_DEPTH, self.__class__.__name__), self.verbosity)
51 self.parsers = {} 51 self.parsers = {}
52 self.sizes = {} 52 self.sizes = {}
53 self.factors = {} 53 self.factors = {}
54 self.regions = None 54 self.regions = None
55 self.percentage = False
55 self.tmpDatName = None 56 self.tmpDatName = None
56 self.tmpRName = None 57 self.tmpRName = None
57 self.width = 800 58 self.width = 800
58 self.height = 300 59 self.height = 300
59 self.arial = False 60 self.arial = False
64 def setInputFiles(self, fileNames, format): 65 def setInputFiles(self, fileNames, format):
65 chooser = ParserChooser(self.verbosity) 66 chooser = ParserChooser(self.verbosity)
66 chooser.findFormat(format) 67 chooser.findFormat(format)
67 for cpt, fileName in enumerate(fileNames): 68 for cpt, fileName in enumerate(fileNames):
68 self.parsers[self.names[cpt]] = chooser.getParser(fileName) 69 self.parsers[self.names[cpt]] = chooser.getParser(fileName)
70 if not self.factors:
71 self.factors = dict([name, 1.0] for name in self.names)
69 72
70 def setOutputFileName(self, fileName): 73 def setOutputFileName(self, fileName):
71 self.outputFileName = fileName 74 self.outputFileName = fileName
72 75
73 def setLabs(self, xLab, yLab): 76 def setLabs(self, xLab, yLab):
80 83
81 def setColors(self, colors): 84 def setColors(self, colors):
82 self.colors = colors 85 self.colors = colors
83 86
84 def setFactors(self, factors): 87 def setFactors(self, factors):
85 self.factors = dict(zip(self.names, factors)) 88 if factors:
89 self.factors = dict(zip(self.names, factors))
86 90
87 def setRegionsFile(self, fileName): 91 def setRegionsFile(self, fileName):
88 if fileName != None: 92 if fileName != None:
89 self._loadRegions(fileName) 93 self._loadRegions(fileName)
94
95 def setPercentage(self, percentage):
96 self.percentage = percentage
97 self.xLab = "% reads"
90 98
91 def setImageSize(self, width, height): 99 def setImageSize(self, width, height):
92 if width != None: 100 if width != None:
93 self.width = width 101 self.width = width
94 if height != None: 102 if height != None:
163 self.maxSize = max([max(self.sizes[region][name].keys()) for name in self.names for region in region]) 171 self.maxSize = max([max(self.sizes[region][name].keys()) for name in self.names for region in region])
164 172
165 def _checkQuorum(self, region): 173 def _checkQuorum(self, region):
166 return (max([sum(self.sizes[region][name].values()) for name in self.sizes[region]]) > 0) 174 return (max([sum(self.sizes[region][name].values()) for name in self.sizes[region]]) > 0)
167 175
176 def _computePercentage(self):
177 for region in self.sizes:
178 for name in self.sizes[region]:
179 if self.sizes[region][name]:
180 sumData = float(sum(self.sizes[region][name].values()))
181 for size in self.sizes[region][name]:
182 self.sizes[region][name][size] = self.sizes[region][name][size] / sumData * 100
183
168 def _writeData(self, region): 184 def _writeData(self, region):
169 self.tmpDatName = "tmpFile%d.dat" % (self.number) 185 self.tmpDatName = "tmpFile%d.dat" % (self.number)
170 handle = open(self.tmpDatName, "w") 186 handle = open(self.tmpDatName, "w")
171 handle.write("Size\tCount\tSample\n") 187 handle.write("Size\tCount\tSample\n")
172 for name in self.sizes[region]: 188 for name in self.sizes[region]:
221 LoggerFactory.setLevel(self.log, self.verbosity) 237 LoggerFactory.setLevel(self.log, self.verbosity)
222 self._checkOptions() 238 self._checkOptions()
223 self.log.info("START Get Read Sizes") 239 self.log.info("START Get Read Sizes")
224 for name in self.names: 240 for name in self.names:
225 self._parse(name) 241 self._parse(name)
242 if self.percentage:
243 self._computePercentage()
226 self._plot() 244 self._plot()
227 self._cleanFiles() 245 self._cleanFiles()
228 self.log.info("END Get Read Sizes") 246 self.log.info("END Get Read Sizes")
229 247
230 248
241 parser.add_option("-l", "--xLabel", dest="xLab", action="store", default="Size", type="string", help="x-axis label name [format: string] [default: Size]") 259 parser.add_option("-l", "--xLabel", dest="xLab", action="store", default="Size", type="string", help="x-axis label name [format: string] [default: Size]")
242 parser.add_option("-L", "--yLabel", dest="yLab", action="store", default="# reads", type="string", help="y-axis label name [format: string] [default: Reads]") 260 parser.add_option("-L", "--yLabel", dest="yLab", action="store", default="# reads", type="string", help="y-axis label name [format: string] [default: Reads]")
243 parser.add_option("-c", "--colors", dest="colors", action="store", default=None, type="string", help="colors of the bars, separated by commas [format: string]") 261 parser.add_option("-c", "--colors", dest="colors", action="store", default=None, type="string", help="colors of the bars, separated by commas [format: string]")
244 parser.add_option("-a", "--factors", dest="factors", action="store", default=None, type="string", help="normalization factors, separated by commas [format: string]") 262 parser.add_option("-a", "--factors", dest="factors", action="store", default=None, type="string", help="normalization factors, separated by commas [format: string]")
245 parser.add_option("-r", "--regions", dest="regionsFileName", action="store", default=None, type="string", help="regions to plot [format: transcript file in GFF format]") 263 parser.add_option("-r", "--regions", dest="regionsFileName", action="store", default=None, type="string", help="regions to plot [format: transcript file in GFF format]")
264 parser.add_option("-p", "--percent", dest="percentage", action="store_true", default=False, help="compute percentage instead [format: boolean] [default: false]")
246 parser.add_option("-z", "--width", dest="width", action="store", default=800, type="int", help="width of the image [format: int] [default: 800]") 265 parser.add_option("-z", "--width", dest="width", action="store", default=800, type="int", help="width of the image [format: int] [default: 800]")
247 parser.add_option("-Z", "--height", dest="height", action="store", default=300, type="int", help="height of the image [format: int] [default: 300]") 266 parser.add_option("-Z", "--height", dest="height", action="store", default=300, type="int", help="height of the image [format: int] [default: 300]")
248 parser.add_option("-A", "--arial", dest="arial", action="store_true", default=False, help="use Arial font [format: boolean] [default: false]") 267 parser.add_option("-A", "--arial", dest="arial", action="store_true", default=False, help="use Arial font [format: boolean] [default: false]")
249 parser.add_option("-v", "--verbosity", dest="verbosity", action="store", default=1, type="int", help="trace level [format: int]") 268 parser.add_option("-v", "--verbosity", dest="verbosity", action="store", default=1, type="int", help="trace level [format: int]")
250 options = parser.parse_args()[0] 269 options = parser.parse_args()[0]
251 iGetReadSizes = GetReadSizes(options.verbosity) 270 iGetReadSizes = GetReadSizes(options.verbosity)
252 iGetReadSizes.setNames(options.names.split(",")) 271 iGetReadSizes.setNames(options.names.split(","))
253 iGetReadSizes.setInputFiles(options.inputFileNames.split(","), options.format) 272 iGetReadSizes.setInputFiles(options.inputFileNames.split(","), options.format)
254 iGetReadSizes.setOutputFileName(options.outputFileName) 273 iGetReadSizes.setOutputFileName(options.outputFileName)
255 iGetReadSizes.setLabs(options.xLab, options.yLab)
256 iGetReadSizes.setSizes(options.minSize, options.maxSize) 274 iGetReadSizes.setSizes(options.minSize, options.maxSize)
257 iGetReadSizes.setColors(None if options.colors == None else options.colors.split(",")) 275 iGetReadSizes.setColors(None if options.colors == None else options.colors.split(","))
258 iGetReadSizes.setFactors(None if options.factors == None else map(float, options.factors.split(","))) 276 iGetReadSizes.setFactors(None if options.factors == None else map(float, options.factors.split(",")))
259 iGetReadSizes.setRegionsFile(options.regionsFileName) 277 iGetReadSizes.setRegionsFile(options.regionsFileName)
278 iGetReadSizes.setPercentage(options.percentage)
260 iGetReadSizes.setImageSize(options.width, options.height) 279 iGetReadSizes.setImageSize(options.width, options.height)
280 iGetReadSizes.setLabs(options.xLab, options.yLab)
261 iGetReadSizes.setArial(options.arial) 281 iGetReadSizes.setArial(options.arial)
262 iGetReadSizes.run() 282 iGetReadSizes.run()